/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 1.324 MiB
#2 Wrong Answer 3ms 1.277 MiB
#3 Wrong Answer 3ms 1.504 MiB

Code

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	
	ios_base::sync_with_stdio(0); 
    cin.tie(0);                   
    cout.tie(0);
    const int N = 1e5 + 9;
    int spf[N];
    spf[1] = 1;
    for (int i = 2; i < N; i++) {
    spf[i] = i;
    }
    for (int i = 2; i < N; i++) {
         if (spf[i] == i) {
           for (int j = i; j < N; j += i) {
                spf[j] = min(spf[j], i);
           }
        }
     }
     vector<int>primes,poss(N,0);
     
     for(int i = 2; i < N; i++){
     	if(spf[i] == i) {
     		if(primes.size()){
     			poss[primes.back()] = i;
     		}
     		primes.push_back(i);
     	}
     }
     
     int tc; cin >> tc;
     while(tc--){
     	int n; cin >> n;
     	vector<int>a(n+1);
     	int flag = 0;
     	map<int,int>mp;
     	for(int i = 1; i <= n; i++){
     		cin >> a[i];
     		int need;
     		if(i != 1 && a[i] == 1 && flag == 0){
     			if(spf[i] != i) {
     				flag = 1; continue;
     			}
     			int x = spf[i];
     			int y = x / spf[i];
     			
     					need = poss[y];
     					
     			
     			int z = need * x;
     			if(z > n) flag = 1;
     			mp[x]++;
     		}
     		
     	}
     	if(flag || a[0] == 1) cout << "NO\n";
     	else{
     		cout << "YES\n";
     		for(int i = 1, j = n; i <= n; i++, j--){
     			cout << j << " ";
     		}
     		cout << '\n';
     	}
     }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1163 Roy and Array Construction
Contest
Brain Booster #8
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 15:56:21
Judged At
2025-02-17 15:56:21
Judged By
Score
2
Total Time
3ms
Peak Memory
1.504 MiB