QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457840#8838. Jesse's Jobucup-team1525#WA 1ms3720kbC++201.2kb2024-06-29 14:23:302024-06-29 14:23:31

Judging History

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

  • [2024-06-29 14:23:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3720kb
  • [2024-06-29 14:23:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int t;
int n;
const int N=1000005;
int a[N];
vector<int> v;
void dfs(int x)
{
    v.push_back(x);
    if (a[x]!=1)
        dfs(a[x]);
}
int main()
{
    scanf("%d",&t);
    while (t--)
    {
        scanf("%d",&n);
        for (int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        v.clear();
        dfs(1);
        if (v.size()!=n)
        {
            printf("%d\n%d\n",n,(int)v.size());
            sort(v.begin(),v.end());
            for (int x:v)
                printf("%d ",x);
            puts("");
        }
        else
        {
            for (int i=1;i<n;++i)
                if (v[i]==2)
                {
                    printf("%d\n%d\n",n-2,i);
                    for (int j=0;j<i;++j)
                        printf("%d ",v[i]);
                    puts("");
                    break;
                }
            // int mnp=1;
            // for (int i=2;i<=n;++i)
            //     if (abs(mnp-a[mnp])>abs(i-a[i]))
            //         mnp=i;
            // int ans=n-abs(mnp-a[mnp])-1;
            // printf("%d\n1\n%d\n",ans,mnp);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3720kb

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
2 2 2 

result:

wrong answer Participant didn't find permutation (test case 3)