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 "art.h"
#include <bits/stdc++.h>
using namespace std;
void solve(int N) {
vector<int> order(N);
iota(order.begin(), order.end(), 1);
int K = sqrt(N);
for (int num = 1; num <= N; num++) {
int idx = find(order.begin(), order.end(), num) - order.begin();
order.erase(order.begin() + idx);
order.insert(order.begin(), num);
int last = publish(order);
for (int i = 1; i < N; i++) {
swap(order[i - 1], order[i]);
if (i % K == 0 || true) {
int cur = publish(order);
if (cur >= last) {
int mn = 1e9;
int midx = -1;
for (int j = i; j > max(0, i - K); j--) {
swap(order[j - 1], order[j]);
int ncur = publish(order);
if (ncur < mn) {
mn = ncur;
midx = j;
}
}
for (int j = max(0, i - K) + 1; j < midx; j++) {
swap(order[j - 1], order[j]);
}
break;
}
last = cur;
}
}
}
answer(order);
}
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... |