#include "grid.h"
#include <random>
#include <algorithm>
#include <map>
using namespace std;
int n;
vector<int> ans;
vector<int> idx;
map<vector<int>, int> logs;
vector<vector<bool>> vis;
int count_candi(int x){
int cnt = 0;
for(int i=0;i<n;i++){
if (vis[x][i])cnt++;
}
return cnt;
}
int get_max_disk(int x) {
vector<int> v;
std::random_device rd;
std::mt19937 g(rd());
for(int i=0;i<n;i++){
if (!ans[i]){
v.push_back(i);
}
}
int p = x;
int cnt = 0;
while(p){
cnt++;
p /= 2;
}
for(int i=0;i<cnt;i++){
if (count_candi(x) < x/30)break;
shuffle(v.begin(), v.end(), g);
vector<int> t = v;
for(int j=x+1; j<=n; j++){
t.push_back(idx[j]);
}
int r = logs[t];
if (!r){
r = PutDisks(t);
logs[t] = r;
}
r -= (n-x);
r -= x - 1;
for(int q = x-r; q >= 1; q--){
for(int j=0;j<q;j++){
vis[q+r][v[j]] = false;
}
}
}
for(int i=0;i<n;i++){
if (vis[x][i]){
//printf("#");
vector<int> v;
v.push_back(i);
for(int j=0;j<n;j++){
if (!ans[j] && j != i){
v.push_back(j);
}
}
for(int j=x+1;j<=n;j++){
v.push_back(idx[j]);
}
int r = logs[v];
if(!r){
r = PutDisks(v);
logs[v] = r;
}
if (r - (n-x) == 2*x-1) {
//puts("");
return i;
}
}
}
return -1;
}
std::vector<int> SortDisks(int N) {
n = N;
ans.resize(n);
idx.resize(n+1);
vis.resize(n+1);
for(int i=1;i<=n;i++){
vis[i].resize(n, true);
}
for(int i=n;i>=1;i--){
int x = get_max_disk(i);
ans[x] = i;
idx[i] = x;
for(int j=1;j<i;j++){
vis[j][x] = false;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
7 ms |
384 KB |
Output is correct |
7 |
Correct |
7 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
7 ms |
384 KB |
Output is correct |
7 |
Correct |
7 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
896 KB |
Output is correct |
10 |
Correct |
17 ms |
1920 KB |
Output is correct |
11 |
Correct |
21 ms |
2304 KB |
Output is correct |
12 |
Correct |
21 ms |
2304 KB |
Output is correct |
13 |
Correct |
20 ms |
1920 KB |
Output is correct |
14 |
Correct |
23 ms |
2560 KB |
Output is correct |
15 |
Correct |
18 ms |
1920 KB |
Output is correct |
16 |
Correct |
20 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
7 ms |
384 KB |
Output is correct |
7 |
Correct |
7 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
384 KB |
Output is correct |
9 |
Correct |
11 ms |
896 KB |
Output is correct |
10 |
Correct |
17 ms |
1920 KB |
Output is correct |
11 |
Correct |
21 ms |
2304 KB |
Output is correct |
12 |
Correct |
21 ms |
2304 KB |
Output is correct |
13 |
Correct |
20 ms |
1920 KB |
Output is correct |
14 |
Correct |
23 ms |
2560 KB |
Output is correct |
15 |
Correct |
18 ms |
1920 KB |
Output is correct |
16 |
Correct |
20 ms |
1920 KB |
Output is correct |
17 |
Incorrect |
28 ms |
3456 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |