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;
int n;
int ask(const vector<int> &q) {
int x = query(q);
if (x == n) {
exit(0);
}
return x;
}
mt19937 rng(123123);
void solve(int n) {
::n = n;
vector<int> a(n);
iota(a.begin(), a.end(), 1);
int cur = ask(a);
for (int i = 0; i <= 0; i++) {
for (int j = i + 1; j < n; j++) {
swap(a[i], a[j]);
int tmp = ask(a);
if (tmp > cur) {
cur = tmp;
} else {
swap(a[i], a[j]);
}
}
}
vector<int> candidates;
for (int i = 1; i < n; i++) {
swap(a[i], a[0]);
int x = ask(a);
swap(a[i], a[0]);
if (cur - x == 2) continue;
candidates.emplace_back(i);
}
auto shift = [&](const vector<int> &v, bool invert = 0, bool answer = 1) {
vector<int> b(v.size());
for (int i = 0; i < v.size(); i++) b[i] = a[v[i]];
for (int i = 0; i < v.size(); i++) a[v[i]] = b[(i + 1) % v.size()];
int res = answer ? ask(a) : 0;
if (invert) {
for (int i = 0; i < v.size(); i++) a[v[i]] = b[i];
}
return res;
};
while (true) {
int diff = shift(candidates, 1) - cur;
if (diff == 0) {
shift(candidates, 0, 0);
continue;
}
int last = -1;
vector<int> good(candidates.size());
for (int d = 1; d <= diff; d++) {
int low = last + 1, high = candidates.size() - 1;
while (low < high) {
int mid = low + high >> 1;
vector<int> tmp;
for (int i = 0; i <= mid; i++) tmp.emplace_back(candidates[i]);
if (tmp.size() != candidates.size()) {
tmp.emplace_back(0);
tmp.emplace_back(candidates.back());
}
if (shift(tmp, 1) - cur >= d - (mid != candidates.size() ? 1 : 0)) {
high = mid;
} else {
low = mid + 1;
}
}
last = high;
good[(high + candidates.size() - 1) % candidates.size()] = 1;
}
shift(candidates, 0, 0);
vector<int> ncan;
for (int i = 0; i < candidates.size(); i++) {
if (!good[i]) ncan.emplace_back(candidates[i]);
}
ncan.swap(candidates);
cur += diff;
}
ask(a);
}
Compilation message (stderr)
mouse.cpp: In lambda function:
mouse.cpp:46:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i = 0; i < v.size(); i++) b[i] = a[v[i]];
| ~~^~~~~~~~~~
mouse.cpp:47:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < v.size(); i++) a[v[i]] = b[(i + 1) % v.size()];
| ~~^~~~~~~~~~
mouse.cpp:50:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < v.size(); i++) a[v[i]] = b[i];
| ~~^~~~~~~~~~
mouse.cpp: In function 'void solve(int)':
mouse.cpp:66:47: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
66 | int mid = low + high >> 1;
| ~~~~^~~~~~
mouse.cpp:73:69: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if (shift(tmp, 1) - cur >= d - (mid != candidates.size() ? 1 : 0)) {
| ~~~~^~~~~~~~~~~~~~~~~~~~
mouse.cpp:84:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i = 0; i < candidates.size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |