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 "grid.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
vector<int> SortDisks(int N) {
vector<int> v, ans;
ans.resize(N);
for(int i = 0; i < N; i++) v.push_back(i);
int left = N;
int sum = 0;
int X = PutDisks(v);
while(left) {
int t = v[left - 1];
for(int i = left - 1; i > 0; i--) v[i] = v[i - 1];
v[0] = t;
int Y = PutDisks(v);
if(Y != X - 1) {
t = v[0];
ans[t] = Y - N + 1;
sum += ans[t];
int lb = lower_bound(v.begin() + left, v.end(), t, [&](const int a, const int b) { return ans[a] < ans[b]; } ) - v.begin();
for(int i = 0; i < lb - 1; i++) v[i] = v[i + 1];
v[lb - 1] = t;
left--;
}
else X = Y;
}
//ans[v[0]] = N * (N + 1) / 2 - sum;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |