#include "grid.h"
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define SZ(x) (int)x.size()
vector<int> SortDisks(int n) {
vector<int> rem; // remaining child indices
vector<int> ans; // length for i-th child
int rev[n]; // inverse map of ans (child with length i-1)
for(int i=0;i<n;i++){
rem.pb(i);
ans.pb(-1);
rev[i]=-1;
}
int prv=PutDisks(rem);
while(!rem.empty()){
vector<int> test;
int tmp=rem[SZ(rem)-1];
for(int i=0;i<SZ(rem);i++){
swap(tmp,rem[i]); // rightshift everything
}
int idx=0;
for(int i=0;i<n;i++){
if(rev[i]==-1)test.pb(rem[idx++]); // there is no known child with this length
else test.pb(rev[i]); // there is a known child with this length -> we want to un-bottleneck
}
int cur=PutDisks(test);
if(cur==prv-1){ // moving the top unknown to the bottom didnt change anything
prv=cur;
}else{ // the bottom ("length" (index in test) whose child is unknown) child can be determined
for(int b=0;b<n;b++){
if(rev[b]==-1){
// test[b]=rem[0] is the child's index
ans[rem[0]]=cur-n+b+1;
rev[ans[rem[0]]-1]=rem[0];
for(int i=0;i<SZ(rem)-1;i++){
rem[i]=rem[i+1];
}
rem.pop_back();
break;
}
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |