QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707425#8838. Jesse's JobRezhou#WA 1ms3816kbC++231.5kb2024-11-03 15:56:292024-11-03 15:56:30

Judging History

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

  • [2024-11-03 15:56:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3816kb
  • [2024-11-03 15:56:29]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> pii;

void solve() {
    int n, m;
    cin >> n;

    m = n;
    vector<int> v(m + 1), find(m + 1), chose(m + 1);
    for (int i = 1; i <= m; i++) {
        cin >> v[i];
        find[v[i]] = i;
    }

    if (v[1] == 1) {
        cout << n << '\n';
        cout << 1 << "\n";
        cout << 1 << '\n';
        return;
    }

    queue<int> q;
    q.push(find[1]);
    chose[find[1]] = 1;

    vector<int> ans;
    ans.push_back(find[1]);
    q.push(v[1]);
    ans.push_back(1);
    ans.push_back(v[1]);
    chose[1] = 1;

    while (!q.empty()) {
        int t = q.front();
        q.pop();

        if (chose[v[t]]) continue;
        ans.push_back(v[t]);
        q.push(v[t]);
        chose[v[t]] = 1;
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    if (ans.size() == n) {
        ans.pop_back();
        cout << n - 2 << '\n';
        cout << 1 << '\n';
        for (int i = 1; i <= n; i++) {
            if (n - 1 - abs(v[i] - i) == n - 2) {
                cout << i << "\n";
                break;
            }
        }
    }
    else {
        cout << n << '\n';
        cout << ans.size() << "\n";
        for (auto& it : ans) cout << it << " ";
        cout << "\n";
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

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

result:

ok Correct (3 test cases)

Test #2:

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

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

result:

wrong answer Integer element pos[1] equals to 6, violates the range [1, 5] (test case 143)