| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 47560 | JohnTitor | 성질 급한 지학이 (IZhO13_crazy) | C++11 | 11 ms | 628 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define setbit(s, i) (s|=(1LL<<(i)))
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "E"
int n;
int p[1001];
bool used[1001];
bool check(int u){
    FOR(i, 1, n) used[i]=0;
    used[p[1]]=1;
    int j=1;
    FFOR(i, 1, u){
        j++;
        if((!used[i])&&(p[j]!=i)) return 0;
        used[p[j]]=1;
    }
    FOR(i, u+1, n){
        j++;
        if((!used[i])&&(p[j]!=i)) return 0;
        used[p[j]]=1;
    }
    return 1;
}
void solve(){
    read(n);
    FOR(i, 1, n) read(p[i]);
    vector <int> ans;
    FOR(j, 1, n) if(check(j)){
        ans.pb(j);
        if(ans.size()>1){
            puts("0");
            return;
        }
    }
    writeln(ans[0]);
}
int main(){
    #ifdef Kanikou
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Kanikou
    int t;
    read(t);
    while(t--) solve();
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
