/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 9ms 4.27 MiB
#2 Wrong Answer 9ms 4.27 MiB
#3 Wrong Answer 9ms 4.27 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define in(v) for(auto &b: v) cin >> b;
#define pb push_back
#ifdef Sabbir
#include <E:\CodeBox\TempBox\Debug\debug.h>
#else
#define dbg(x...)
#endif
const int mx = 1000001;
int spf[mx];

void sieve_spf() {
    for (int i = 2; i < mx; i++) spf[i] = i;
    for (int i = 2; i * i < mx; i++) {
        if (spf[i] == i) {
            for (int j = i * i; j < mx; j += i) {
                if (spf[j] == j) spf[j] = i;
            }
        }
    }
}

void solve() {
    int n; cin >> n;
    vector<int> C(n); in(C);

    vector<vector<int>> groups(n + 1);
    for (int i = 1; i <= n; i++) {
        groups[spf[i]].pb(i);
    }

    vector<int> ans(n + 1);
    ans[1] = 1;
    
    for (int i = 2; i <= n; i++) {
        ordered_set os;
        reverse(all(groups[i]));    
        for (auto idx : groups[i]) {
            int required = C[idx - 1];
            if (required > (int)os.size()) {
                cout << "NO\n";
                return;
            }
            if (required == (int)os.size()) {
                if(os.size() == 0) {
                   os.insert(-1e7);
                   ans[idx] = 1e7;
                   dbg(ans);
                }else {    
                    os.insert(((*os.begin()) - 1));
                    ans[idx]=-(*os.begin());
                }
                
            } else {
                ans[idx] = -(*os.find_by_order(required));
            }
        }
    }

    cout << "YES\n";
    for (int i = 1; i <= n; i++) cout << ans[i] << " ";
    cout << "\n";
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    sieve_spf();
    int t; cin >> t;
    while (t--) solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1163 Roy and Array Construction
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 17:57:17
Judged At
2025-02-17 17:57:17
Judged By
Score
2
Total Time
9ms
Peak Memory
4.27 MiB