# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
690488 | Kalashnikov | Crazy old lady (IZhO13_crazy) | C++17 | 23 ms | 380 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |