#include "prize.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;
#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed
vector<vector<int>> cache;
vector<int> neoask(int i) {
if (cache[i].empty()) return cache[i] = ask(i);
return cache[i];
}
int minDeter = 0;
void solve(int s, int e, vector<bool> &mask) {
if (s > e) return;
auto vs = neoask(s);
if (vs[0] + vs[1] != minDeter) {
mask[s] = true;
solve(s + 1, e, mask);
return;
}
auto ve = neoask(e);
if (ve[0] + ve[1] != minDeter) {
mask[e] = true;
solve(s, e - 1, mask);
return;
}
if (e - s <= 1) return;
if (vs[0] == ve[0]) return;
int m = (s + e) >> 1;
auto vm = neoask(m);
if (vm[0] + vm[1] != minDeter) mask[m] = true;
solve(s, m, mask);
solve(m, e, mask);
}
int find_best(int n) {
if (n <= 5000) {
for (int i = 0; i < n; i++) {
auto v = ask(i);
if (v[0] + v[1] == 0) return i;
}
}
vector<bool> mask(n);
cache.resize(n);
// 473번 해보기
random_device rd;
mt19937 gen(rd());
vector<int> shu;
for (int i = 0; i < n; i++) shu.emplace_back(i);
shuffle(iterall(shu), gen);
for (int j = 0; j < 473; j++) {
int i = shu[j];
cache[i] = ask(i);
minDeter = max(minDeter, cache[i][0] + cache[i][1]);
}
solve(0, n - 1, mask);
for (int i = 0; i < n; i++) {
if (!mask[i]) continue;
auto v = neoask(i);
if (v[0] + v[1] == 0) return i;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
6256 KB |
Output is correct |
2 |
Correct |
18 ms |
6160 KB |
Output is correct |
3 |
Correct |
16 ms |
6256 KB |
Output is correct |
4 |
Correct |
15 ms |
6240 KB |
Output is correct |
5 |
Correct |
16 ms |
6168 KB |
Output is correct |
6 |
Correct |
16 ms |
6240 KB |
Output is correct |
7 |
Correct |
18 ms |
6264 KB |
Output is correct |
8 |
Correct |
18 ms |
6236 KB |
Output is correct |
9 |
Correct |
16 ms |
6256 KB |
Output is correct |
10 |
Correct |
19 ms |
6264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
6256 KB |
Output is correct |
2 |
Correct |
16 ms |
6168 KB |
Output is correct |
3 |
Correct |
15 ms |
6264 KB |
Output is correct |
4 |
Correct |
18 ms |
6236 KB |
Output is correct |
5 |
Correct |
16 ms |
6264 KB |
Output is correct |
6 |
Correct |
15 ms |
6256 KB |
Output is correct |
7 |
Correct |
18 ms |
6264 KB |
Output is correct |
8 |
Correct |
16 ms |
6244 KB |
Output is correct |
9 |
Correct |
14 ms |
6240 KB |
Output is correct |
10 |
Correct |
16 ms |
6264 KB |
Output is correct |
11 |
Correct |
18 ms |
6256 KB |
Output is correct |
12 |
Correct |
21 ms |
6264 KB |
Output is correct |
13 |
Correct |
21 ms |
6264 KB |
Output is correct |
14 |
Correct |
11 ms |
1024 KB |
Output is correct |
15 |
Correct |
67 ms |
6264 KB |
Output is correct |
16 |
Partially correct |
66 ms |
6240 KB |
Partially correct - number of queries: 5116 |
17 |
Partially correct |
52 ms |
6240 KB |
Partially correct - number of queries: 5084 |
18 |
Partially correct |
61 ms |
6264 KB |
Partially correct - number of queries: 5087 |
19 |
Correct |
77 ms |
6256 KB |
Output is correct |
20 |
Correct |
26 ms |
3324 KB |
Output is correct |
21 |
Partially correct |
60 ms |
6264 KB |
Partially correct - number of queries: 5076 |
22 |
Correct |
53 ms |
6236 KB |
Output is correct |
23 |
Correct |
16 ms |
6240 KB |
Output is correct |
24 |
Correct |
18 ms |
6264 KB |
Output is correct |
25 |
Correct |
38 ms |
6260 KB |
Output is correct |
26 |
Correct |
60 ms |
6256 KB |
Output is correct |
27 |
Correct |
18 ms |
6240 KB |
Output is correct |
28 |
Correct |
49 ms |
6160 KB |
Output is correct |
29 |
Correct |
57 ms |
6236 KB |
Output is correct |
30 |
Partially correct |
56 ms |
6240 KB |
Partially correct - number of queries: 5062 |
31 |
Partially correct |
88 ms |
6264 KB |
Partially correct - number of queries: 5048 |
32 |
Correct |
25 ms |
6240 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Partially correct |
40 ms |
6236 KB |
Partially correct - number of queries: 5094 |
35 |
Correct |
24 ms |
6264 KB |
Output is correct |
36 |
Partially correct |
75 ms |
6264 KB |
Partially correct - number of queries: 5019 |
37 |
Correct |
21 ms |
6236 KB |
Output is correct |
38 |
Correct |
18 ms |
6236 KB |
Output is correct |
39 |
Partially correct |
60 ms |
6264 KB |
Partially correct - number of queries: 5032 |
40 |
Correct |
46 ms |
6128 KB |
Output is correct |
41 |
Partially correct |
46 ms |
6256 KB |
Partially correct - number of queries: 5078 |
42 |
Partially correct |
59 ms |
6264 KB |
Partially correct - number of queries: 5077 |
43 |
Correct |
62 ms |
6256 KB |
Output is correct |
44 |
Partially correct |
64 ms |
6240 KB |
Partially correct - number of queries: 5091 |
45 |
Correct |
64 ms |
6136 KB |
Output is correct |
46 |
Partially correct |
57 ms |
6240 KB |
Partially correct - number of queries: 5084 |
47 |
Correct |
55 ms |
6256 KB |
Output is correct |
48 |
Partially correct |
66 ms |
6240 KB |
Partially correct - number of queries: 5071 |
49 |
Partially correct |
58 ms |
6244 KB |
Partially correct - number of queries: 5068 |
50 |
Partially correct |
69 ms |
6264 KB |
Partially correct - number of queries: 5092 |
51 |
Partially correct |
97 ms |
6256 KB |
Partially correct - number of queries: 5089 |
52 |
Partially correct |
59 ms |
6236 KB |
Partially correct - number of queries: 5100 |
53 |
Correct |
16 ms |
6256 KB |
Output is correct |
54 |
Partially correct |
86 ms |
6264 KB |
Partially correct - number of queries: 5069 |
55 |
Partially correct |
61 ms |
6236 KB |
Partially correct - number of queries: 5086 |
56 |
Partially correct |
64 ms |
6236 KB |
Partially correct - number of queries: 5069 |
57 |
Partially correct |
77 ms |
6264 KB |
Partially correct - number of queries: 5067 |
58 |
Partially correct |
62 ms |
6264 KB |
Partially correct - number of queries: 5072 |
59 |
Partially correct |
56 ms |
6256 KB |
Partially correct - number of queries: 5078 |
60 |
Partially correct |
60 ms |
6264 KB |
Partially correct - number of queries: 5026 |
61 |
Correct |
14 ms |
6252 KB |
Output is correct |
62 |
Correct |
23 ms |
6256 KB |
Output is correct |
63 |
Correct |
22 ms |
6240 KB |
Output is correct |
64 |
Correct |
15 ms |
6264 KB |
Output is correct |
65 |
Correct |
17 ms |
6256 KB |
Output is correct |
66 |
Correct |
31 ms |
6256 KB |
Output is correct |
67 |
Correct |
19 ms |
6248 KB |
Output is correct |
68 |
Correct |
24 ms |
6240 KB |
Output is correct |
69 |
Correct |
16 ms |
6256 KB |
Output is correct |
70 |
Correct |
19 ms |
6264 KB |
Output is correct |
71 |
Partially correct |
40 ms |
6264 KB |
Partially correct - number of queries: 5216 |
72 |
Correct |
17 ms |
6264 KB |
Output is correct |
73 |
Partially correct |
72 ms |
6264 KB |
Partially correct - number of queries: 5153 |
74 |
Partially correct |
55 ms |
6136 KB |
Partially correct - number of queries: 5176 |
75 |
Correct |
15 ms |
6264 KB |
Output is correct |
76 |
Correct |
58 ms |
6264 KB |
Output is correct |
77 |
Partially correct |
67 ms |
6264 KB |
Partially correct - number of queries: 5212 |
78 |
Correct |
21 ms |
6264 KB |
Output is correct |
79 |
Correct |
38 ms |
6264 KB |
Output is correct |
80 |
Partially correct |
57 ms |
6264 KB |
Partially correct - number of queries: 5195 |
81 |
Partially correct |
89 ms |
6264 KB |
Partially correct - number of queries: 5173 |
82 |
Partially correct |
72 ms |
6264 KB |
Partially correct - number of queries: 5191 |
83 |
Correct |
16 ms |
6264 KB |
Output is correct |
84 |
Correct |
48 ms |
6264 KB |
Output is correct |
85 |
Partially correct |
88 ms |
6264 KB |
Partially correct - number of queries: 5193 |
86 |
Correct |
64 ms |
6264 KB |
Output is correct |
87 |
Correct |
24 ms |
6264 KB |
Output is correct |
88 |
Correct |
65 ms |
6264 KB |
Output is correct |
89 |
Correct |
67 ms |
6264 KB |
Output is correct |
90 |
Correct |
20 ms |
6264 KB |
Output is correct |
91 |
Correct |
48 ms |
6136 KB |
Output is correct |
92 |
Correct |
50 ms |
6264 KB |
Output is correct |
93 |
Correct |
65 ms |
6264 KB |
Output is correct |
94 |
Correct |
42 ms |
6264 KB |
Output is correct |
95 |
Correct |
66 ms |
6264 KB |
Output is correct |
96 |
Correct |
56 ms |
6264 KB |
Output is correct |
97 |
Correct |
45 ms |
6264 KB |
Output is correct |