Submission #1029200

# Submission time Handle Problem Language Result Execution time Memory
1029200 2024-07-20T13:45:48 Z Minbaev Crazy old lady (IZhO13_crazy) C++17
100 / 100
8 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
const ll maxn = 1007;
	
ll t, n, cnt, sol;
ll seats[maxn];
ll visited[maxn];
 
void solve(){
	cnt = 0, sol = 0;
	cin >> n;
	
   	for (int i = 0; i < n; i++) {
        cin >> seats[i], seats[i]--;
    }
    
    for (int k = 0; k < n; k++) {
    	
        bool pos = true;
        
        for (int i = 0; i < n; i++) visited[i] = 0;
        
        visited[seats[0]] = 1;
        int j = 0;
        
        for (int i = 0; i < n; i++) {
        	
            if (i == k) continue;
            
            j++;
            if (visited[i] == 0 && seats[j] != i) {
                pos = false;
                break;
            }
            
            visited[seats[j]] = 1;
        }
        
        if (pos) {
            cnt++;
            sol = k;
        }
    }
    
    if (cnt > 1) cout << "0\n";
    else cout << sol+1 << '\n';
}
	
int main(){
	cin >> t;
	
	while(t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 4 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 5 ms 348 KB Output is correct
20 Correct 8 ms 344 KB Output is correct