This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |