Submission #47573

# Submission time Handle Problem Language Result Execution time Memory
47573 2018-05-05T04:42:16 Z dqhungdl Crazy old lady (IZhO13_crazy) C++17
100 / 100
14 ms 740 KB
#include <bits/stdc++.h>
using namespace std;

int T,n,a[1005];
bool Free[1005];

bool Check(int crazyid)
{
	for(int i=1;i<=n;i++)
		Free[i]=false;
	Free[a[1]]=true;
	int curid=1;
	for(int i=2;i<=n;i++)
	{
		if(curid==crazyid)
			curid++;
		if((Free[curid]==false&&a[i]!=curid)||Free[a[i]]==true)
			return false;
		Free[a[i]]=true;
		curid++;
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("TEST.INP","r",stdin);
	//freopen("TEST.OUT","w",stdout);
	cin>>T;
	while(T--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		int id,res=0;
		for(int i=1;i<=n;i++)
			if(Check(i)==true)
			{
				res++;
				id=i;
			}
		cout<<(res==1?id:0)<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 2 ms 552 KB Output is correct
7 Correct 2 ms 552 KB Output is correct
8 Correct 3 ms 552 KB Output is correct
9 Correct 3 ms 552 KB Output is correct
10 Correct 3 ms 580 KB Output is correct
11 Correct 4 ms 708 KB Output is correct
12 Correct 4 ms 708 KB Output is correct
13 Correct 5 ms 708 KB Output is correct
14 Correct 6 ms 708 KB Output is correct
15 Correct 7 ms 708 KB Output is correct
16 Correct 10 ms 708 KB Output is correct
17 Correct 8 ms 708 KB Output is correct
18 Correct 13 ms 708 KB Output is correct
19 Correct 11 ms 708 KB Output is correct
20 Correct 14 ms 740 KB Output is correct