# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97448 | Kastanda | Crazy old lady (IZhO13_crazy) | C++11 | 10 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I do it for the glory
#include<bits/stdc++.h>
using namespace std;
const int N = 1003;
int n, q, P[N], M[N];
inline bool Check(int id)
{
memset(M, 0, sizeof(M));
M[P[1]] = 1;
for (int i = 1; i <= n; i++)
if (i != id)
{
int j = i + (i < id);
if (M[P[j]])
return 0;
if (P[j] != i && !M[i])
return 0;
M[P[j]] = 1;
}
return 1;
}
int main()
{
scanf("%d", &q);
for (; q; q --)
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &P[i]);
int cz = -1;
for (int i = 1; i <= n; i++)
if (Check(i))
{
if (cz != -1)
{cz = -2; break;}
else
cz = i;
}
if (cz == -2)
printf("0\n");
else
printf("%d\n", cz);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |