QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#458866#8838. Jesse's Jobucup-team3608#WA 1ms3548kbC++171.6kb2024-06-29 20:11:222024-06-29 20:11:22

Judging History

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

  • [2024-06-29 20:11:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3548kb
  • [2024-06-29 20:11:22]
  • 提交

answer

#include"bits/stdc++.h"
#include"bits/stdc++.h"

using lint = int64_t;

using namespace std;

void solve(){
    int n; cin>>n;
    vector<int> v(n), p(n);
    for(int i = 0; i <n; i++){
        cin>>v[i];
        v[i]--;
        p[v[i]] = i;
    }
    for(int i = 0; i <n; i++){
        if(v[i] == i){
            cout<<n<<"\n";
            cout<<1<<"\n";
            cout<<i+1<<"\n";
            return;
        }
    }
    if(n == 2){
        cout<<"0\n1\n1\n";
        return;
    }
    for(int i = 0; i <n; i++){
        int r = p[i];
        if(p[r] == i){
            cout<<n<<"\n";
            cout<<2<<"\n";
            cout<<i+1<<" "<<r+1<<"\n";
            return;
        }
    }
    vector<bool> vis(n);
    int edges = 0;
    for(int i = 0; i < n; i++){
        if(vis[i]) continue;
        if(edges == n-2) break;
        vis[i] = true;
        edges++;
        int cur = v[i];
        while(cur != i){
            if(edges == n-2) break;
            vis[cur] = true;
            vis[v[cur]] = true;
            edges++;
            cur = v[cur];
        }
    }
    int k = 0;
    for(int i = 0; i < n; i++)
        if(vis[i])
            k++;
    cout<<n-2<<"\n";
    vector<int> ans; ans.reserve(n);
    for(int i = 0; i < n; i++)
        if(vis[v[i]])
            ans.push_back(i+1);
    cout<<ans.size()<<"\n";
    for(int a : ans) cout<<a<<" ";
    cout<<"\n";

    return;

}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int t; cin>>t;
    while(t--) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3520kb

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
1
2
4
1
3
6
1
4
6
2
2 5
6
1
2
5
1
3
6
1
1
4
2
1 2
6
1
1
6
1
3
6
2
1 2
6
2
1 3
6
1
6
6
1
2
6
1
5
6
1
3
6
1
2
6
1
2
6
1
2
6
1
3
6
1
5
6
1
4
6
1
2
4
5
1 2 3 4 6 
6
1
2
6
1
1
6
1
1
6
1
1
4
5
1 2 3 4 5 
6
1
6
6
1
3
6
1
1
6
1
4
6
1
3
2
3
1 2 3 
4
5
1 2 3 5 6 
5
1
2
5
1
1
6
1
4
6
1
2
4
4
1 3 4 5 
4...

result:

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