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>
#include "grader.h"
using namespace std;
void solve(int N) {
vector <int> g(N), ans(N);
for (int i = 0; i < N; i++)
g[i] = i+1;
random_shuffle(g.begin(), g.end());
int C = query(g), t;
for (int i = 0; i < N; i++) {
if (ans[i]) continue;
int a = 0, b = 0;
for (int j = i+1; j < N; j++) {
if (ans[j]) continue;
swap(g[i], g[j]);
t = query(g);
swap(g[i], g[j]);
if (t == C + 2) {
ans[i] = g[i];
ans[j] = g[j];
swap(g[i], g[j]);
break;
} else if (t == C + 1) {
if (!a) a = j;
else {
b = j;
break;
}
}
}
swap(g[i], g[a]);
swap(g[i], g[b]);
t = query(g);
if (t >= C + 2) {
ans[i] = g[i];
ans[a] = g[a];
if (t == C + 3)
ans[b] = g[b];
} else {
swap(g[i], g[b]);
swap(g[i], g[a]);
swap(g[i], g[b]);
swap(g[i], g[a]);
t = query(g);
ans[i] = g[i];
ans[b] = g[b];
if (t == C + 3)
ans[a] = g[a];
}
C = t;
}
return;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |