Submission #341118

#TimeUsernameProblemLanguageResultExecution timeMemory
341118juggernautCrazy old lady (IZhO13_crazy)C++14
100 / 100
19 ms512 KiB
#include<bits/stdc++.h>
using namespace std;
int a[1000];
bool flag[1001];
int main(){
	int test;
	scanf("%d",&test);
	while(test--){
		int ans=0,i,j,n,t;
		scanf("%d",&n);
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++)flag[j]=false;
			flag[a[0]]=true;
			for(j=1;j<n;j++){
				t=j;
				if(t>=i)t++;
				if(!flag[t]&&a[j]!=t)break;
				flag[a[j]]=true;
			}
			if(j==n){
				if(ans)ans=-1;
				else ans=i;
			}
		}
		ans=max(ans,0);
		printf("%d\n",ans);
	}
}

Compilation message (stderr)

crazy.cpp: In function 'int main()':
crazy.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |  scanf("%d",&test);
      |  ~~~~~^~~~~~~~~~~~
crazy.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
crazy.cpp:11:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |   for(i=0;i<n;i++)scanf("%d",&a[i]);
      |                   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...