# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
961873 |
2024-04-12T15:35:41 Z |
garamlee500 |
Hacker (BOI15_hac) |
C++17 |
|
180 ms |
41760 KB |
#include <iostream>
using namespace std;
int nums[500000];
//int sums[500000];
// 0 to 8388606 for root/internal
// 8388607 + x for leaves
int sums[16777215];
int n, k;
int getItem(int i){
return nums[i%n];
}
int query(int l, int r, int i = 0, int x = 0, int y =8388607){
if (l==x&&y==r){
return sums[i];
}
int result= 1000000001;
int mid = (x+y+1)/2;
if (l < mid){
result = min (result, query(l, min(r, mid-1), 2*i+1, x, mid-1));
}
if (r >= mid){
result = min(result, query(max(l, mid), r, 2*i+2, mid, y));
}
return result;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++){
cin >> nums[i];
}
// Bytesar gets worst set of adjacent n/2 + n%2
k = n/2 + n%2;
sums[0+8388607]=0;
// sums starting at i, up to i + k-1
for (int i = 0; i < k; i++){
sums[0+8388607] += nums[i];
}
for (int i = 1; i < n; i++){
sums[i+8388607] = sums[i-1+8388607];
sums[i+8388607] += getItem(i+k-1) - getItem(i-1);
//cout << sums[i+8388607] << endl;
}
for (int i = 8388606; i>=0; i--){
sums[i] = min(sums[2*i+1], sums[2*i+2]);
}
int best = 0;
for (int i = 0; i < n; i++){
// starts can be anywher from i-k+1, to i;
int start = i-k+1;
int last= i, minimum;
if (start < 0){
minimum = min(
query((start+n)%n, n-1),
query(0, last)
);
}
else{
minimum = query(start, last);
}
best = max(best, minimum);
}
cout << best << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
35356 KB |
Output is correct |
2 |
Correct |
13 ms |
35420 KB |
Output is correct |
3 |
Correct |
12 ms |
35408 KB |
Output is correct |
4 |
Correct |
13 ms |
35420 KB |
Output is correct |
5 |
Correct |
11 ms |
35572 KB |
Output is correct |
6 |
Correct |
12 ms |
35420 KB |
Output is correct |
7 |
Correct |
11 ms |
35420 KB |
Output is correct |
8 |
Correct |
13 ms |
35420 KB |
Output is correct |
9 |
Correct |
12 ms |
35532 KB |
Output is correct |
10 |
Correct |
11 ms |
35416 KB |
Output is correct |
11 |
Correct |
11 ms |
35420 KB |
Output is correct |
12 |
Correct |
12 ms |
35420 KB |
Output is correct |
13 |
Correct |
11 ms |
35420 KB |
Output is correct |
14 |
Correct |
14 ms |
35420 KB |
Output is correct |
15 |
Correct |
11 ms |
35388 KB |
Output is correct |
16 |
Correct |
13 ms |
35420 KB |
Output is correct |
17 |
Correct |
12 ms |
35408 KB |
Output is correct |
18 |
Correct |
11 ms |
35420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
35356 KB |
Output is correct |
2 |
Correct |
13 ms |
35420 KB |
Output is correct |
3 |
Correct |
12 ms |
35408 KB |
Output is correct |
4 |
Correct |
13 ms |
35420 KB |
Output is correct |
5 |
Correct |
11 ms |
35572 KB |
Output is correct |
6 |
Correct |
12 ms |
35420 KB |
Output is correct |
7 |
Correct |
11 ms |
35420 KB |
Output is correct |
8 |
Correct |
13 ms |
35420 KB |
Output is correct |
9 |
Correct |
12 ms |
35532 KB |
Output is correct |
10 |
Correct |
11 ms |
35416 KB |
Output is correct |
11 |
Correct |
11 ms |
35420 KB |
Output is correct |
12 |
Correct |
12 ms |
35420 KB |
Output is correct |
13 |
Correct |
11 ms |
35420 KB |
Output is correct |
14 |
Correct |
14 ms |
35420 KB |
Output is correct |
15 |
Correct |
11 ms |
35388 KB |
Output is correct |
16 |
Correct |
13 ms |
35420 KB |
Output is correct |
17 |
Correct |
12 ms |
35408 KB |
Output is correct |
18 |
Correct |
11 ms |
35420 KB |
Output is correct |
19 |
Correct |
11 ms |
35416 KB |
Output is correct |
20 |
Correct |
12 ms |
35420 KB |
Output is correct |
21 |
Correct |
11 ms |
35360 KB |
Output is correct |
22 |
Correct |
12 ms |
35420 KB |
Output is correct |
23 |
Correct |
13 ms |
35420 KB |
Output is correct |
24 |
Correct |
13 ms |
35672 KB |
Output is correct |
25 |
Correct |
14 ms |
35420 KB |
Output is correct |
26 |
Correct |
12 ms |
35420 KB |
Output is correct |
27 |
Correct |
12 ms |
35420 KB |
Output is correct |
28 |
Correct |
12 ms |
35420 KB |
Output is correct |
29 |
Correct |
12 ms |
35576 KB |
Output is correct |
30 |
Correct |
13 ms |
35416 KB |
Output is correct |
31 |
Correct |
13 ms |
35416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
35420 KB |
Output is correct |
2 |
Correct |
12 ms |
35416 KB |
Output is correct |
3 |
Correct |
13 ms |
35604 KB |
Output is correct |
4 |
Correct |
38 ms |
38096 KB |
Output is correct |
5 |
Correct |
71 ms |
38748 KB |
Output is correct |
6 |
Correct |
88 ms |
39496 KB |
Output is correct |
7 |
Correct |
113 ms |
39748 KB |
Output is correct |
8 |
Correct |
168 ms |
41532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
35356 KB |
Output is correct |
2 |
Correct |
13 ms |
35420 KB |
Output is correct |
3 |
Correct |
12 ms |
35408 KB |
Output is correct |
4 |
Correct |
13 ms |
35420 KB |
Output is correct |
5 |
Correct |
11 ms |
35572 KB |
Output is correct |
6 |
Correct |
12 ms |
35420 KB |
Output is correct |
7 |
Correct |
11 ms |
35420 KB |
Output is correct |
8 |
Correct |
13 ms |
35420 KB |
Output is correct |
9 |
Correct |
12 ms |
35532 KB |
Output is correct |
10 |
Correct |
11 ms |
35416 KB |
Output is correct |
11 |
Correct |
11 ms |
35420 KB |
Output is correct |
12 |
Correct |
12 ms |
35420 KB |
Output is correct |
13 |
Correct |
11 ms |
35420 KB |
Output is correct |
14 |
Correct |
14 ms |
35420 KB |
Output is correct |
15 |
Correct |
11 ms |
35388 KB |
Output is correct |
16 |
Correct |
13 ms |
35420 KB |
Output is correct |
17 |
Correct |
12 ms |
35408 KB |
Output is correct |
18 |
Correct |
11 ms |
35420 KB |
Output is correct |
19 |
Correct |
11 ms |
35416 KB |
Output is correct |
20 |
Correct |
12 ms |
35420 KB |
Output is correct |
21 |
Correct |
11 ms |
35360 KB |
Output is correct |
22 |
Correct |
12 ms |
35420 KB |
Output is correct |
23 |
Correct |
13 ms |
35420 KB |
Output is correct |
24 |
Correct |
13 ms |
35672 KB |
Output is correct |
25 |
Correct |
14 ms |
35420 KB |
Output is correct |
26 |
Correct |
12 ms |
35420 KB |
Output is correct |
27 |
Correct |
12 ms |
35420 KB |
Output is correct |
28 |
Correct |
12 ms |
35420 KB |
Output is correct |
29 |
Correct |
12 ms |
35576 KB |
Output is correct |
30 |
Correct |
13 ms |
35416 KB |
Output is correct |
31 |
Correct |
13 ms |
35416 KB |
Output is correct |
32 |
Correct |
13 ms |
35420 KB |
Output is correct |
33 |
Correct |
12 ms |
35416 KB |
Output is correct |
34 |
Correct |
13 ms |
35604 KB |
Output is correct |
35 |
Correct |
38 ms |
38096 KB |
Output is correct |
36 |
Correct |
71 ms |
38748 KB |
Output is correct |
37 |
Correct |
88 ms |
39496 KB |
Output is correct |
38 |
Correct |
113 ms |
39748 KB |
Output is correct |
39 |
Correct |
168 ms |
41532 KB |
Output is correct |
40 |
Correct |
15 ms |
35436 KB |
Output is correct |
41 |
Correct |
18 ms |
35416 KB |
Output is correct |
42 |
Correct |
20 ms |
35728 KB |
Output is correct |
43 |
Correct |
80 ms |
39092 KB |
Output is correct |
44 |
Correct |
176 ms |
41760 KB |
Output is correct |
45 |
Correct |
44 ms |
37976 KB |
Output is correct |
46 |
Correct |
105 ms |
39708 KB |
Output is correct |
47 |
Correct |
172 ms |
41532 KB |
Output is correct |
48 |
Correct |
177 ms |
41736 KB |
Output is correct |
49 |
Correct |
180 ms |
40956 KB |
Output is correct |
50 |
Correct |
173 ms |
40956 KB |
Output is correct |