/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 11ms 6.332 MiB
#2 Wrong Answer 10ms 6.336 MiB
#3 Wrong Answer 10ms 6.188 MiB

Code

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e6 + 9;
bool is_prime[N];
vector<int> primes,poss(N);
void sieve() {
is_prime[1] = false;
for (int i = 2; i < N; i++) {
is_prime[i] = true;}
for (int i = 2; i*i < N; i++) {
if (is_prime[i]) {
for (int j = i + i; j < N; j += i) {
is_prime[j] = false;}}}
for (int i = 2; i < N; i++) {
if (is_prime[i]) {
	if(primes.size()){
     			poss[primes.back()] = i;
     		}
primes.push_back(i);}}}

int main() {
	
	ios_base::sync_with_stdio(0); 
    cin.tie(0);                   
    cout.tie(0);
    sieve();
    const int N1 = 1e5 + 9;
    int spf[N1];
    spf[1] = 1;
    for (int i = 2; i < N1; i++) {
    spf[i] = i;
    }
    for (int i = 2; i < N1; i++) {
         if (spf[i] == i) {
           for (int j = i; j < N1; j += i) {
                spf[j] = min(spf[j], 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 16:03:45
Judged At
2025-02-17 16:03:45
Judged By
Score
2
Total Time
11ms
Peak Memory
6.336 MiB