QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770943#8212. Football in Osijektassei903WA 0ms3856kbC++231.8kb2024-11-22 03:54:052024-11-22 03:54:05

Judging History

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

  • [2024-11-22 03:54:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2024-11-22 03:54:05]
  • 提交

answer

#include <bits/stdc++.h>

#define rep1(n) for(int i = 0; i < (int)n; i++)
#define rep2(i, n) for(int i = 0; i < (int)n; i++)
#define rep3(i, l, r) for(int i = (int)l; i < (int)r; i++)
#define overloadrep(a, b, c, x, ...) x
#define rep(...) overloadrep(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
using namespace std;

using ll = long long;
using vi = vector<int>;


void solve() {
    int n;cin >> n;
    vector<int> p(n);for (auto &x: p) cin >> x, x--;
    vector<int> deg(n, 0);
    rep(i, n)deg[p[i]]++;
    queue<int> q;
    rep(i, n)if (deg[i] == 0) q.push(i);
    vector<int> dp(n, 0);
    vector<int> order;
    while (!q.empty()) {
        int x = q.front();q.pop();
        order.emplace_back(x);
        dp[x] = -1;
        deg[p[x]]--;
        if (deg[p[x]] == 0)q.push(p[x]);
    }

    rep(i, n) {
        if (dp[i] != 0) continue;
        int cnt = 0, x = i;
        do {
            cnt++;
            x = p[x];
            
        } while (x != i);
        
        do {
            dp[x] = cnt;
        }while (x != i);
    }
    // rep(i, sz(order)) cout << order[i] << " ";
    // cout << endl;
    for (int i : order | views :: reverse) {
        dp[i] = dp[p[i]] + 1;
    }
    // rep(i, n) cout << dp[i] << " " ;
    // cout << endl;
    vector<bool> flag(n+1, 0);
    int m = 0;
    rep(i, n)flag[dp[i]] = true, m = max(m, dp[i]);
    
    rep(i, 1, n+1) {
        if (i > 1) cout << " ";
        if (flag[i]) cout << 0;
        else if (i <= m) cout << 1;
        else cout << i - m; 
    }
    cout << endl;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // int T;cin >> T;
    while(T--) {
        solve();
    }
    
} 

詳細信息

Test #1:

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

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: 3612kb

input:

1
1

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2
2 2

output:

0 0

result:

ok 2 number(s): "0 0"

Test #4:

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

input:

10
4 7 2 8 4 3 4 9 7 3

output:

1 1 1 0 0 0 0 1 2 3

result:

ok 10 numbers

Test #5:

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

input:

10
8 7 4 8 3 4 2 5 3 7

output:

1 0 0 0 0 1 2 3 4 5

result:

wrong answer 7th numbers differ - expected: '1', found: '2'