Submission #939277

# Submission time Handle Problem Language Result Execution time Memory
939277 2024-03-06T08:03:53 Z Amirreza_Fakhri Hacker (BOI15_hac) C++17
40 / 100
314 ms 604 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 = 5e3+5;

int n, v[maxn], ps[maxn];
bool mark[maxn];

int inc(int i) {
    return (i+1)%n;
}

int dec(int i) {
    return (i-1+n)%n;
}

int g(int i, int x) {
    if (i+x < n) {
        return ps[i+x]-ps[i];
    }
    int j = (i+x)%n;
    return ps[n-1]-ps[i]+ps[j];
}

int p(int i, int x) {
    i = (i-x-1+n*2)%n;
    return g(i, x);
}

int f(int i, int j) {
    int l1, l2;
    if (i < j) l1 = j-i-1, l2 = n-2-(j-i-1);
    else l1 = n-2-(i-j-1), l2 = i-j-1;
    int res1 = v[i]+g(i, (l1+1)/2);
    if (l1&1) res1 += p(i, l2/2);
    else res1 += p(i, (l2+1)/2);

    int res2 = v[i]+p(i, (l2+1)/2);
    if (l2&1) res2 += g(i, l1/2);
    else res2 += g(i, (l1+1)/2);

    return max(res1, res2);
}

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];
        ps[i] = v[i];
        if (i) ps[i] += ps[i-1];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int res = inf;
        for (int j = 0; j < n; j++) {
            if (i != j) smin(res, f(i, j));
        }
        // cout << i << ' ' << res << '\n';
        smax(ans, res);
    }
    cout << ans << '\n';
    return 0;
}

























# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 12 ms 348 KB Output is correct
21 Correct 7 ms 348 KB Output is correct
22 Correct 101 ms 348 KB Output is correct
23 Correct 290 ms 504 KB Output is correct
24 Correct 104 ms 348 KB Output is correct
25 Correct 276 ms 496 KB Output is correct
26 Correct 282 ms 344 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 348 KB Output is correct
30 Correct 277 ms 348 KB Output is correct
31 Correct 314 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 274 ms 496 KB Output is correct
4 Incorrect 22 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 12 ms 348 KB Output is correct
21 Correct 7 ms 348 KB Output is correct
22 Correct 101 ms 348 KB Output is correct
23 Correct 290 ms 504 KB Output is correct
24 Correct 104 ms 348 KB Output is correct
25 Correct 276 ms 496 KB Output is correct
26 Correct 282 ms 344 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 348 KB Output is correct
30 Correct 277 ms 348 KB Output is correct
31 Correct 314 ms 492 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 274 ms 496 KB Output is correct
35 Incorrect 22 ms 604 KB Output isn't correct
36 Halted 0 ms 0 KB -