Submission #97448

#TimeUsernameProblemLanguageResultExecution timeMemory
97448KastandaCrazy old lady (IZhO13_crazy)C++11
100 / 100
10 ms512 KiB
// 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)

crazy.cpp: In function 'int main()':
crazy.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
crazy.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &n);
         ~~~~~^~~~~~~~~~
crazy.cpp:29:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &P[i]);
             ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...