#include "prize.h"
#include <iostream>
#include <vector>
#include <random>
#include <ctime>
using namespace std;
const int maxn = 200005;
int N;
int max_result = 0;
vector<int> results[maxn];
int divide(int l, int r, int removed_from_left, int removed_from_right)
{
if (l > r)
{
return 0;
}
int mid = (l + r) / 2;
vector<int> curr;
while (mid <= r)
{
//curr = ask(mid);
if (!results[mid].empty())
{
curr = results[mid];
}
else
{
curr = ask(mid);
results[mid].push_back(curr[0]);
results[mid].push_back(curr[1]);
}
if (curr[0] + curr[1] == 0)
{
return mid;
}
if (curr[0] + curr[1] == max_result)
{
break;
}
++mid;
}
if (mid <= r)
{
curr[0] -= (removed_from_left - (mid - (l + r) / 2));
curr[1] -= removed_from_right;
if (curr[0] > 0)
{
int idx = divide(l, (l + r) / 2 - 1, removed_from_left, removed_from_right + curr[1] + (mid - (l + r) / 2));
if (idx != 0)
{
return idx;
}
}
if (curr[1] > 0)
{
int idx = divide(mid + 1, r, removed_from_left + curr[0] + (mid - (l + r) / 2), removed_from_right);
if (idx != 0)
{
return idx;
}
}
return 0;
}
else
{
mid = (l + r) / 2 - 1;
while (mid >= l)
{
if (!results[mid].empty())
{
curr = results[mid];
}
else
{
curr = ask(mid);
results[mid].push_back(curr[0]);
results[mid].push_back(curr[1]);
}
if (curr[0] + curr[1] == 0)
{
return mid;
}
if (curr[0] + curr[1] == max_result)
{
return mid;
}
--mid;
}
if (mid == l - 1)
{
return 0;
}
curr[0] -= removed_from_left;
if (curr[0] > 0)
{
return divide(l, mid - 1, removed_from_left, removed_from_right + (r - mid));
}
return 0;
}
return 0;
}
int find_best(int n)
{
N = n;
for (int i = 0; i < 470; ++i)
{
int idx = rand() % n;
while (!results[idx].empty())
{
idx = rand() % n;
}
vector<int> curr_result = ask(idx);
results[idx].push_back(curr_result[0]);
results[idx].push_back(curr_result[1]);
if (curr_result[0] + curr_result[1] == 0)
{
return idx;
}
max_result = max(max_result, curr_result[0] + curr_result[1]);
}
return divide(0, N - 1, 0, 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5000 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
5 ms |
4992 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4988 KB |
Output is correct |
6 |
Correct |
5 ms |
4992 KB |
Output is correct |
7 |
Correct |
8 ms |
4992 KB |
Output is correct |
8 |
Correct |
5 ms |
4944 KB |
Output is correct |
9 |
Correct |
5 ms |
5008 KB |
Output is correct |
10 |
Correct |
6 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5080 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
5 ms |
4996 KB |
Output is correct |
4 |
Correct |
5 ms |
5008 KB |
Output is correct |
5 |
Correct |
5 ms |
4944 KB |
Output is correct |
6 |
Correct |
6 ms |
4996 KB |
Output is correct |
7 |
Correct |
7 ms |
5004 KB |
Output is correct |
8 |
Correct |
6 ms |
4944 KB |
Output is correct |
9 |
Correct |
7 ms |
5012 KB |
Output is correct |
10 |
Correct |
6 ms |
4944 KB |
Output is correct |
11 |
Correct |
7 ms |
4944 KB |
Output is correct |
12 |
Correct |
8 ms |
4992 KB |
Output is correct |
13 |
Correct |
12 ms |
4980 KB |
Output is correct |
14 |
Correct |
10 ms |
4944 KB |
Output is correct |
15 |
Correct |
7 ms |
5032 KB |
Output is correct |
16 |
Correct |
4 ms |
4944 KB |
Output is correct |
17 |
Correct |
9 ms |
4992 KB |
Output is correct |
18 |
Partially correct |
44 ms |
5136 KB |
Partially correct - number of queries: 5073 |
19 |
Correct |
9 ms |
4944 KB |
Output is correct |
20 |
Correct |
17 ms |
5016 KB |
Output is correct |
21 |
Correct |
19 ms |
5004 KB |
Output is correct |
22 |
Correct |
11 ms |
5120 KB |
Output is correct |
23 |
Correct |
8 ms |
4984 KB |
Output is correct |
24 |
Correct |
9 ms |
4928 KB |
Output is correct |
25 |
Correct |
30 ms |
5004 KB |
Output is correct |
26 |
Correct |
23 ms |
5064 KB |
Output is correct |
27 |
Correct |
7 ms |
4992 KB |
Output is correct |
28 |
Correct |
32 ms |
5012 KB |
Output is correct |
29 |
Correct |
43 ms |
5064 KB |
Output is correct |
30 |
Partially correct |
41 ms |
5060 KB |
Partially correct - number of queries: 5054 |
31 |
Correct |
9 ms |
4992 KB |
Output is correct |
32 |
Correct |
11 ms |
5000 KB |
Output is correct |
33 |
Correct |
3 ms |
4944 KB |
Output is correct |
34 |
Correct |
23 ms |
5020 KB |
Output is correct |
35 |
Correct |
5 ms |
5020 KB |
Output is correct |
36 |
Correct |
15 ms |
4980 KB |
Output is correct |
37 |
Correct |
9 ms |
4988 KB |
Output is correct |
38 |
Correct |
5 ms |
5008 KB |
Output is correct |
39 |
Correct |
30 ms |
5024 KB |
Output is correct |
40 |
Correct |
35 ms |
5048 KB |
Output is correct |
41 |
Correct |
29 ms |
5064 KB |
Output is correct |
42 |
Correct |
28 ms |
5064 KB |
Output is correct |
43 |
Correct |
23 ms |
5000 KB |
Output is correct |
44 |
Correct |
24 ms |
4996 KB |
Output is correct |
45 |
Correct |
20 ms |
4944 KB |
Output is correct |
46 |
Correct |
9 ms |
4984 KB |
Output is correct |
47 |
Correct |
27 ms |
4944 KB |
Output is correct |
48 |
Correct |
36 ms |
5200 KB |
Output is correct |
49 |
Correct |
9 ms |
4984 KB |
Output is correct |
50 |
Partially correct |
45 ms |
5012 KB |
Partially correct - number of queries: 5088 |
51 |
Correct |
20 ms |
4988 KB |
Output is correct |
52 |
Correct |
10 ms |
4992 KB |
Output is correct |
53 |
Correct |
9 ms |
4944 KB |
Output is correct |
54 |
Correct |
14 ms |
5052 KB |
Output is correct |
55 |
Correct |
8 ms |
4988 KB |
Output is correct |
56 |
Partially correct |
55 ms |
5016 KB |
Partially correct - number of queries: 5089 |
57 |
Correct |
26 ms |
5032 KB |
Output is correct |
58 |
Correct |
32 ms |
5128 KB |
Output is correct |
59 |
Correct |
25 ms |
5064 KB |
Output is correct |
60 |
Correct |
27 ms |
4996 KB |
Output is correct |
61 |
Correct |
8 ms |
4996 KB |
Output is correct |
62 |
Correct |
7 ms |
4988 KB |
Output is correct |
63 |
Correct |
9 ms |
4996 KB |
Output is correct |
64 |
Correct |
7 ms |
4944 KB |
Output is correct |
65 |
Correct |
8 ms |
5072 KB |
Output is correct |
66 |
Correct |
13 ms |
5004 KB |
Output is correct |
67 |
Correct |
13 ms |
4944 KB |
Output is correct |
68 |
Correct |
7 ms |
4944 KB |
Output is correct |
69 |
Correct |
10 ms |
4944 KB |
Output is correct |
70 |
Correct |
10 ms |
4944 KB |
Output is correct |
71 |
Partially correct |
39 ms |
5208 KB |
Partially correct - number of queries: 5207 |
72 |
Correct |
11 ms |
5008 KB |
Output is correct |
73 |
Partially correct |
58 ms |
5056 KB |
Partially correct - number of queries: 5146 |
74 |
Partially correct |
34 ms |
5144 KB |
Partially correct - number of queries: 5173 |
75 |
Correct |
6 ms |
4944 KB |
Output is correct |
76 |
Correct |
44 ms |
5056 KB |
Output is correct |
77 |
Partially correct |
45 ms |
5064 KB |
Partially correct - number of queries: 5161 |
78 |
Correct |
12 ms |
4944 KB |
Output is correct |
79 |
Correct |
27 ms |
5032 KB |
Output is correct |
80 |
Partially correct |
47 ms |
5064 KB |
Partially correct - number of queries: 5158 |
81 |
Partially correct |
27 ms |
5140 KB |
Partially correct - number of queries: 5146 |
82 |
Partially correct |
59 ms |
5116 KB |
Partially correct - number of queries: 5141 |
83 |
Correct |
11 ms |
5076 KB |
Output is correct |
84 |
Correct |
38 ms |
5028 KB |
Output is correct |
85 |
Partially correct |
34 ms |
5128 KB |
Partially correct - number of queries: 5225 |
86 |
Correct |
25 ms |
5032 KB |
Output is correct |
87 |
Correct |
12 ms |
4988 KB |
Output is correct |
88 |
Correct |
22 ms |
5000 KB |
Output is correct |
89 |
Correct |
10 ms |
4944 KB |
Output is correct |
90 |
Correct |
8 ms |
4996 KB |
Output is correct |
91 |
Correct |
15 ms |
5008 KB |
Output is correct |
92 |
Correct |
29 ms |
5008 KB |
Output is correct |
93 |
Correct |
43 ms |
5044 KB |
Output is correct |
94 |
Correct |
36 ms |
5064 KB |
Output is correct |
95 |
Correct |
44 ms |
5028 KB |
Output is correct |
96 |
Correct |
36 ms |
5108 KB |
Output is correct |
97 |
Correct |
35 ms |
5092 KB |
Output is correct |