QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707893#8838. Jesse's JobRezhouWA 1ms3612kbC++231.8kb2024-11-03 18:02:142024-11-03 18:02:14

Judging History

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

  • [2024-11-03 18:02:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3612kb
  • [2024-11-03 18:02:14]
  • 提交

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;
    }

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

    if (v[1] != find[1]) {
        q.push(v[1]);
        ans.push_back(v[1]);
        chose[v[1]] = 1;
    }

    if (1 != v[1] && 1 != find[1]) {
        ans.push_back(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;
    }
    if (ans.size() == n) {
        int add = 0, ok = 0;
        vector<int> now;
        for (int i = n - 1; i >= 0; i--) {
            add += ans[i];
            add -= v[ans[i]];

            now.push_back(ans[i]);
            if (add == -1) {
                cout << n - 2 << '\n';
                cout << now.size() << '\n';
                sort(now.begin(), now.end());
                for (auto& it : now) cout << it << " ";
                cout << '\n';
                return;
            }
        }
        cout << n-2 <<endl;
        cout << 1 << "\n";
        cout << 1 << endl;
    }
    else {
        sort(ans.begin(), ans.end());
        ans.erase(unique(ans.begin(), ans.end()), ans.end());
        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: 3516kb

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
5 

result:

ok Correct (3 test cases)

Test #2:

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

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

result:

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