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 "art.h"
using namespace std;
int nPublic;
// map<pair<int, int>, bool> dict;
// bool compare(int a, int b) {
// if (dict.count({a, b})) return dict[{a, b}];
// vector<int> ask = {a};
// for (int i = 0; i<nPublic; i++) {
// if (i+1 == a || i+1 == b) continue;
// ask.push_back(i+1);
// }
// ask.push_back(b);
// int AB = publish(ask);
// ask[0] = b;
// ask[nPublic-1] = a;
// int BA = publish(ask);
// dict[{a, b}] = AB < BA;
// dict[{b, a}] = BA < AB;
// return AB < BA;
// }
int query(vector<int> a) {
for (int &i: a) i++;
return publish(a);
}
void solve(int n) {
nPublic = n;
vector<int> a;
for (int i = 0; i<n; i++) {
a.push_back(i);
}
vector<int> between0andme(n);
for (int i = 1; i<n; i++) {
swap(a[i], a[n-1]);
int one = query(a);
swap(a[n-1], a[0]);
int two = query(a);
swap(a[n-1], a[0]);
swap(a[i], a[n-1]);
between0andme[i] = abs(one-two);
}
cerr << "\n";
int extreme = max_element(between0andme.begin(), between0andme.end())-between0andme.begin();
cerr << extreme << "\n\n";
vector<int> newA = {extreme};
for (int i = 0; i<n; i++) {
if (i == extreme) continue;
newA.push_back(i);
}
vector<int> ranking(n, -1);
ranking[0] = extreme;
for (int i = 1; i<n; i++) {
swap(newA[n-1], newA[i]);
int one = query(newA);
swap(newA[n-1], newA[0]);
int two = query(newA);
swap(newA[n-1], newA[0]);
swap(newA[n-1], newA[i]);
// cout << abs(one-two) << "\n";
ranking[abs(one-two)/2 + 1] = newA[i];
}
if (query(ranking)) reverse(ranking.begin(), ranking.end());
for (int &i: ranking) i++;
answer(ranking);
}
// signed main() {
// cin.tie(0);
// ios_base::sync_with_stdio(0);
// int n; cin >> n;
// deque<int> a(n);
// for (int i = 0; i<n; i++) cin >> a[i];
// for (int i = 0; i<n; i++) {
// int cnt = 0;
// for (int i = 0; i<n; i++) {
// for (int j = i+1; j<n; j++) {
// if (a[i]>a[j]) cnt++;
// }
// }
// a.push_back(a[0]);
// a.pop_front();
// cout << cnt << "\n";
// }
// return 0;
// }
Compilation message (stderr)
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
20 | if(v.size() != N) {
| ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | if(v.size() != N) {
| ~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |