QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#816711#8838. Jesse's Jobwsc2008#WA 0ms3856kbC++141.1kb2024-12-16 16:59:082024-12-16 16:59:09

Judging History

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

  • [2024-12-16 16:59:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2024-12-16 16:59:08]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void write(ll x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
const ll N=1e6+9;
ll T,n,a[N];
bool vis[N];
void solve(){
    n=read();
    rep(i,1,n)a[i]=read(),vis[i]=0;
    ll u=1;
    vector<ll>v;
    while(!vis[u])v.push_back(u),vis[u]=1,u=a[u];
    if(v.size()==n){
        v.clear(),u=1;
        while(u!=2)v.push_back(u),u=a[u];
        write(n-2),putchar('\n');
    }
    else write(n),putchar('\n');
    for(ll x:v)write(x),putchar(' ');
    putchar('\n');
}
bool Med;
int main(){
    cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
    T=read();
    while(T--)solve();
    cerr<<"\n"<<clock()*1.0/CLOCKS_PER_SEC*1000<<"ms\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3856kb

input:

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

output:

0
1 
4
1 2 
4
1 3 4 

result:

wrong answer Integer element pos[1] equals to 4, violates the range [1, 2] (test case 1)