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<algorithm>
#include<vector>
using namespace std;
#define pii pair<int,int>
vector<int>w, TP;
int Len[1010];
vector<int> SortDisks(int n) {
int i;
for (i = 0; i < n; i++) {
w.push_back(i);
Len[i] = -1;
}
int prev = PutDisks(w);
while (1) {
for (i = 0; i < n; i++) {
if (Len[w[i]] != -1)break;
}
int L = i;
if (L == 0)break;
TP = w;
int z = w[L-1];
for (i = L-1; i > 0; i--)w[i] = w[i - 1];
w[0] = z;
int cur = PutDisks(w);
if (cur == prev - 1) {
prev = cur;
continue;
}
else {
Len[w[0]] = cur - n + 1;
w = TP;
vector<pii>V;
for (i = L - 1; i < n; i++) {
V.push_back({ Len[w[i]],w[i] });
}
sort(V.begin(), V.end());
int pv = L - 1;
for (auto &t : V)w[pv++] = t.second;
prev = PutDisks(w);
}
}
vector<int>Ans(n);
for (i = 0; i < n; i++)Ans[i] = Len[i];
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... |