# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
848289 | Darren0724 | Crazy old lady (IZhO13_crazy) | C++17 | 1 ms | 344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n;cin>>n;
vector<int> v(n+1),pos(n+1);
for(int i=1;i<=n;i++){
cin>>v[i];
pos[v[i]]=i;
}
vector<int> ans;
for(int i=1;i<=n;i++){
vector<int> a(n+1);
a[i]=1;
int flag=1;
int cnt=0;
for(int j=1;j<=n;j++){
if(j==v[i]){
continue;
}
cnt++;
int seat=-1;
if(a[j]==0){
seat=j;
if(v[j]!=j){
flag=0;
break;
}
}
else if(a[pos[j]]==0){
seat=pos[j];
}
else{
flag=0;
break;
}
if(cnt!=n-1&&seat==v[i]){
flag=0;
break;
}
a[seat]=1;
}
if(flag){
ans.push_back(i);
}
}
cout<<(ans.size()==1?ans[0]:0)<<endl;
}
int32_t main() {
int t;cin>>t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |