#include "grid.h"
#include <vector>
#include <stdio.h>
using namespace std;
int N, sm[1010], rcn, rot[1010], rvd[1010], chk[1010]; // rvd[i]: disk number of size i
int Put(){
vector<int> v;
for(int i=1; i<=N; i++) v.push_back(sm[i]-1);
return PutDisks(v)-N;
}
void fill(){
for(int i=0; i<rcn; i++) sm[i+1]=rot[i];
for(int i=rcn, j=1; j<=N; j++){
if(chk[j]) sm[++i]=rvd[j];
}
}
std::vector<int> SortDisks(int N_) {
rcn = N = N_;
for(int i=0; i<N; i++) rot[i]=i+1;
fill();
int ini=Put(), nxt;
while(ini && rcn>1){
int tmp=rot[rcn-1];
for(int i=rcn-1; i>=0; i--) rot[i+1]=rot[i];
rot[0]=tmp;
fill(); nxt=Put();
if(nxt >= ini){
rcn--;
rvd[1+nxt]=rot[0], chk[1+nxt]=1;
for(int i=0; i<rcn; i++) rot[i]=rot[i+1];
}
else ini=nxt;
}
for(int i=1, j=0; i<=N; i++){
if(chk[i]) sm[rvd[i]]=i;
else sm[rot[j++]]=i;
}
std::vector<int> dap;
for(int i=1; i<=N; i++) dap.push_back(sm[i]);
return dap;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
244 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
248 KB |
Output is correct |
12 |
Correct |
3 ms |
296 KB |
Output is correct |
13 |
Correct |
2 ms |
248 KB |
Output is correct |
14 |
Correct |
3 ms |
248 KB |
Output is correct |
15 |
Correct |
3 ms |
248 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
244 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
248 KB |
Output is correct |
12 |
Correct |
3 ms |
296 KB |
Output is correct |
13 |
Correct |
2 ms |
248 KB |
Output is correct |
14 |
Correct |
3 ms |
248 KB |
Output is correct |
15 |
Correct |
3 ms |
248 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
248 KB |
Output is correct |
18 |
Correct |
13 ms |
416 KB |
Output is correct |
19 |
Correct |
17 ms |
248 KB |
Output is correct |
20 |
Correct |
19 ms |
412 KB |
Output is correct |
21 |
Correct |
2 ms |
248 KB |
Output is correct |
22 |
Correct |
20 ms |
376 KB |
Output is correct |
23 |
Correct |
20 ms |
248 KB |
Output is correct |
24 |
Correct |
20 ms |
376 KB |
Output is correct |
25 |
Correct |
19 ms |
376 KB |
Output is correct |
26 |
Correct |
20 ms |
376 KB |
Output is correct |