QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549753#8838. Jesse's Jobucup-team4906#WA 0ms3592kbC++201.1kb2024-09-06 21:02:342024-09-06 21:02:35

Judging History

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

  • [2024-09-06 21:02:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-09-06 21:02:34]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)

using namespace std;
const int N = 1e6 + 10;
int a[N], n;

void sol() {
    cin >> n;
    vector<int> pos(n + 1);
    F(i, 1, n) cin >> a[i], pos[a[i]] = i;
    vector<int> vst(n + 1);
    F(i, 1, n) if(! vst[i]) {
        int x = i;
        vector<int> tmp;
        while(! vst[x]) {
            vst[x] = 1;
            tmp.push_back(x);
            x = a[x];
        }
        // cout << tmp.size() << "?\n";
        if(tmp.size() != n) {
            cout << n << "\n";
            cout << tmp.size() << "\n";
            for(auto x : tmp) cout << x << " "; cout << "\n";
            return;
        } else {
            cout << n - 2 << "\n";
            if(n == 2) {
                cout << 1 << "\n" << 1 << "\n";
            } else {
                cout << 2 << "\n" << 1 << " " << pos[1] << "\n";
            }
            return;
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t; cin >> t;
    F(i, 1, t) sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

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