#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[1]]=1;
int assigned=0;
for(int i=2;i<=n;i++)
{
assigned++;
if(assigned==lady) assigned++;
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=i;
else
{
unde=0;
break;
}
}
}
//cout<<" zzz\n";
cout<<unde<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
484 KB |
Output is correct |
18 |
Correct |
4 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
348 KB |
Output is correct |
20 |
Correct |
5 ms |
500 KB |
Output is correct |