답안 #97448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97448 2019-02-16T08:42:12 Z Kastanda 성질 급한 지학이 (IZhO13_crazy) C++11
100 / 100
10 ms 512 KB
// 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

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]);
             ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 9 ms 384 KB Output is correct
19 Correct 9 ms 384 KB Output is correct
20 Correct 10 ms 384 KB Output is correct