# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
688557 | Alcabel | Art Collections (BOI22_art) | C++17 | 1537 ms | 868 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 <bits/stdc++.h>
using namespace std;
void solve(int n) {
vector<int> p(n);
iota(p.begin(), p.end(), 1);
vector<int> sorted = {p[0]}, posOf(n);
int was = publish(p);
for (int i = 1; i < n; ++i) {
swap(p[0], p[i]);
int cur = publish(p);
swap(p[0], p[i]);
sorted.emplace_back(p[i]);
posOf[p[i] - 1] = i;
bool isNewGreater = false;
for (int j = i; j >= 0; --j) {
// j is current pos of p[i]
// - posOf[p[0] - 1] - (i - posOf[p[i] - 1]) + isNewGreater
// + (i - posOf[p[0] - 1]) + posOf[p[i] - 1] - (1 - isNewGreater)
if (was - posOf[p[0] - 1] - (i - posOf[p[i] - 1]) + isNewGreater + (i - posOf[p[0] - 1]) + posOf[p[i] - 1] - (1 - isNewGreater) == cur) {
break;
}
assert(j > 0);
if (sorted[j - 1] == p[0]) {
isNewGreater = true;
}
--posOf[p[i] - 1];
++posOf[sorted[j - 1] - 1];
swap(sorted[j - 1], sorted[j]);
}
}
answer(sorted);
}
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... |