# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
111166 | imsifile | On the Grid (FXCUP4_grid) | C++98 | 0 ms | 0 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 "grid.h"
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
int N, rot[2010], sm[1010];
int Put(){
vector<int> v;
for(int i=0; i<N; i++) v.push_back(rot[i]);
return PutDisks(v)-N;
}
void Rotate(int X, int am){ // rot[0 ~ X-1] left am
reverse(rot, rot+am);
reverse(rot+am, rot+X);
reverse(rot, rot+X);
}
void SortDisks(int N_) {
N = N_;
for(int i=0; i<N; i++) rot[i]=i+1;
for(int i=N; i>1; i--){
int pv = Put();
for(int X=i; X>1;){
Rotate(X, X/2);
int nx = Put();
if(pv > nx) Rotate(X, (X+1)/2), X = X/2;
else pv = nx, X = (X+1)/2;
}
sm[rot[0]] = 1+pv;
Rotate(i, 1);
for(int j=i; j<N; j++){
if(sm[rot[j-1]] > sm[rot[j]]) swap(rot[j-1], rot[j]);
}
}
sm[rot[0]] = 1;
for(int i=1; i<=N; i++) Report(sm[i]);
}