#include "grid.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
vector<int> SortDisks(int N) {
vector<int> v, ans;
ans.resize(N);
for(int i = 0; i < N; i++) v.push_back(i);
int left = N;
int sum = 0;
int X = PutDisks(v);
while(left > 1) {
int t = v[left - 1];
for(int i = left - 1; i > 0; i--) v[i] = v[i - 1];
v[0] = t;
int Y = PutDisks(v);
if(Y != X - 1) {
t = v[0];
ans[t] = Y - N + 1;
sum += ans[t];
int lb = lower_bound(v.begin() + left, v.end(), t, [&](const int a, const int b) { return ans[a] < ans[b]; } ) - v.begin();
for(int i = 0; i < lb - 1; i++) v[i] = v[i + 1];
v[lb - 1] = t;
left--;
}
else X = Y;
}
ans[v[0]] = N * (N + 1) / 2 - sum;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |