QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#477952 | #8838. Jesse's Job | Rosmontispes | WA | 0ms | 3596kb | C++20 | 1.4kb | 2024-07-14 13:55:22 | 2024-07-14 13:55:22 |
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 ;
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 - 1<<"\n";
cout<<n / 2<<"\n";
for(int i = 0;i < n / 2;i ++)
cout<<ans[i]<<" ";
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: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
3 2 2 1 4 2 1 4 3 6 3 5 4 2 6 1
output:
0 1 2 4 1 2 2 3 3 4 2
result:
wrong answer Participant didn't find permutation (test case 2)