# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1098062 |
2024-10-09T02:34:43 Z |
modwwe |
Hacker (BOI15_hac) |
C++17 |
|
94 ms |
48260 KB |
#include <bits/stdc++.h>
// #define int long long
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0);
#define pii pair<int, int>
#define endl "\n"
using namespace std;
typedef long long ll;
// typedef __int128_t lll;
typedef long double ld;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const int LG = 20;
int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, flag, q, ans, flag2;
int arr[MAXN], ps[MAXN], dp[MAXN];
int sps[MAXN][LG];
inline int go_fw(int ind, int k) {
if (ind+k-1 <= n) return ps[ind+k-1]-ps[ind-1];
return ps[n]-ps[ind-1]+go_fw(1, k-(n-ind+1));
}
inline int get_mn(int v, int k) {
int res = INF;
for (int i=LG-1; i>=0; i--) {
if (k&(1<<i)) {
res = min(res, sps[v][i]);
v += (1<<i);
}
}
return res;
}
inline int solve(int ind) {
int j = ind, res = INF;
if (ind >= (n+1)/2) return get_mn(ind-(n+1)/2+1, (n+1)/2);
return min(get_mn(1, ind), get_mn(n-((n+1)/2-ind)+1, (n+1)/2-ind));
}
int32_t main() {
#ifdef LOCAL
freopen("inp.in", "r", stdin);
freopen("res.out", "w", stdout);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
cin >> n;
for (int i=1; i<=n; i++) {
cin >> arr[i]; tmp += arr[i];
ps[i] = ps[i-1]+arr[i];
}
for (int i=1; i<=n; i++) sps[i][0] = go_fw(i, (n+1)/2);
for (int j=1; j<LG; j++) for (int i=1; i<=n; i++) sps[i][j] = min(sps[i][j-1], sps[i+(1<<(j-1))][j-1]);
ans = 0;
for (int i=1; i<=n; i++) ans = max(ans, solve(i));
cout << ans << endl;
return 0;
}
Compilation message
hac.cpp: In function 'int solve(int)':
hac.cpp:57:9: warning: unused variable 'j' [-Wunused-variable]
57 | int j = ind, res = INF;
| ^
hac.cpp:57:18: warning: unused variable 'res' [-Wunused-variable]
57 | int j = ind, res = INF;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2408 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2408 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4696 KB |
Output is correct |
26 |
Correct |
2 ms |
4700 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
4832 KB |
Output is correct |
4 |
Correct |
12 ms |
13404 KB |
Output is correct |
5 |
Correct |
28 ms |
23900 KB |
Output is correct |
6 |
Correct |
39 ms |
28496 KB |
Output is correct |
7 |
Correct |
48 ms |
31572 KB |
Output is correct |
8 |
Correct |
90 ms |
48248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2408 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
2 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4696 KB |
Output is correct |
26 |
Correct |
2 ms |
4700 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4700 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
4832 KB |
Output is correct |
35 |
Correct |
12 ms |
13404 KB |
Output is correct |
36 |
Correct |
28 ms |
23900 KB |
Output is correct |
37 |
Correct |
39 ms |
28496 KB |
Output is correct |
38 |
Correct |
48 ms |
31572 KB |
Output is correct |
39 |
Correct |
90 ms |
48248 KB |
Output is correct |
40 |
Correct |
2 ms |
4700 KB |
Output is correct |
41 |
Correct |
3 ms |
6744 KB |
Output is correct |
42 |
Correct |
8 ms |
9260 KB |
Output is correct |
43 |
Correct |
29 ms |
24156 KB |
Output is correct |
44 |
Correct |
87 ms |
47956 KB |
Output is correct |
45 |
Correct |
15 ms |
15452 KB |
Output is correct |
46 |
Correct |
45 ms |
31324 KB |
Output is correct |
47 |
Correct |
93 ms |
47988 KB |
Output is correct |
48 |
Correct |
94 ms |
48260 KB |
Output is correct |
49 |
Correct |
90 ms |
47388 KB |
Output is correct |
50 |
Correct |
87 ms |
47384 KB |
Output is correct |