QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#478198#8838. Jesse's JobGoldenWA 0ms3544kbC++171.3kb2024-07-14 18:44:092024-07-14 18:44:09

Judging History

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

  • [2024-07-14 18:44:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3544kb
  • [2024-07-14 18:44:09]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


const int N = 1e6 + 5;

int p[N];
bool was[N];

void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        was[i] = false;
    }
    vector<int> cycle;
    int ind = 1;
    while (!was[p[ind]]) {
        was[p[ind]] = true;
        cycle.push_back(ind);
        ind = p[ind];
    }
    if ((int)cycle.size() == n) {
        if (n == 2) {
            if (p[1] != 1)
                cout << "0\n1\n1\n";
            else
                cout << "2\n1\n1\n";
            return;
        }
        else {
            cout << n - 2 << "\n";
            cycle.pop_back(), cycle.pop_back();
            sort(cycle.begin(), cycle.end());
            cout << cycle.size() << "\n";
            for (int val : cycle) {
                cout << val << " ";
            }
            cout << "\n";
        }
    }
    else {
        cout << n << "\n";
        cout << cycle.size() << "\n";
        for (int val : cycle) {
            cout << val << " ";
        }
        cout << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t; cin >> t;
    while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

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