QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#457811 | #8838. Jesse's Job | ucup-team052# | WA | 1ms | 5912kb | C++23 | 1.4kb | 2024-06-29 14:11:52 | 2024-06-29 14:11:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 1000005
int vis[N],p[N],n;
void work()
{
n=read();
for(int i=1;i<=n;i++) p[i]=read();
for(int i=1;i<=n;i++) vis[i]=0;
{
int cnt=0;
int cur=1;
while(!vis[cur]) cnt++,vis[cur]=1,cur=p[cur];
if(cnt!=n)
{
printf("%d\n%d\n",n,cnt);
for(int i=1;i<=n;i++) if(vis[i]) printf("%d ",i);
printf("\n");
return ;
}
}
if(p[1]!=2)
{
for(int i=1;i<=n;i++) vis[i]=0;
int cur=1,premn=p[1],cnt=0;
while(1)
{
vis[cur]=1;
cur=p[cur];
cnt++;
if(cur<premn) break;
}
printf("%d\n%d\n",n-2,cnt);
for(int i=1;i<=n;i++) if(vis[i]) printf("%d ",i);
printf("\n");
}
else
{
printf("%d\n%d\n",n-2,n-1);
for(int i=2;i<=n;i++) printf("%d ",i);
printf("\n");
}
}
signed main()
{
int T=read(); while(T--) work();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5912kb
input:
3 2 2 1 4 2 1 4 3 6 3 5 4 2 6 1
output:
0 1 2 4 2 1 2 4 3 1 3 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5836kb
input:
872 6 1 5 2 6 3 4 6 5 2 1 3 4 6 4 2 1 3 4 6 2 3 1 4 5 6 6 4 5 1 6 2 3 6 6 2 3 1 4 5 5 2 1 3 4 5 6 1 2 6 4 3 5 4 2 1 4 3 6 1 6 4 2 5 3 6 6 1 3 5 4 2 6 2 1 4 5 6 3 6 3 4 1 5 6 2 6 4 1 5 3 2 6 6 5 2 1 6 3 4 6 4 1 6 2 5 3 6 5 1 3 6 2 4 6 6 2 5 4 3 1 6 6 2 5 3 1 4 6 5 2 4 1 3 6 6 6 1 3 2 4 5 6 2 3 4 6 5 ...
output:
6 1 1 6 4 1 3 4 5 4 2 1 2 6 3 1 2 3 6 4 1 3 4 6 6 4 1 4 5 6 5 2 1 2 6 1 1 4 2 1 2 6 1 1 6 3 1 2 6 6 2 1 2 6 2 1 3 6 5 1 2 3 4 5 6 3 1 3 5 6 3 1 2 4 6 3 1 2 5 6 2 1 6 6 5 1 3 4 5 6 6 4 1 3 4 5 6 5 1 2 4 5 6 6 5 1 2 3 4 6 6 5 1 2 3 5 6 6 2 1 4 4 2 1 4 6 2 1 3 6 1 1 6 1 1 6 ...
result:
wrong answer Participant didn't find permutation (test case 30)