#include "grid.h"
#include <random>
#include <algorithm>
using namespace std;
int n;
vector<int> ans;
vector<int> idx;
int get_max_disk(int x) {
vector<int> v;
std::random_device rd;
std::mt19937 g(rd());
vector<bool> vis(n, true);
for(int i=0;i<n;i++){
if (!ans[i]){
v.push_back(i);
} else {
vis[i] = false;
}
}
int p = x;
int cnt = 0;
while(p){
cnt++;
p>>=1;
}
for(int i=0;i<cnt;i++){
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 = PutDisks(t);
r -= (n-x);
r -= x - 1;
for(int j=0;j<x-r;j++){
vis[v[j]] = false;
}
}
for(int i=0;i<n;i++){
if (vis[i]){
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 = PutDisks(v);
if (r - (n-x) == 2*x-1) {
return i;
}
}
}
return -1;
}
std::vector<int> SortDisks(int N) {
n = N;
ans.resize(n);
idx.resize(n+1);
for(int i=n;i>=1;i--){
int x = get_max_disk(i);
ans[x] = i;
idx[i] = x;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
7 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
7 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
384 KB |
Output is correct |
9 |
Incorrect |
11 ms |
384 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Incorrect |
11 ms |
384 KB |
Output isn't correct |
5 |
Correct |
7 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
380 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Halted |
0 ms |
0 KB |
- |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |