QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#457622#8835. Goodmanucup-team1338#WA 3ms7572kbC++20573b2024-06-29 13:28:382024-06-29 13:28:39

Judging History

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

  • [2024-06-29 13:28:39]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7572kb
  • [2024-06-29 13:28:38]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N=500013;
int p[N],f[N],r[N];
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
void solve(){
    int n;
    cin>>n;
    iota(f,f+n+1,0);
    iota(r,r+n+1,0);
    for(int i=1;i<=n;i++)cin>>p[i],f[find(p[i])]=find(i);
    sort(r+1,r+n+1,[&](int x,int y){
        return find(x)==find(y)?x<y:find(x)<find(y);
    });
    for(int i=1;i<=n;i++)cout<<r[i]<<' ';
    cout<<'\n';
}

int main(){
    ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5544kb

input:

2
4
1 2 3 4
6
6 5 4 3 2 1

output:

1 2 3 4 
1 6 2 5 3 4 

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 7572kb

input:

873
6
1 5 2 4 6 3
6
5 1 6 4 3 2
4
1 4 3 2
6
2 1 6 5 4 3
6
4 5 1 3 6 2
6
6 2 1 5 4 3
5
1 5 4 3 2
6
1 2 6 3 5 4
4
2 1 3 4
6
1 6 4 2 3 5
6
6 1 3 5 2 4
6
2 1 4 5 3 6
6
3 4 1 5 2 6
6
4 1 5 2 6 3
6
5 2 1 4 6 3
6
4 1 6 2 3 5
6
5 1 3 4 6 2
6
6 2 5 4 1 3
6
6 2 5 1 4 3
6
5 2 3 6 4 1
6
6 1 2 5 4 3
6
2 3 4 6 1 ...

output:

1 2 3 5 6 4 
1 2 3 5 6 4 
1 2 4 3 
1 2 3 6 4 5 
2 5 6 1 3 4 
2 1 3 6 4 5 
1 2 5 3 4 
1 2 3 4 6 5 
1 2 3 4 
1 2 3 4 5 6 
3 1 2 4 5 6 
1 2 3 4 5 6 
1 3 2 4 5 6 
1 2 4 3 5 6 
2 1 3 5 6 4 
1 2 4 3 5 6 
1 2 5 6 3 4 
2 1 3 5 6 4 
2 1 3 4 5 6 
1 4 5 6 2 3 
1 2 3 6 4 5 
1 2 3 4 5 6 
1 5 2 3 6 4 
1 4 2 3 5 6...

result:

wrong answer Jury found better answer than participant (test case 1)