답안 #355219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
355219 2021-01-22T10:23:08 Z nicolaalexandra 성질 급한 지학이 (IZhO13_crazy) C++14
100 / 100
20 ms 512 KB
#include <bits/stdc++.h>
#define DIM 1010
using namespace std;

int v[DIM],f[DIM];
int t,n,i;

int check (int poz){

    memset (f,0,sizeof f);


    f[v[1]] = 1;
    for (int i=2;i<=n;i++){

        if (i <= poz){

            if (!f[i-1] && v[i] != i-1)
                return 0;

            if (f[v[i]])
                return 0;
            f[v[i]] = 1;

        } else {
            if (!f[i] && v[i] != i)
                return 0;

            if (f[v[i]])
                return 0;
            f[v[i]] = 1;
        }

    }

    return 1;
}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>t;
    for (;t--;){
        cin>>n;

        for (i=1;i<=n;i++)
            cin>>v[i];

        int sol = 0, cnt = 0;
        for (i=1;i<=n;i++){
            if (check(i)){
                sol = i;
                cnt++;
            }
        }

        if (cnt == 1)
            cout<<sol<<"\n";
        else cout<<"0\n";

    }



    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 4 ms 396 KB Output is correct
11 Correct 4 ms 364 KB Output is correct
12 Correct 4 ms 364 KB Output is correct
13 Correct 5 ms 364 KB Output is correct
14 Correct 7 ms 364 KB Output is correct
15 Correct 9 ms 364 KB Output is correct
16 Correct 13 ms 364 KB Output is correct
17 Correct 10 ms 364 KB Output is correct
18 Correct 17 ms 364 KB Output is correct
19 Correct 14 ms 364 KB Output is correct
20 Correct 20 ms 364 KB Output is correct