#include <bits/stdc++.h>
#include "grid.h"
using namespace std;
int ask(vector <int> &X, vector <int> &Y)
{
vector <int> Z = X;
int i;
for(i=0; i<Y.size(); i++){
Z.push_back(Y[i]);
}
return PutDisks(Z);
}
vector <int> SortDisks(int n)
{
vector <int> ans(n, 0), chk(n, 0);
vector <int> X, Y;
int i, j, t;
int s, e, m, v1, v2;
for(i=0; i<n; i++){
X.clear(); Y.clear();
for(j=0; j<n; j++){
if(chk[j]) Y.push_back(j);
}
for(j=0; j<n; j++){
if(!chk[j]) X.push_back(j);
}
sort(Y.begin(), Y.end(), [&](int &a, int &b){
return ans[a] < ans[b];
});
v1 = ask(X, Y);
for(s=1, e=n-i-1; s<=e; ){
m = s + e >> 1;
rotate(X.begin(), X.begin() + m, X.end());
v2 = ask(X, Y);
if(v1 + m == v2) s = m + 1;
else e = m - 1;
rotate(X.begin(), X.begin() + n - i - m, X.end());
}
chk[X[e]] = 1; ans[X[e]] = v1 - (n - e) + 1;
}
return ans;
}
Compilation message
grid.cpp: In function 'int ask(std::vector<int>&, std::vector<int>&)':
grid.cpp:13:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<Y.size(); i++){
~^~~~~~~~~
grid.cpp: In function 'std::vector<int> SortDisks(int)':
grid.cpp:45:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
m = s + e >> 1;
~~^~~
grid.cpp:24:12: warning: unused variable 't' [-Wunused-variable]
int i, j, t;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
304 KB |
Output is correct |
4 |
Correct |
6 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
128 KB |
Output is correct |
6 |
Correct |
6 ms |
256 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
304 KB |
Output is correct |
4 |
Correct |
6 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
128 KB |
Output is correct |
6 |
Correct |
6 ms |
256 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
11 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
256 KB |
Output is correct |
12 |
Correct |
12 ms |
384 KB |
Output is correct |
13 |
Correct |
10 ms |
256 KB |
Output is correct |
14 |
Correct |
11 ms |
384 KB |
Output is correct |
15 |
Correct |
10 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
304 KB |
Output is correct |
4 |
Correct |
6 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
128 KB |
Output is correct |
6 |
Correct |
6 ms |
256 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
11 ms |
384 KB |
Output is correct |
11 |
Correct |
11 ms |
256 KB |
Output is correct |
12 |
Correct |
12 ms |
384 KB |
Output is correct |
13 |
Correct |
10 ms |
256 KB |
Output is correct |
14 |
Correct |
11 ms |
384 KB |
Output is correct |
15 |
Correct |
10 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
256 KB |
Output is correct |
17 |
Incorrect |
13 ms |
256 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |