#include "prize.h"
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#else
#define debug(...)
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
// #define int long long
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FOS(i, r, l) for (int i = (r); i >= (l); --i)
#define FRN(i, n) for (int i = 0; i < (n); ++i)
#define FSN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : (x))
#define WHILE while
template<typename T> T gcd(T a, T b) { T d2 = (a | b) & -(a | b); a /= d2; b /= d2; WHILE(b) { a = a % b; swap(a, b); } return a * d2; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
void _assert(bool statement) { if (statement) return; cerr << "\n>> Assertion failed!\n"; exit(0); }
void _assert(bool statement, const str &message) { if (statement) return; cerr << "\n>> Assertion failed: " << message << '\n'; exit(0); }
void _error(const str &message) { cerr << "\n>> Error: " << message << '\n'; exit(0); }
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
----------------------------------------------------------------
END OF TEMPLATE
----------------------------------------------------------------
Tran The Bao - ghostwriter
Training for VOI23 gold medal
----------------------------------------------------------------
GOAT
----------------------------------------------------------------
*/
int find_best(int n) {
int pos = -1;
vi ansp;
FRN(i, min(n, 474)) {
if (pos == -1) {
pos = i;
ansp = ask(i);
if (ansp[0] + ansp[1] == 0) return i;
}
else {
vi tmp = ask(i);
if (tmp[0] + tmp[1] == 0) return i;
if (ansp[0] + ansp[1] < tmp[0] + tmp[1]) {
pos = i;
ansp = tmp;
}
}
}
int cnt = 0, pre = pos;
WHILE(1) {
int l = pre + 1, r = n - 1, ans = -1;
WHILE(l <= r) {
int mid = l + (r - l) / 2;
vi tmp = ask(mid);
if (tmp[0] + tmp[1] == 0) return mid;
if (tmp[0] + tmp[1] < ansp[0] + ansp[1]) {
ans = mid;
r = mid - 1;
}
else if (tmp[0] - ansp[0] > cnt) r = mid - 1;
else l = mid + 1;
}
++cnt;
pre = ans;
}
return 0;
}
/*
8
3 2 3 1 3 3 2 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
296 KB |
Output is correct |
3 |
Correct |
6 ms |
296 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
292 KB |
Output is correct |
7 |
Correct |
2 ms |
296 KB |
Output is correct |
8 |
Correct |
2 ms |
300 KB |
Output is correct |
9 |
Correct |
3 ms |
292 KB |
Output is correct |
10 |
Correct |
5 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
296 KB |
Output is correct |
3 |
Correct |
3 ms |
292 KB |
Output is correct |
4 |
Correct |
3 ms |
220 KB |
Output is correct |
5 |
Correct |
2 ms |
292 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
4 ms |
208 KB |
Output is correct |
8 |
Correct |
3 ms |
208 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
296 KB |
Output is correct |
12 |
Correct |
5 ms |
296 KB |
Output is correct |
13 |
Correct |
9 ms |
300 KB |
Output is correct |
14 |
Correct |
7 ms |
208 KB |
Output is correct |
15 |
Correct |
13 ms |
208 KB |
Output is correct |
16 |
Partially correct |
60 ms |
292 KB |
Partially correct - number of queries: 7022 |
17 |
Correct |
4 ms |
296 KB |
Output is correct |
18 |
Partially correct |
30 ms |
328 KB |
Partially correct - number of queries: 8138 |
19 |
Correct |
4 ms |
208 KB |
Output is correct |
20 |
Correct |
20 ms |
208 KB |
Output is correct |
21 |
Correct |
34 ms |
208 KB |
Output is correct |
22 |
Correct |
5 ms |
280 KB |
Output is correct |
23 |
Correct |
3 ms |
276 KB |
Output is correct |
24 |
Correct |
4 ms |
208 KB |
Output is correct |
25 |
Correct |
36 ms |
208 KB |
Output is correct |
26 |
Correct |
45 ms |
208 KB |
Output is correct |
27 |
Correct |
5 ms |
300 KB |
Output is correct |
28 |
Partially correct |
58 ms |
208 KB |
Partially correct - number of queries: 7796 |
29 |
Partially correct |
52 ms |
208 KB |
Partially correct - number of queries: 6018 |
30 |
Partially correct |
84 ms |
208 KB |
Partially correct - number of queries: 8074 |
31 |
Correct |
6 ms |
208 KB |
Output is correct |
32 |
Correct |
6 ms |
276 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
12 ms |
208 KB |
Output is correct |
35 |
Correct |
5 ms |
292 KB |
Output is correct |
36 |
Correct |
18 ms |
300 KB |
Output is correct |
37 |
Correct |
4 ms |
208 KB |
Output is correct |
38 |
Correct |
3 ms |
292 KB |
Output is correct |
39 |
Correct |
28 ms |
276 KB |
Output is correct |
40 |
Partially correct |
57 ms |
208 KB |
Partially correct - number of queries: 6963 |
41 |
Partially correct |
37 ms |
292 KB |
Partially correct - number of queries: 5083 |
42 |
Partially correct |
41 ms |
208 KB |
Partially correct - number of queries: 5083 |
43 |
Correct |
36 ms |
296 KB |
Output is correct |
44 |
Correct |
31 ms |
208 KB |
Output is correct |
45 |
Correct |
32 ms |
296 KB |
Output is correct |
46 |
Correct |
3 ms |
272 KB |
Output is correct |
47 |
Correct |
32 ms |
208 KB |
Output is correct |
48 |
Partially correct |
56 ms |
296 KB |
Partially correct - number of queries: 6162 |
49 |
Correct |
6 ms |
296 KB |
Output is correct |
50 |
Partially correct |
68 ms |
208 KB |
Partially correct - number of queries: 8127 |
51 |
Correct |
30 ms |
208 KB |
Output is correct |
52 |
Correct |
2 ms |
296 KB |
Output is correct |
53 |
Correct |
3 ms |
296 KB |
Output is correct |
54 |
Correct |
34 ms |
300 KB |
Output is correct |
55 |
Correct |
5 ms |
208 KB |
Output is correct |
56 |
Partially correct |
73 ms |
296 KB |
Partially correct - number of queries: 8135 |
57 |
Partially correct |
47 ms |
208 KB |
Partially correct - number of queries: 6085 |
58 |
Partially correct |
62 ms |
300 KB |
Partially correct - number of queries: 6180 |
59 |
Partially correct |
47 ms |
208 KB |
Partially correct - number of queries: 5083 |
60 |
Correct |
40 ms |
208 KB |
Output is correct |
61 |
Correct |
5 ms |
292 KB |
Output is correct |
62 |
Correct |
5 ms |
292 KB |
Output is correct |
63 |
Correct |
4 ms |
296 KB |
Output is correct |
64 |
Correct |
6 ms |
216 KB |
Output is correct |
65 |
Correct |
4 ms |
208 KB |
Output is correct |
66 |
Correct |
14 ms |
296 KB |
Output is correct |
67 |
Correct |
4 ms |
296 KB |
Output is correct |
68 |
Correct |
4 ms |
208 KB |
Output is correct |
69 |
Correct |
29 ms |
208 KB |
Output is correct |
70 |
Correct |
4 ms |
208 KB |
Output is correct |
71 |
Partially correct |
60 ms |
208 KB |
Partially correct - number of queries: 8274 |
72 |
Correct |
9 ms |
208 KB |
Output is correct |
73 |
Partially correct |
62 ms |
208 KB |
Partially correct - number of queries: 8169 |
74 |
Partially correct |
73 ms |
208 KB |
Partially correct - number of queries: 8224 |
75 |
Correct |
6 ms |
208 KB |
Output is correct |
76 |
Partially correct |
47 ms |
208 KB |
Partially correct - number of queries: 7102 |
77 |
Partially correct |
59 ms |
208 KB |
Partially correct - number of queries: 8156 |
78 |
Correct |
9 ms |
208 KB |
Output is correct |
79 |
Correct |
35 ms |
208 KB |
Output is correct |
80 |
Partially correct |
57 ms |
208 KB |
Partially correct - number of queries: 8161 |
81 |
Partially correct |
74 ms |
292 KB |
Partially correct - number of queries: 8138 |
82 |
Partially correct |
66 ms |
208 KB |
Partially correct - number of queries: 8097 |
83 |
Correct |
4 ms |
208 KB |
Output is correct |
84 |
Partially correct |
26 ms |
336 KB |
Partially correct - number of queries: 6748 |
85 |
Partially correct |
67 ms |
208 KB |
Partially correct - number of queries: 8170 |
86 |
Correct |
5 ms |
208 KB |
Output is correct |
87 |
Correct |
5 ms |
208 KB |
Output is correct |
88 |
Correct |
4 ms |
208 KB |
Output is correct |
89 |
Correct |
4 ms |
208 KB |
Output is correct |
90 |
Correct |
6 ms |
208 KB |
Output is correct |
91 |
Correct |
5 ms |
296 KB |
Output is correct |
92 |
Correct |
5 ms |
208 KB |
Output is correct |
93 |
Correct |
9 ms |
208 KB |
Output is correct |
94 |
Correct |
6 ms |
208 KB |
Output is correct |
95 |
Correct |
8 ms |
208 KB |
Output is correct |
96 |
Correct |
7 ms |
208 KB |
Output is correct |
97 |
Correct |
5 ms |
208 KB |
Output is correct |