Submission #101050

#TimeUsernameProblemLanguageResultExecution timeMemory
101050choikiwonCrazy old lady (IZhO13_crazy)C++17
100 / 100
18 ms512 KiB
#include<bits/stdc++.h>
using namespace std;

const int MN = 1010;

int N;
int P[MN];

void main2() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d", &P[i]);
        P[i]--;
    }

    int ans = -1;
    for(int i = 0; i < N; i++) {
        vector<int> chk(N, 0);

        chk[ P[0] ] = 1;
        int t = i != 0, ok = 1;
        for(int j = 1; j < N; j++) {
            if(j - t == i) t = 0;

            //cout << i << ' ' << j - t << endl;

            if(!chk[j - t] && P[j] != j - t) {
                ok = 0;
                break;
            }
            chk[ P[j] ] = 1;
        }

        if(ok) {
            if(ans == -1) ans = i;
            else {
                ans = -1;
                break;
            }
        }
    }

    if(ans == -1) printf("0\n");
    else printf("%d\n", ans + 1);
}

int TC;
int main() {
    scanf("%d", &TC);
    while(TC--) main2();
}

Compilation message (stderr)

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