#include<bits/stdc++.h>
using namespace std;
const int MAXN=1024;
int t;
int a[MAXN];
bool taken[MAXN];
void solve()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
set<int>possible;
for(int lady=1;lady<=n;lady++)
{
memset(taken,0,sizeof(taken));
taken[a[1]]=1;
bool ok=1;
for(int j=1;j<lady;j++)
{
if(taken[j]==0&&a[j+1]!=j)
{
ok=0;break;
}
taken[a[j+1]]=1;
}
for(int j=lady+1;j<=n;j++)
{
if(taken[j]==0&&a[j]!=j)
{
ok=0;break;
}
taken[a[j]]=1;
}
if(ok)possible.insert(lady);
}
if(possible.size()==1)
{
cout<<(*possible.begin())<<endl;
}
else
{
cout<<0<<endl;
}
}
int main()
{
cin>>t;
while(t--)solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
308 KB |
Output is correct |
9 |
Correct |
3 ms |
208 KB |
Output is correct |
10 |
Correct |
4 ms |
316 KB |
Output is correct |
11 |
Correct |
4 ms |
312 KB |
Output is correct |
12 |
Correct |
6 ms |
208 KB |
Output is correct |
13 |
Correct |
6 ms |
336 KB |
Output is correct |
14 |
Correct |
8 ms |
336 KB |
Output is correct |
15 |
Correct |
8 ms |
208 KB |
Output is correct |
16 |
Correct |
12 ms |
340 KB |
Output is correct |
17 |
Correct |
10 ms |
208 KB |
Output is correct |
18 |
Correct |
16 ms |
336 KB |
Output is correct |
19 |
Correct |
16 ms |
336 KB |
Output is correct |
20 |
Correct |
19 ms |
336 KB |
Output is correct |