Submission #958562

#TimeUsernameProblemLanguageResultExecution timeMemory
958562adaawfCrazy old lady (IZhO13_crazy)C++14
100 / 100
7 ms456 KiB
#include <iostream>
using namespace std;
int a[1005], dd[1005];
int main() {
    int t;
    cin >> t;
    for (int jj = 0; jj < t; jj++) {
        int n, c = 0, res = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        for (int k = 1; k <= n; k++) {
            int flag = 0;
            for (int i = 1; i <= n; i++) dd[i] = 0;
            dd[a[1]] = 1;
            int j = 1;
            for (int i = 1; i <= n; i++) {
                if (i == k) continue;
                j++;
                if (dd[i] == 0 && a[j] != i) {
                    flag = 1;
                    break;
                }
                dd[a[j]] = 1;
            }
            if (flag == 0) {
                c++;
                res = k;
            }
        }
        if (c > 1) cout << 0;
        else cout << res;
        cout << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...