#include <bits/stdc++.h>
using namespace std;
void prim(){
int n;
cin >> n;
vector<int> lis={0};
for (int i=0;i<n;i++){
int unos;
cin >> unos;
lis.push_back(unos);
}
vector<int> rje={};
for (int i=1;i<=n;i++){
bool dob=1;
vector<bool> bio(n,0);
bio[lis[1]]=1;
for (int j=1;j<i;j++){
if (bio[j]==0 && lis[j+1]!=j){
dob=0;
break;
}
bio[lis[j+1]]=1;
}
for (int j=i+1;j<=n;j++){
if (bio[j]==0 && lis[j]!=j){
dob=0;
break;
}
bio[lis[j]]=1;
}
if (dob){
rje.push_back(i);
}
}
if (rje.size()==1){
cout << rje[0] << "\n";
}
else {
cout << "0\n";
}
}
int main(){
long long int t;
cin >> t;
for (long long int i=0;i<t;i++){
prim();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 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 |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
4 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
600 KB |
Output is correct |
16 |
Correct |
5 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
7 ms |
348 KB |
Output is correct |
19 |
Correct |
8 ms |
348 KB |
Output is correct |
20 |
Correct |
10 ms |
348 KB |
Output is correct |