#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
using ii = pair<int, int>;
int n;
vector<int> V[200007];
ii ans(int i) {
if(V[i].size() == 0)
V[i] = ask(i);
return {V[i][0], V[i][1]};
}
int worst_sum;
int find_in_segment(int a, int b, int ok) {
if(!ok)
return -1;
int mid1 = (a + b) / 2;
while(ans(mid1).X + ans(mid1).Y != worst_sum && mid1 >= a) {
if(ans(mid1).X + ans(mid1).Y == 0)
return mid1;
mid1--;
}
if(mid1 > a) {
int x = find_in_segment(a, mid1 - 1, ans(mid1).X - ans(a - 1).X);
if(x != -1)
return x;
}
if(mid1 < b) {
int x = find_in_segment(mid1 + 1, b, ans(b + 1).X - ans(mid1).X);
if(x != -1)
return x;
}
return -1;
}
int find_best(int n) {
::n = n;
int pocz = 0, kon = n - 1;
while(pocz <= min(474, n)) {
worst_sum = max(worst_sum, ans(pocz).X + ans(pocz).Y);
if(ans(pocz).X + ans(pocz).Y == 0)
return pocz;
pocz++;
}
while(ans(pocz).X + ans(pocz).Y != worst_sum) {
if(ans(pocz).X + ans(pocz).Y == 0)
return pocz;
pocz++;
}
while(ans(kon).X + ans(kon).Y != worst_sum) {
if(ans(kon).X + ans(kon).Y == 0)
return kon;
kon--;
}
pocz++;
kon--;
return find_in_segment(pocz, kon, ans(kon + 1).X - ans(pocz - 1).X);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
5112 KB |
Output is correct |
2 |
Correct |
12 ms |
5012 KB |
Output is correct |
3 |
Correct |
11 ms |
5012 KB |
Output is correct |
4 |
Correct |
11 ms |
5032 KB |
Output is correct |
5 |
Correct |
12 ms |
5024 KB |
Output is correct |
6 |
Correct |
7 ms |
4984 KB |
Output is correct |
7 |
Correct |
10 ms |
5040 KB |
Output is correct |
8 |
Correct |
9 ms |
4984 KB |
Output is correct |
9 |
Correct |
10 ms |
5112 KB |
Output is correct |
10 |
Correct |
13 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4984 KB |
Output is correct |
2 |
Correct |
11 ms |
4984 KB |
Output is correct |
3 |
Correct |
11 ms |
4984 KB |
Output is correct |
4 |
Correct |
10 ms |
4984 KB |
Output is correct |
5 |
Correct |
11 ms |
5012 KB |
Output is correct |
6 |
Correct |
7 ms |
4988 KB |
Output is correct |
7 |
Correct |
11 ms |
5008 KB |
Output is correct |
8 |
Correct |
10 ms |
4984 KB |
Output is correct |
9 |
Correct |
12 ms |
5012 KB |
Output is correct |
10 |
Correct |
13 ms |
4984 KB |
Output is correct |
11 |
Execution timed out |
3087 ms |
5112 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |