#include <bits/stdc++.h>
#include "grid.h"
using namespace std;
bool used[1001];
bool usedIdx[1000];
int myQuery(vector<int>& v1, vector<int>& v2,int k) {
vector<int> v;
for (int i = (int)v1.size() - k; i < (int)v1.size(); i++)
v.push_back(v1[i]);
for (int i = 0; i < (int)v1.size() - k; i++)
v.push_back(v1[i]);
for (int i : v2)
v.push_back(i);
return PutDisks(v);
}
std::vector<int> SortDisks(int N) {
vector<int> ret(N);
vector<int> revret(N+1);
fill(revret.begin(), revret.end(), -1);
for (int i = 1; i < N; i++) {
vector<int> v, v2;
for (int j = 0; j < N; j++) {
if (!usedIdx[j])
v.push_back(j);
}
for (int j = 1; j <= N; j++) {
if (revret[j] != -1)
v2.push_back(revret[j]);
}
int cur = myQuery(v, v2, 0);
int l = 1, r = (int)v.size() - 1, x = 0, y = cur;
while (l <= r) {
int m = (l + r) >> 1;
int tmp = myQuery(v, v2, m);
if (tmp > cur) {
x = m;
y = tmp;
r = m - 1;
}
else
l = m + 1;
}
x = v[((int)v.size() - x) % (int)v.size()];
y -= N - 1;
ret[x] = y;
revret[y] = x;
used[y] = true;
usedIdx[x] = true;
}
int x, y;
for (int i = 0; i < N; i++) {
if (!usedIdx[i])
x = i;
}
for (int i = 1; i <= N; i++) {
if (!used[i])
y = i;
}
ret[x] = y;
return ret;
}
Compilation message
grid.cpp: In function 'std::vector<int> SortDisks(int)':
grid.cpp:62:7: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
62 | ret[x] = y;
| ^
grid.cpp:62:9: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
62 | ret[x] = y;
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
2 ms |
312 KB |
Output is correct |
10 |
Correct |
2 ms |
304 KB |
Output is correct |
11 |
Correct |
3 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
324 KB |
Output is correct |
15 |
Correct |
2 ms |
296 KB |
Output is correct |
16 |
Correct |
2 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
2 ms |
312 KB |
Output is correct |
10 |
Correct |
2 ms |
304 KB |
Output is correct |
11 |
Correct |
3 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
324 KB |
Output is correct |
15 |
Correct |
2 ms |
296 KB |
Output is correct |
16 |
Correct |
2 ms |
324 KB |
Output is correct |
17 |
Incorrect |
3 ms |
308 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |