Submission #939333

# Submission time Handle Problem Language Result Execution time Memory
939333 2024-03-06T09:23:13 Z Amirreza_Fakhri Hacker (BOI15_hac) C++17
100 / 100
244 ms 18516 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 5e5+5;

int n, v[maxn];
multiset <int> st;

int g(int i, int x = (n+1)/2) {
    if (i+x-1 < n) {
        // if (i == 1) cout << "HI\n" << ' ' << v[i+x-1] << ' ' << (i-1 >= 0 ? v[i-1] : 0) << '\n';
        return v[i+x-1]-(i-1 >= 0 ? v[i-1] : 0);
    }
    int j = (i+x-1)%n;
    return v[j]+v[n-1]-(i-1 >= 0 ? v[i-1] : 0);
}
 
int p(int i, int x = (n+1)/2) {
    i = (i-x+1+3*n)%n;
    return g(i);
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (i) v[i] += v[i-1];
    }
    for (int i = 0; i < (n+1)/2; i++) st.insert(g(i));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int j = ((n+1)/2-1+i)%n;
        smax(ans, *st.begin());
        st.erase(st.find(p(j)));
        st.insert(g((j+1)%n));
    }
    cout << ans << '\n';
    return 0;
}

























# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 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 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 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 1 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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 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 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 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 1 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 348 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 1 ms 476 KB Output is correct
25 Correct 2 ms 640 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 26 ms 4484 KB Output is correct
5 Correct 75 ms 7260 KB Output is correct
6 Correct 103 ms 8348 KB Output is correct
7 Correct 113 ms 9840 KB Output is correct
8 Correct 234 ms 15956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 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 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 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 1 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 348 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 1 ms 476 KB Output is correct
25 Correct 2 ms 640 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 26 ms 4484 KB Output is correct
36 Correct 75 ms 7260 KB Output is correct
37 Correct 103 ms 8348 KB Output is correct
38 Correct 113 ms 9840 KB Output is correct
39 Correct 234 ms 15956 KB Output is correct
40 Correct 3 ms 600 KB Output is correct
41 Correct 8 ms 1116 KB Output is correct
42 Correct 11 ms 3672 KB Output is correct
43 Correct 76 ms 8248 KB Output is correct
44 Correct 244 ms 18512 KB Output is correct
45 Correct 40 ms 5212 KB Output is correct
46 Correct 111 ms 11152 KB Output is correct
47 Correct 227 ms 18256 KB Output is correct
48 Correct 171 ms 18516 KB Output is correct
49 Correct 159 ms 17492 KB Output is correct
50 Correct 167 ms 17672 KB Output is correct