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 = 1100;
int N;
vector <int> cv;
vector <int> nv;
int ans[MAXN];
void cyc (int M, int K)
{
nv.clear();
for (int i = 0; i < M; i++)
nv.push_back(cv[(i+K)%M]);
for (int i = M; i < N; i++)
nv.push_back(cv[i]);
}
vector<int> SortDisks(int __N) {
N = __N;
for (int i = 0; i < N; i++)
cv.push_back(i);
for (int i = N; i >= 1; i--)
{
int cval = PutDisks (cv);
for (int j = 7; j >= 0; j--)
{
if ((1 << j) >= i) continue;
cyc (i, (1 << j));
int nval = PutDisks (nv);
if (nval == cval + (1 << j))
{
cv = nv;
cval = nval;
}
}
ans[cv[0]] = cval - N;
swap (cv[0], cv[i-1]);
for (int j = i - 1; j < N - 1; j++)
{
if (ans[cv[j]] > ans[cv[j+1]])
swap (cv[j], cv[j+1]);
else
break;
}
}
vector <int> res;
for (int i = 0; i < N; i++)
res.push_back(ans[i] + 1);
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |