#include "prize.h"
#include "bits/stdc++.h"
using namespace std;
int ddd = 1;
int fen[200005][10];
int corr[10];
int n;
unordered_map<int, int> aaa;
void add(int id, int x, int k) {
id++;
while(id <= n) {
fen[id][k] += x;
id += (id & (-id));
}
}
int sum(int id, int k) {
int ans = 0;
id++;
while(id > 0) {
ans += fen[id][k];
id -= (id & (-id));
}
return ans;
}
int getbefore(int id, int k) {
int t = 0;
for(int i = 1; i < ddd; i++) {
if(corr[i] < k) t += sum(id, i);
}
return t;
}
void add_val(int a, int k) {
if(aaa[k] == 0) {corr[ddd] = k; aaa[k] = ddd++;}
add(a, 1, aaa[k]);
}
int find_best(int N) {
n = N;
int now = 0;
int dx = 0;
int sign = 1;
// int t = 100;
while(1) {
cerr << now << '\n';
vector<int> res = ask(now);
if(res[0] + res[1] == 0) return now;
if(res[0] == getbefore(now, res[0] + res[1])) {
sign = 1;
dx *= 2;
if(dx == 0) dx++;
}
else {
sign = -1;
dx /= 2;
if(dx == 0) dx++;
}
add_val(now, res[0] + res[1]);
if(sign == 1) dx = min(dx, n - 1 - now);
else dx = min(dx, now);
now += dx * sign;
}
// for(int i = 0; i < n; i++) {
// vector<int> res = ask(i);
// if(res[0] + res[1] == 0)
// return i;
// }
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
400 KB |
Output is correct |
3 |
Correct |
1 ms |
280 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
292 KB |
Output is correct |
8 |
Correct |
1 ms |
284 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
280 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
288 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
268 KB |
Output is correct |
8 |
Correct |
1 ms |
288 KB |
Output is correct |
9 |
Correct |
1 ms |
284 KB |
Output is correct |
10 |
Correct |
1 ms |
456 KB |
Output is correct |
11 |
Correct |
4 ms |
1724 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
20 ms |
3608 KB |
Output is correct |
14 |
Correct |
4 ms |
432 KB |
Output is correct |
15 |
Correct |
9 ms |
1372 KB |
Output is correct |
16 |
Partially correct |
101 ms |
6720 KB |
Partially correct - number of queries: 7918 |
17 |
Correct |
1 ms |
280 KB |
Output is correct |
18 |
Partially correct |
126 ms |
8032 KB |
Partially correct - number of queries: 9606 |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
36 ms |
1688 KB |
Output is correct |
21 |
Correct |
35 ms |
3104 KB |
Output is correct |
22 |
Correct |
8 ms |
968 KB |
Output is correct |
23 |
Correct |
1 ms |
292 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
44 ms |
4196 KB |
Output is correct |
26 |
Incorrect |
129 ms |
3392 KB |
Incorrect |
27 |
Halted |
0 ms |
0 KB |
- |