QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#478022 | #8838. Jesse's Job | Rosmontispes | WA | 1ms | 3612kb | C++20 | 1.5kb | 2024-07-14 15:39:52 | 2024-07-14 15:39:52 |
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;
for(int i = 1;i <= n;i ++)
cin>>ar[i];
vector<int>ans;
vector<int>vis(n + 1);
bool ok = 0;
for(int i = 1;i <= n;i ++)
{
if(ar[i] != i)
{
int res = i;
int cnt = 1;
vis[res] =1 ;
ans.push_back(res);
while(ar[res] != i)
{
ans.push_back(ar[res]);
vis[ar[res]] = 1;
swap(ar[res],ar[ar[res]]);
cnt ++;
}
if(cnt != n)
ok = 1;
}
else
if(!vis[i])
ans.push_back(i),ok = 1;
if(ok)
break;
}
if(ok)
{
cout<<n<<"\n";
cout<<(int)ans.size()<<"\n";
for(auto v:ans)
cout<<v<<" ";
cout<<"\n";
}
else
{
cout<<n - 2<<"\n";
vector<int>anss;
for(int i = 0;i < n / 2;i ++)
{
if(ans[i] == 2)
break;
anss.push_back(ans[i]);
}
cout<<(int)anss.size()<<"\n";
for(auto v:anss)
cout<<v<<" ";
cout<<"\n";
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
cin>>T;
while(T --)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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 3 1 3 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3536kb
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 5 4 3 4 2 1 2 6 3 1 2 3 6 4 1 4 6 3 6 4 1 6 5 4 5 2 1 2 6 1 1 4 2 1 2 6 1 1 6 3 1 6 2 6 2 1 2 6 2 1 3 6 5 1 4 3 5 2 6 3 1 5 3 6 3 1 4 2 6 3 1 5 2 6 2 1 6 6 5 1 6 4 3 5 6 4 1 5 3 4 6 5 1 6 5 4 2 6 5 1 2 3 4 6 6 5 1 5 3 2 6 6 2 1 4 4 2 1 4 6 2 1 3 6 1 1 6 1 1 6 ...
result:
wrong answer Participant didn't find permutation (test case 30)