# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
882528 | alexdd | Crazy old lady (IZhO13_crazy) | C++17 | 1 ms | 348 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<iostream>
using namespace std;
int n;
int p[1005];
bool occupied[1005];
bool verif(int lady)
{
for(int i=1;i<=n;i++)
occupied[i]=0;
occupied[p[lady]]=1;
int assigned=0;
for(int i=1;i<=n;i++)
{
assigned++;
if(i==lady)
{
assigned--;
continue;
}
if(!occupied[assigned])
{
if(p[i]!=assigned)
return 0;
occupied[p[i]]=1;
}
else
{
if(p[i]==assigned)
return 0;
occupied[p[i]]=1;
}
}
return 1;
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>p[i];
}
int unde=-1;
for(int i=1;i<=n;i++)
{
if(verif(i))
{
// cout<<i<<" ";
// continue;
if(unde==-1)
unde=p[i];
else
{
unde=0;
break;
}
}
}
// cout<<" zzz\n";
cout<<unde<<"\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |