QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#477947 | #8835. Goodman | Rosmontispes | WA | 1ms | 3832kb | C++20 | 886b | 2024-07-14 13:35:25 | 2024-07-14 13:35:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define fi first
#define se second
void solve()
{
int n;
cin>>n;
vector<int>ar(n + 1),idx(n + 1,-1);
int res = 0;
vector<int>p;
for(int i = 1;i <= n;i ++)
{
cin>>ar[i];
if(ar[i] == i)
p.push_back(ar[i]);
else
idx[ar[i]] = i;
}
vector<int>ans;
for(auto v:p)
ans.push_back(v);
for(int i = 1;i <= n;i ++)
{
if(idx[i] != -1 && idx[idx[i]] != -1)
{
ans.push_back(i);
ans.push_back(idx[i]);
idx[idx[i]] = -1;
}
}
for(auto v:ans)
cout<<v<<" ";
cout<<"\n";
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
cin>>T;
while(T --)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3816kb
input:
2 4 1 2 3 4 6 6 5 4 3 2 1
output:
1 2 3 4 1 6 2 5 3 4
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3832kb
input:
873 6 1 5 2 4 6 3 6 5 1 6 4 3 2 4 1 4 3 2 6 2 1 6 5 4 3 6 4 5 1 3 6 2 6 6 2 1 5 4 3 5 1 5 4 3 2 6 1 2 6 3 5 4 4 2 1 3 4 6 1 6 4 2 3 5 6 6 1 3 5 2 4 6 2 1 4 5 3 6 6 3 4 1 5 2 6 6 4 1 5 2 6 3 6 5 2 1 4 6 3 6 4 1 6 2 3 5 6 5 1 3 4 6 2 6 6 2 5 4 1 3 6 6 2 5 1 4 3 6 5 2 3 6 4 1 6 6 1 2 5 4 3 6 2 3 4 6 1 ...
output:
1 4 2 3 5 2 6 5 4 1 2 3 5 6 3 1 3 2 4 1 2 3 6 4 5 1 3 2 6 4 1 5 2 2 1 3 4 5 6 1 1 2 5 3 4 1 2 5 3 4 6 3 3 4 1 2 1 2 4 3 5 6 2 3 1 2 4 6 5 4 6 1 2 3 5 4 3 6 1 3 2 5 4 2 1 2 3 6 4 1 5 3 2 4 1 3 5 1 6 5 1 2 3 5 4 1 6 3 3 4 1 2 5 1 6 5 2 4 1 5 3 6 2 1 4 3 6 5 3 2 3 1 6 4 5 1 2 3 6 4 ...
result:
wrong answer Participant didn't find permutation (test case 1)