# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1090778 |
2024-09-18T18:07:24 Z |
ShaShi |
Hacker (BOI15_hac) |
C++17 |
|
95 ms |
45904 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 |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
860 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
764 KB |
Output is correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
13 ms |
7416 KB |
Output is correct |
5 |
Correct |
32 ms |
18268 KB |
Output is correct |
6 |
Correct |
44 ms |
23120 KB |
Output is correct |
7 |
Correct |
55 ms |
27472 KB |
Output is correct |
8 |
Correct |
94 ms |
45532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
860 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
764 KB |
Output is correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
1 ms |
860 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
13 ms |
7416 KB |
Output is correct |
36 |
Correct |
32 ms |
18268 KB |
Output is correct |
37 |
Correct |
44 ms |
23120 KB |
Output is correct |
38 |
Correct |
55 ms |
27472 KB |
Output is correct |
39 |
Correct |
94 ms |
45532 KB |
Output is correct |
40 |
Correct |
2 ms |
1372 KB |
Output is correct |
41 |
Correct |
4 ms |
2140 KB |
Output is correct |
42 |
Correct |
5 ms |
3168 KB |
Output is correct |
43 |
Correct |
32 ms |
18484 KB |
Output is correct |
44 |
Correct |
93 ms |
45704 KB |
Output is correct |
45 |
Correct |
16 ms |
9304 KB |
Output is correct |
46 |
Correct |
49 ms |
27484 KB |
Output is correct |
47 |
Correct |
95 ms |
45480 KB |
Output is correct |
48 |
Correct |
91 ms |
45904 KB |
Output is correct |
49 |
Correct |
86 ms |
45096 KB |
Output is correct |
50 |
Correct |
92 ms |
45096 KB |
Output is correct |