Submission #1010727

# Submission time Handle Problem Language Result Execution time Memory
1010727 2024-06-29T10:03:39 Z ivopav Crazy old lady (IZhO13_crazy) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

bool dob(vector<int> lis2,vector<int> lis,int ind,int n){
    vector<bool> bio(n,0);
    bio[ind]=1;
    for (int i=0;i<n;i++){
        if (i==lis2[ind]){
            continue;
        }
        if (bio[i]==0 && lis2[i]!=i){
            return 0;
        }
        bio[lis[i]]=1;
    }
    return 1;
}

void prim(){
    int n;
    cin >> n;
    vector<int> lis2={};
    vector<int> lis(n,0);
    for (int i=0;i<n;i++){
        int unos;
        cin >> unos;
        lis2.push_back(--unos);
        lis[unos]=i;
    }
    vector<int> rje={};
    for (int i=0;i<n;i++){
        if (dob(lis2,lis,i,n)){
            rje.push_back(i);
        }
    }
    if (rje.size()==1){
        cout << rje[0]+1 << "\n";
    }
    else {
        cout << "0\n";
    }
    
}

int main(){
    long long int t;
    cin >> t;
    for (long long int i=0;i<t;i++){
        prim();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -