#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int find_best(int n) {
int i = 0, at = 0, lolipop = 0;
vector<pii> resp(n, mk(-1,-1));
for(int i = 0; i < min(450,n); i++) {
vector<int> aux = ask(i);
resp[i] = {aux[0],aux[1]};
lolipop = max(lolipop, aux[0] + aux[1]);
}
while(i < n) {
// achar primeiro cara mais valioso doq um pirulito de indice maior que i
int l = i, r = n-1;
while(l <= r) {
int mid = (l+r)/2;
vector<int> aux;
if(resp[mid] == mk(-1,-1)) aux = ask(mid), resp[mid] = {aux[0],aux[1]};
else aux = {resp[mid].fr};
if(aux[0] > at) r = mid-1;
else l = mid+1;
}
while(r+1 < n) {
vector<int> aux;
if(resp[r+1] == mk(-1,-1)) aux = ask(r+1), resp[r+1] = {aux[0], aux[1]};
else aux = {resp[r+1].fr, resp[r+1].sc};
if(resp[r+1].fr + resp[r+1].sc == lolipop) break;
r++;
}
i = r;
while(i >= 0) {
vector<int> aux;
if(resp[i] == mk(-1,-1)) aux = ask(i), resp[i] = {aux[0], aux[1]};
else aux = {resp[i].fr, resp[i].sc};
if(aux[0] + aux[1] == 0) return i;
if(aux[0] + aux[1] == resp[r+1].fr + resp[r+1].sc or aux[0] == 0) break;
i--;
}
i = r+1;
at = resp[r+1].fr;
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:18:31: warning: control reaches end of non-void function [-Wreturn-type]
18 | vector<pii> resp(n, mk(-1,-1));
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
3 ms |
1880 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
3 ms |
1880 KB |
Output is correct |
5 |
Correct |
3 ms |
1880 KB |
Output is correct |
6 |
Correct |
3 ms |
1880 KB |
Output is correct |
7 |
Correct |
3 ms |
1880 KB |
Output is correct |
8 |
Correct |
3 ms |
1880 KB |
Output is correct |
9 |
Correct |
2 ms |
1880 KB |
Output is correct |
10 |
Correct |
3 ms |
1880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
3 ms |
1960 KB |
Output is correct |
3 |
Correct |
3 ms |
1880 KB |
Output is correct |
4 |
Correct |
2 ms |
1964 KB |
Output is correct |
5 |
Correct |
3 ms |
1880 KB |
Output is correct |
6 |
Correct |
3 ms |
1880 KB |
Output is correct |
7 |
Correct |
3 ms |
1880 KB |
Output is correct |
8 |
Correct |
3 ms |
1880 KB |
Output is correct |
9 |
Correct |
3 ms |
1880 KB |
Output is correct |
10 |
Correct |
3 ms |
1880 KB |
Output is correct |
11 |
Correct |
5 ms |
2136 KB |
Output is correct |
12 |
Correct |
3 ms |
1880 KB |
Output is correct |
13 |
Correct |
5 ms |
1880 KB |
Output is correct |
14 |
Incorrect |
52 ms |
600 KB |
Incorrect |
15 |
Halted |
0 ms |
0 KB |
- |