QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707879 | #8838. Jesse's Job | Rezhou# | WA | 1ms | 3816kb | C++23 | 1.8kb | 2024-11-03 17:59:08 | 2024-11-03 17:59:09 |
Judging History
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;
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 || add == 1) {
cout << n - 2 << '\n';
cout << now.size() << '\n';
sort(now.begin(), now.end());
for (auto& it : now) cout << it << " ";
cout << '\n';
break;
}
}
}
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: 3584kb
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: 3816kb
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 Integer parameter [name=score] equals to 6, violates the range [0, 5] (test case 138)