# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
343304 | apostoldaniel854 | Crazy old lady (IZhO13_crazy) | C++14 | 36 ms | 492 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>
using namespace std;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
using ll = long long;
const int MAX_N = 1000;
int p[1 + MAX_N];
bool used[1 + MAX_N];
void solveTest () {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
vector <int> crazy_old_lady_seat;
for (int pos = 1; pos <= n; pos++) {
for (int i = 1; i <= n; i++)
used[i] = false;
used[p[1]] = true;
bool ok = true;
for (int i = 2; i <= n; i++) {
int to_take = i;
if (to_take <= pos)
to_take--;
if (p[i] != to_take && not used[to_take])
ok = false;
used[p[i]] = true;
}
if (ok)
crazy_old_lady_seat.pb (pos);
}
if (crazy_old_lady_seat.size () != 1)
cout << 0 << "\n";
else
cout << crazy_old_lady_seat.back () << "\n";
}
int main () {
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int t;
cin >> t;
while (t--)
solveTest ();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |