# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047183 | sofijavelkovska | Art Collections (BOI22_art) | C++17 | 387 ms | 1296 KiB |
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 "sample_grader.cpp"
#include <bits/stdc++.h>
using namespace std;
vector<int> sorted;
int inv;
bool smaller(int x, int y)
{
swap(sorted[x-1], sorted[y-1]);
int newinv=publish(sorted);
swap(sorted[x-1], sorted[y-1]);
if (x<y && inv<newinv)
return true;
if (x>y && inv>newinv)
return true;
return false;
}
vector<int> mergesort(vector<int> a)
{
int n=a.size();
if (n==1)
return a;
vector<int> left, right;
for (int i=0; i<n/2; i++)
left.push_back(a[i]);
for (int i=n/2; i<n; i++)
right.push_back(a[i]);
a.clear();
left=mergesort(left);
right=mergesort(right);
reverse(left.begin(), left.end());
reverse(right.begin(), right.end());
while (a.size()<n)
{
if (right.empty() || (!left.empty() && smaller(left.back(), right.back())))
{
a.push_back(left.back());
left.pop_back();
}
else
{
a.push_back(right.back());
right.pop_back();
}
}
return a;
}
void solve(int n)
{
vector<int> a(n);
for (int i=0; i<n; i++)
a[i]=i+1;
sorted.resize(n);
for (int i=0; i<n; i++)
sorted[i]=i+1;
inv=publish(a);
answer(mergesort(a));
return;
}
Compilation message (stderr)
# | 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... |