QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796163#8212. Football in Osijekucup-team173#WA 0ms3648kbC++231.8kb2024-12-01 13:33:422024-12-01 13:33:42

Judging History

你现在查看的是最新测评结果

  • [2024-12-01 13:33:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2024-12-01 13:33:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> vis(n + 1), bel(n + 1), sz(n + 1), cir(n + 1);
    vector<int> stk(n + 1), instk(n + 1); int tp = 0;
    for(int i = 1; i <= n; i++) if(!vis[i]) {
        auto dfs = [&](auto self, int x) -> void {
            vis[x] = 1, stk[++tp] = x, instk[x] = 1;
            if(bel[a[x]]) {
                bel[x] = bel[a[x]], sz[bel[x]]++;
            } else if(vis[a[x]]) {
                while(stk[tp] != a[x]) {
                    cir[x]++, sz[x]++;
                    bel[stk[tp]] = x;
                    instk[stk[tp]] = 0;
                    tp--;
                }
                cir[x]++, sz[x]++, bel[a[x]] = x, instk[a[x]] = 0, tp--;
            } else {
                self(self, a[x]);
            }
            if(instk[x]) tp--, instk[x] = 0;
        };
        dfs(dfs, i);
    }
    vector<int> ve, ans(n + 2);
    for(int i = 1; i <= n; i++) {
        if(bel[i] == i) {
            ve.push_back(sz[i]);
            ans[cir[i]]++, ans[sz[i] + 1]--;
        }
    }
    for(int i = 1; i <= n; i++) ans[i] += ans[i - 1];
    for(int i = 1; i <= n; i++) ans[i] = !ans[i];
    sort(ve.begin(), ve.end(), greater<int>());
    for(int i = 1; i < ve.size(); i++) ve[i] += ve[i - 1];
    for(int i = 1; i < ve.size(); i++) {
        for(int j = ve[i - 1] + 1; j <= ve[i]; j++) {
            ans[j] = i;
        }
    }
    for(int i = 1; i <= n; i++) {
        cout << ans[i] << " \n"[i == n];
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

5
2 3 1 3 5

output:

0 1 0 0 1

result:

ok 5 number(s): "0 1 0 0 1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

1
1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3636kb

input:

2
2 2

output:

0 1

result:

wrong answer 2nd numbers differ - expected: '0', found: '1'