Submission #92654

# Submission time Handle Problem Language Result Execution time Memory
92654 2019-01-04T09:34:23 Z SamAnd Crazy old lady (IZhO13_crazy) C++17
100 / 100
10 ms 632 KB
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1003;
void sp();
void fp();

int n;
int a[N];
bool c[N];
int main()
{
	//fp();
	int tt;
	cin>>tt;
	for(int ii=0;ii<tt;++ii)
	{
		cin>>n;
		for(int i=1;i<=n;++i)
		{
			cin>>a[i];
			c[i]=false;
		}
		int ans=0;
		for(int i=1;i<=n;++i)
		{
			for(int i=1;i<=n;++i)
				c[i]=false;
			c[a[1]]=true;
			bool z=true;
			for(int j=1,k=2;j<=n,k<=n;++j,++k)
			{
				if(j==i)
				{
					--k;
					continue;
				}
				if(a[k]!=j && !c[j])
				{
					z=false;
					break;
				}
				c[a[k]]=true;
			}
			if(z && !ans)
				ans=i;
			else if(z && ans)
			{
				ans=0;
				break;
			}
		}
		cout<<ans<<endl;
	}
	sp();
	return 0;
}

void fp()
{
#ifndef OLYMP
	freopen("crazy.in","r",stdin);
	freopen("crazy.out","w",stdout);
#endif
}
void sp()
{
#ifdef OLYMP
	system("pause");
#endif
}

Compilation message

crazy.cpp: In function 'int main()':
crazy.cpp:31:21: warning: left operand of comma operator has no effect [-Wunused-value]
    for(int j=1,k=2;j<=n,k<=n;++j,++k)
                    ~^~~
crazy.cpp: In function 'void fp()':
crazy.cpp:62:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("crazy.in","r",stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
crazy.cpp:63:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("crazy.out","w",stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 4 ms 404 KB Output is correct
11 Correct 4 ms 380 KB Output is correct
12 Correct 4 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 7 ms 376 KB Output is correct
18 Correct 10 ms 376 KB Output is correct
19 Correct 8 ms 376 KB Output is correct
20 Correct 10 ms 380 KB Output is correct