# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1171800 | Iskachun | Art Collections (BOI22_art) | C++20 | 0 ms | 0 KiB |
#include <iostream>
#include <vector>
#include <set>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include "art.h"/*
using namespace std;
typedef long long ll;
namespace {
int N;
int Q = 0;
const int MAX_Q = 4000;
const int MAX_N = 4000;
vector<int> solution;
}
void __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) result(const char *msg, ...) {
va_list args;
va_start(args, msg);
vfprintf(stdout, msg, args);
fprintf(stdout, "\n");
va_end(args);
exit(0);
}
void __attribute__((noreturn)) answer(vector<int> R) {
printf("answer({");
for(int i = 0; i < int(R.size()); ++i) {
if(i == 0)
printf("%d", R[i]);
else
printf(", %d", R[i]);
}
printf("})\n");
fflush(stdout);
if(R == solution)
result("Correct: %d published ranking(s).", Q);
else
result("Wrong answer!");
}
int publish(vector<int> R) {
printf("publish({");
for(int i = 0; i < int(R.size()); ++i) {
if(i == 0)
printf("%d", R[i]);
else
printf(", %d", R[i]);
}
printf("})\n");
fflush(stdout);
if (++Q > MAX_Q)
result("Too many published rankings!");
if (int(R.size()) != N)
result("Invalid published ranking!");
set<int> chosen;
for(auto &x : R) {
if(x < 1 || x > N || chosen.count(x))
result("Invalid published ranking!");
chosen.insert(x);
}
vector<int> positions(N+1);
for(int i = 0; i < N; ++i)
positions[R[i]] = i;
int complaints = 0;
for(int i = 0; i < N; ++i) {
for(int j = i+1; j < N; ++j) {
if(positions[solution[i]] > positions[solution[j]])
++complaints;
}
}
return complaints;
}*/
void solve(int n) {
vector<int> ans(n);
for (int i = 1; i <= n; i++) ans[i - 1] = i;
int x = publish(ans);
while (x) {
for (int i = 1; i < n; i++) {
vector<int> curr = ans;
swap(curr[i], curr[i - 1]);
int y = publish(curr);
if (y < x) ans = curr, i++, x = y;
}
}
answer(ans);
/// use of functions
/*std::vector<int> order = {1, 2, 3};
publish(order);
order = {2, 3, 1};
publish(order);
order = {1, 3, 2};
answer(order);*/
}/*
int main() {
//freopen("filename.in", "r", stdin), freopen("filename.out", "w", stdout);
//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//int t = 1; //cin >> t;
//while (t--) solve();
if (scanf("%d", &N) != 1 || N < 2 || N > MAX_N)
result("Invalid input!");
solution.resize(N);
set<int> chosen;
for(auto &x : solution) {
if(scanf("%d", &x) != 1 || x < 1 || x > N || chosen.count(x))
result("Invalid input!");
chosen.insert(x);
}
solve(N);
result("No answer!");
}
*/