답안 #5656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5656 2014-05-10T03:54:38 Z baneling100 성질 급한 지학이 (IZhO13_crazy) C++
100 / 100
12 ms 1096 KB
#include <stdio.h>

int T, N, P[1001], check[1001], ans;

void input(void)
{
    int i;

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

void process(void)
{
    int i, j, now, ok;

    for(i=1 ; i<=N ; i++)
    {
        for(j=1 ; j<=N ; j++)
            check[j]=0;
        check[P[1]]=ok=1;
        now=0;
        for(j=2 ; j<=N && ok ; j++)
        {
            now++;
            if(now==i)
                now++;
            if(check[now])
            {
                if(now==P[j])
                    ok=0;
                else
                {
                    if(check[P[j]])
                        ok=0;
                    else
                        check[P[j]]=1;
                }
            }
            else
            {
                if(now==P[j])
                    check[now]=1;
                else
                    ok=0;
            }
        }
        if(ok)
        {
            if(ans)
            {
                ans=0;
                break;
            }
            else
                ans=i;
        }
    }
}

void output(void)
{
    printf("%d\n",ans);
}

int main(void)
{
    int i;

    scanf("%d",&T);
    for(i=1 ; i<=T ; i++)
    {
        input();
        process();
        output();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1096 KB Output is correct
2 Correct 0 ms 1096 KB Output is correct
3 Correct 0 ms 1096 KB Output is correct
4 Correct 0 ms 1096 KB Output is correct
5 Correct 0 ms 1096 KB Output is correct
6 Correct 0 ms 1096 KB Output is correct
7 Correct 0 ms 1096 KB Output is correct
8 Correct 0 ms 1096 KB Output is correct
9 Correct 0 ms 1096 KB Output is correct
10 Correct 0 ms 1096 KB Output is correct
11 Correct 0 ms 1096 KB Output is correct
12 Correct 0 ms 1096 KB Output is correct
13 Correct 0 ms 1096 KB Output is correct
14 Correct 4 ms 1096 KB Output is correct
15 Correct 8 ms 1096 KB Output is correct
16 Correct 8 ms 1096 KB Output is correct
17 Correct 8 ms 1096 KB Output is correct
18 Correct 12 ms 1096 KB Output is correct
19 Correct 12 ms 1096 KB Output is correct
20 Correct 12 ms 1096 KB Output is correct