QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#434526 | #4800. Oscar's Round Must Have a Constructive Problem | ship2077 | WA | 18ms | 3928kb | C++14 | 824b | 2024-06-08 16:29:29 | 2024-06-08 16:29:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
mt19937 mt(time(NULL));
constexpr int M=1e5+5;
int n,cnt,num,p[M],per[M];
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
int rnd(int l,int r){return mt()%(r-l+1)+l;}
void solve(){ n=read();num=0;
for (int i=1;i<=n;i++) p[i]=read();
for (int i=1;i<=n;i++) num+=p[i]==p[1];
if (num==n) return puts("NO"),void();
iota(per+1,per+n+1,1);
cnt=0;while (1){ bool flag=0;
for (int i=1;i<n;i++)
if (per[i]==p[i]) flag=1,
swap(per[i],per[rnd(i+1,n)]);
if (per[n]==p[n]) swap(per[n],per[rnd(1,n-1)]);
cnt++; if (!flag) break;
} puts("YES");
for (int i=1;i<=n;i++) printf("%d%c",per[i]," \n"[i==n]);
}
int main(){int T=read();while (T--) solve();return 0;}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3904kb
input:
3 3 3 3 3 3 3 2 1 6 1 1 4 5 1 4
output:
NO YES 1 3 2 YES 5 2 3 4 6 1
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 18ms
memory: 3928kb
input:
50069 1 1 2 1 1 2 1 2 2 2 1 2 2 2 3 1 1 1 3 1 1 2 3 1 1 3 3 1 2 1 3 1 2 2 3 1 2 3 3 1 3 1 3 1 3 2 3 1 3 3 3 2 1 1 3 2 1 2 3 2 1 3 3 2 2 1 3 2 2 2 3 2 2 3 3 2 3 1 3 2 3 2 3 2 3 3 3 3 1 1 3 3 1 2 3 3 1 3 3 3 2 1 3 3 2 2 3 3 2 3 3 3 3 1 3 3 3 2 3 3 3 3 4 1 1 1 1 4 1 1 1 2 4 1 1 1 3 4 1 1 1 4 4 1 1 2 1 ...
output:
NO NO YES 2 1 YES 1 2 NO NO YES 2 3 1 YES 2 3 1 YES 3 1 2 YES 2 1 3 YES 3 1 2 YES 2 1 3 YES 3 2 1 YES 3 1 2 YES 1 2 3 YES 1 2 3 YES 3 2 1 YES 1 3 2 NO YES 1 3 2 YES 1 2 3 YES 1 2 3 YES 3 2 1 YES 1 2 3 YES 1 2 3 YES 3 2 1 YES 1 3 2 YES 2 3 1 YES 1 3 2 YES 1 2 3 YES 1 2 3 NO NO YES 2 3 4 1 YES 4 2 3 1...
result:
wrong answer P_1 == A_1.