#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define setbit(s, i) (s|=(1LL<<(i)))
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
char c;
bool nega=0;
while((!isdigit(c=getchar()))&&(c!='-'));
if(c=='-'){
nega=1;
c=getchar();
}
x=c-48;
while(isdigit(c=getchar())) x=x*10+c-48;
if(nega) x=-x;
}
template <typename T> inline void writep(T x){
if(x>9) writep(x/10);
putchar(x%10+48);
}
template <typename T> inline void write(T x){
if(x<0){
putchar('-');
x=-x;
}
writep(x);
}
template <typename T> inline void writeln(T x){
write(x);
putchar('\n');
}
#define taskname "E"
int n;
int p[1001];
bool used[1001];
bool check(int u){
FOR(i, 1, n) used[i]=0;
used[p[1]]=1;
int j=1;
FFOR(i, 1, u){
j++;
if((!used[i])&&(p[j]!=i)) return 0;
used[p[j]]=1;
}
FOR(i, u+1, n){
j++;
if((!used[i])&&(p[j]!=i)) return 0;
used[p[j]]=1;
}
return 1;
}
void solve(){
read(n);
FOR(i, 1, n) read(p[i]);
vector <int> ans;
FOR(j, 1, n) if(check(j)){
ans.pb(j);
if(ans.size()>1){
puts("0");
return;
}
}
writeln(ans[0]);
}
int main(){
#ifdef Kanikou
if(fopen(taskname".inp", "r"))
freopen(taskname".inp", "r", stdin);
#endif // Kanikou
int t;
read(t);
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
3 ms |
544 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
628 KB |
Output is correct |
13 |
Correct |
4 ms |
628 KB |
Output is correct |
14 |
Correct |
4 ms |
628 KB |
Output is correct |
15 |
Correct |
6 ms |
628 KB |
Output is correct |
16 |
Correct |
6 ms |
628 KB |
Output is correct |
17 |
Correct |
7 ms |
628 KB |
Output is correct |
18 |
Correct |
10 ms |
628 KB |
Output is correct |
19 |
Correct |
9 ms |
628 KB |
Output is correct |
20 |
Correct |
11 ms |
628 KB |
Output is correct |