// In the name of Allah
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5 + 7;
int n;
pii A[maxn];
void askx(int i) {
if (A[i].F != -1) return ;
vector<int> res = ask(i);
A[i] = Mp(res[0], res[1]);
return ;
}
int find_best(int n) {
fill(A, A + n, Mp(-1, -1));
if (n <= 5000) {
for (int i = 0; i < n; i++) {
askx(i);
if (A[i].F + A[i].S == 0) return i;
}
return -1;
}
int mx = 0;
for (int i = 0; i < 475; i++) {
askx(i);
if (A[i].F + A[i].S == 0) return i;
mx = max(mx, A[i].F + A[i].S);
}
int i = 0;
while (i < n) {
askx(i);
if (A[i].F + A[i].S == 0) return i;
else if (A[i].F + A[i].S != mx) {
i++;
continue;
}
int M = 1024;
while (i + M < n) {
int j = i + M; askx(j);
if (A[j].F + A[j].S == 0) return j;
if (A[j].F + A[j].S == mx && A[j].F == A[i].F) i = j + 1;
else break;
}
bool flag = 0;
int l = i, r = min(n, i + 1024);
while (r - l > 1) {
int mid = (l + r) / 2;
int j = mid; askx(j);
if (A[j].F + A[j].S == 0) return j;
if (A[j].F + A[j].S == mx && A[j].F == A[i].F) {
l = mid;
if (!flag) break;
}
else r = mid;
flag = 1;
}
i = l + 1;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1880 KB |
Output is correct |
2 |
Correct |
8 ms |
1880 KB |
Output is correct |
3 |
Correct |
8 ms |
1880 KB |
Output is correct |
4 |
Correct |
9 ms |
1880 KB |
Output is correct |
5 |
Correct |
8 ms |
1880 KB |
Output is correct |
6 |
Correct |
1 ms |
1880 KB |
Output is correct |
7 |
Correct |
8 ms |
1980 KB |
Output is correct |
8 |
Correct |
8 ms |
1880 KB |
Output is correct |
9 |
Correct |
8 ms |
1880 KB |
Output is correct |
10 |
Incorrect |
12 ms |
1880 KB |
Integer -1 violates the range [0, 199999] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1876 KB |
Output is correct |
2 |
Correct |
9 ms |
1880 KB |
Output is correct |
3 |
Correct |
6 ms |
1880 KB |
Output is correct |
4 |
Correct |
9 ms |
1880 KB |
Output is correct |
5 |
Correct |
8 ms |
1880 KB |
Output is correct |
6 |
Correct |
1 ms |
1880 KB |
Output is correct |
7 |
Correct |
11 ms |
1980 KB |
Output is correct |
8 |
Correct |
6 ms |
1880 KB |
Output is correct |
9 |
Correct |
7 ms |
1880 KB |
Output is correct |
10 |
Incorrect |
13 ms |
1880 KB |
Integer -1 violates the range [0, 199999] |
11 |
Halted |
0 ms |
0 KB |
- |