답안 #90599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
90599 2018-12-22T19:59:40 Z popovicirobert 성질 급한 지학이 (IZhO13_crazy) C++14
100 / 100
17 ms 1088 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = 1000;

int arr[MAXN + 1];
bool vis[MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, t, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> t;
    while(t > 0) {
        t--;
        cin >> n;
        for(i = 1; i <= n; i++) {
            cin >> arr[i];
        }
        int ans = 0;
        int sol;
        for(int pos = 1; pos <= n; pos++) {
            int j = 1;
            bool ok = 1;
            memset(vis, 0, sizeof(vis));
            for(i = 1; i <= n; i++) {
                if(i > 1) {
                    if(j == pos) {
                        j++;
                    }
                    if(vis[j] == 0 && arr[i] != j) {
                        ok = 0;
                    }
                    j++;
                }
                vis[arr[i]] = 1;
            }
            ans += ok;
            if(ok) {
                sol = pos;
                //cerr << pos << " ";
            }
        }
        //cerr << "\n";
        if(ans == 1) {
            cout << sol << "\n";
        }
        else {
            cout << 0 << "\n";
        }
    }
    //cin.close();
    //cout.close();
    return 0;
}

Compilation message

crazy.cpp: In function 'int main()':
crazy.cpp:55:28: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
             cout << sol << "\n";
                            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 564 KB Output is correct
4 Correct 2 ms 564 KB Output is correct
5 Correct 2 ms 564 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Correct 2 ms 564 KB Output is correct
8 Correct 3 ms 564 KB Output is correct
9 Correct 4 ms 764 KB Output is correct
10 Correct 4 ms 764 KB Output is correct
11 Correct 5 ms 764 KB Output is correct
12 Correct 6 ms 796 KB Output is correct
13 Correct 6 ms 816 KB Output is correct
14 Correct 8 ms 964 KB Output is correct
15 Correct 8 ms 964 KB Output is correct
16 Correct 12 ms 1028 KB Output is correct
17 Correct 11 ms 1028 KB Output is correct
18 Correct 16 ms 1028 KB Output is correct
19 Correct 16 ms 1052 KB Output is correct
20 Correct 17 ms 1088 KB Output is correct