QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#707794#8838. Jesse's JobRezhou#WA 0ms3820kbC++231.6kb2024-11-03 17:33:462024-11-03 17:33:46

Judging History

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

  • [2024-11-03 17:33:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2024-11-03 17:33:46]
  • 提交

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

    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    if (ans.size() == n) {
        int add = 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';
                for (auto& it : now) cout << it << " ";
                cout << '\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;
}

詳細信息

Test #1:

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

input:

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

output:

4
2
1 2 

result:

wrong answer Integer parameter [name=score] equals to 4, violates the range [0, 2] (test case 1)