#include <bits/stdc++.h>
#include "prize.h"
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define vv vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1;
//~ #ifdef LOCAL
//~ vector<int> ask(int i){ return vector<int>(2, 0); }
//~ #endif
int SUM; // bound na checka, czy to jest gosc z lepszej, czy nie
int f(int l, int r, int resl, int resr){
int midl = (l+r)/2, midr = (l+r)/2;
int result = 0;
vv<int> tmp = ask(midl), tmp2 = tmp; int sum = tmp[0]+tmp[1];
while(sum != SUM && l < midl-1){
if(!sum) return midl;
--midl;
tmp = ask(midl); sum = tmp[0]+tmp[1];
}
if(sum == SUM && resl != tmp[0]) result = max(result, f(l, midl, resl, tmp[0]));
sum = tmp2[0]+tmp2[1];
while(sum != SUM && midr+1 < r){
if(!sum) return midr;
++midr;
tmp = ask(midr); sum = tmp[0]+tmp[1];
}
if(sum == SUM && resr != tmp[0]) result = max(result, f(midr, r, tmp[0], resr));
return result;
}
int find_best(int n){
if(n <= 5000){
vv<int> tmp; int result = 0;
for(int i = 0; i < n; ++i){
tmp = ask(i);
if(!(tmp[0]+tmp[1])){ result = i; break; }
} return result;
}
int sq = int(sqrt(n));
for(int i = 0; i < sq; ++i){
vv<int> tmp = ask(i); int sum = tmp[0]+tmp[1];
SUM = max(SUM, sum);
if(!sum) return i;
}
int l = 0, r = n-1, resl = 0, resr = 0;
vv<int> tmp;
for(int i = 0; i < n; ++i){
tmp = ask(i); int sum = tmp[0]+tmp[1];
if(sum == SUM){ l = i, resl = tmp[0]; break; }
else if(!sum) return i;
}
for(int i = n-1; ~i; --i){
tmp = ask(i); int sum = tmp[0]+tmp[1];
if(sum == SUM){ r = i, resr = tmp[0]; break; }
else if(!sum) return i;
}
return f(l, r, resl, resr);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
432 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Incorrect |
2 ms |
432 KB |
answer is not correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
440 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Incorrect |
2 ms |
432 KB |
answer is not correct |
11 |
Halted |
0 ms |
0 KB |
- |