#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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
352 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
352 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
8 ms |
376 KB |
Output is correct |
12 |
Correct |
8 ms |
380 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
14 ms |
380 KB |
Output is correct |
15 |
Correct |
8 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
352 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
8 ms |
376 KB |
Output is correct |
12 |
Correct |
8 ms |
380 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
14 ms |
380 KB |
Output is correct |
15 |
Correct |
8 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
376 KB |
Output is correct |
17 |
Correct |
9 ms |
376 KB |
Output is correct |
18 |
Correct |
18 ms |
376 KB |
Output is correct |
19 |
Correct |
18 ms |
376 KB |
Output is correct |
20 |
Correct |
25 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
22 ms |
416 KB |
Output is correct |
23 |
Correct |
21 ms |
376 KB |
Output is correct |
24 |
Correct |
21 ms |
376 KB |
Output is correct |
25 |
Correct |
23 ms |
376 KB |
Output is correct |
26 |
Correct |
26 ms |
376 KB |
Output is correct |