# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
690488 | 2023-01-30T08:27:54 Z | Kalashnikov | Crazy old lady (IZhO13_crazy) | C++17 | 23 ms | 380 KB |
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second using namespace std; using ll = long long; const int N = 2e5+5 , inf = 2e9 + 7; const ll INF = 1e18 , mod = 1e9+7 , P = 6547; int p[N]; int p1[N]; void solve(int tc) { int n; cin >> n; for(int i = 1; i <= n; i ++) { cin >> p[i]; } vector<int> vec; for(int i = 1; i <= n; i ++) { p1[1] = i; int cur = 1; for(int j = 2; j <= n; j ++) { if(cur == i) cur ++; p1[j] = cur; cur ++; } vector<int> u(n+1 , 0); u[p[1]] = 1; int ok = 1; for(int j = 2; j <= n; j ++) { if(u[p1[j]] == 0) { if(p[j] != p1[j]) { ok = 0; break; } u[p[j]] = 1; } else { if(u[p[j]] == 1) { ok = 0; break; } u[p[j]] = 1; } } if(ok) vec.push_back(i); } if(vec.size() == 1) { cout << vec[0] << '\n'; } else cout << "0\n"; } /* */ main() { file("crazy"); ios; int tt = 1 , tc = 0; cin >> tt; while(tt --) { solve(++tc); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 328 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 2 ms | 344 KB | Output is correct |
9 | Correct | 3 ms | 340 KB | Output is correct |
10 | Correct | 3 ms | 340 KB | Output is correct |
11 | Correct | 4 ms | 340 KB | Output is correct |
12 | Correct | 4 ms | 340 KB | Output is correct |
13 | Correct | 6 ms | 340 KB | Output is correct |
14 | Correct | 7 ms | 344 KB | Output is correct |
15 | Correct | 10 ms | 340 KB | Output is correct |
16 | Correct | 12 ms | 380 KB | Output is correct |
17 | Correct | 12 ms | 340 KB | Output is correct |
18 | Correct | 19 ms | 340 KB | Output is correct |
19 | Correct | 16 ms | 340 KB | Output is correct |
20 | Correct | 23 ms | 340 KB | Output is correct |