#include "grid.h"
#include<algorithm>
#include<vector>
using namespace std;
#define pii pair<int,int>
vector<int>w, TP;
int Len[1010];
vector<int> SortDisks(int n) {
int i;
for (i = 0; i < n; i++) {
w.push_back(i);
Len[i] = -1;
}
int prev = PutDisks(w);
while (1) {
for (i = 0; i < n; i++) {
if (Len[w[i]] != -1)break;
}
int L = i;
if (L == 0)break;
TP = w;
int z = w[L-1];
for (i = L-1; i > 0; i--)w[i] = w[i - 1];
w[0] = z;
int cur = PutDisks(w);
if (cur < prev) {
prev = cur;
continue;
}
else {
Len[w[0]] = cur - n + 1;
w = TP;
vector<pii>V;
for (i = L - 1; i < n; i++) {
V.push_back({ Len[w[i]],w[i] });
}
sort(V.begin(), V.end());
int pv = L - 1;
for (auto &t : V)w[pv++] = t.second;
}
}
vector<int>Ans(n);
for (i = 0; i < n; i++)Ans[i] = Len[i];
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 |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
252 KB |
Output is correct |
12 |
Correct |
3 ms |
248 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
380 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
252 KB |
Output is correct |
12 |
Correct |
3 ms |
248 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
380 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
248 KB |
Output is correct |
18 |
Correct |
16 ms |
376 KB |
Output is correct |
19 |
Correct |
20 ms |
376 KB |
Output is correct |
20 |
Correct |
25 ms |
380 KB |
Output is correct |
21 |
Correct |
19 ms |
376 KB |
Output is correct |
22 |
Correct |
25 ms |
376 KB |
Output is correct |
23 |
Correct |
25 ms |
376 KB |
Output is correct |
24 |
Correct |
25 ms |
376 KB |
Output is correct |
25 |
Correct |
25 ms |
376 KB |
Output is correct |
26 |
Correct |
25 ms |
248 KB |
Output is correct |