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;
int N, original;
vector<int> order;
bool smaller(int a, int b){
swap(order[a-1], order[b-1]);
int nw = publish(order);
swap(order[a-1], order[b-1]);
if(a < b){
if(nw < original) {
return false; //B is smaller.
} else {
return true; //A is smaller.
}
} else {
if(nw < original) {
return true; //A is smaller
} else {
return false; //B is smaller.
}
}
}
vector<int> merge_sort(int l, int r){
if(l == r){
if(l > N) return {};
else return {l};
}
int m = (l + r) / 2;
vector<int> left = merge_sort(l, m);
vector<int> right = merge_sort(m + 1, r);
vector<int> nw;
int i = 0;
int j = 0;
while(i < (int)left.size() || j < (int)right.size()){
if(i >= (int)left.size()){
nw.push_back(right[j]); j++;
}else if(j >= (int)right.size()){
nw.push_back(left[i]); i++;
}else{
if(smaller(left[i], right[j])){
nw.push_back(left[i]); i++;
}else{
nw.push_back(right[j]); j++;
}
}
}
return nw;
}
void solve(int n) {
N = n;
order.resize(N);
for(int i = 0; i < N; i++) order[i] = i + 1;
original = publish(order);
int pw = 1;
while(pw < N) pw *= 2;
vector<int> ans = merge_sort(1, pw);
answer(ans);
}
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... |