Submission #101050

# Submission time Handle Problem Language Result Execution time Memory
101050 2019-03-16T07:30:14 Z choikiwon Crazy old lady (IZhO13_crazy) C++17
100 / 100
18 ms 512 KB
#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

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 time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 8 ms 512 KB Output is correct
17 Correct 13 ms 384 KB Output is correct
18 Correct 14 ms 384 KB Output is correct
19 Correct 13 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct