Submission #1097134

# Submission time Handle Problem Language Result Execution time Memory
1097134 2024-10-06T08:11:17 Z hgmhc None (JOI14_ho_t3) C++17
100 / 100
171 ms 2760 KB
#include <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
using namespace std; using ll = long long;

const int N = 1e5+3;
int n, a[2*N];
ll p[2*N], S;

bool valid(ll l) {
    int s = 1, e = 0;
    ll sum = 0;
    while (s <= n and e < n+n) {
        if (sum < l) {
            sum += a[++e];
        } else {
            int x = e+1, y = n+n, m;
            while (x <= y) {
                m = (x+y)/2;
                if (p[m]-p[e] >= sum) y = m-1;
                else x = m+1;
            }
            if (p[x]-p[e] > 0 and S-(p[x]-p[e])-sum >= sum) {
                return true;
            }
            sum -= a[s++];
        }
    }
    return false;
}

int main() {
    scanf("%d", &n);
    rep(i,1,n) scanf("%d", &a[i]), p[i] = p[i-1]+a[i], a[i+n] = a[i];
    S = p[n];
    rep(i,n+1,n+n) p[i] = p[i-1]+a[i];
    ll x = 0, y = 1e15, m;
    while (x <= y) {
        m = (x+y)/2;
        if (valid(m)) x = m+1;
        else y = m-1;
    }
    printf("%lld", y);
}

Compilation message

2014_ho_t3.cpp: In function 'int main()':
2014_ho_t3.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:33:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     rep(i,1,n) scanf("%d", &a[i]), p[i] = p[i-1]+a[i], a[i+n] = a[i];
      |                ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 1 ms 348 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 1 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 1 ms 2396 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 1 ms 348 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 1 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 1 ms 2396 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 6 ms 600 KB Output is correct
22 Correct 6 ms 604 KB Output is correct
23 Correct 5 ms 604 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 10 ms 604 KB Output is correct
27 Correct 7 ms 604 KB Output is correct
28 Correct 8 ms 628 KB Output is correct
29 Correct 8 ms 604 KB Output is correct
30 Correct 11 ms 604 KB Output is correct
31 Correct 4 ms 604 KB Output is correct
32 Correct 4 ms 604 KB Output is correct
33 Correct 5 ms 604 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 5 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 1 ms 348 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 1 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 1 ms 2396 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 6 ms 600 KB Output is correct
22 Correct 6 ms 604 KB Output is correct
23 Correct 5 ms 604 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 5 ms 604 KB Output is correct
26 Correct 10 ms 604 KB Output is correct
27 Correct 7 ms 604 KB Output is correct
28 Correct 8 ms 628 KB Output is correct
29 Correct 8 ms 604 KB Output is correct
30 Correct 11 ms 604 KB Output is correct
31 Correct 4 ms 604 KB Output is correct
32 Correct 4 ms 604 KB Output is correct
33 Correct 5 ms 604 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 5 ms 856 KB Output is correct
36 Correct 151 ms 2648 KB Output is correct
37 Correct 167 ms 2648 KB Output is correct
38 Correct 165 ms 2652 KB Output is correct
39 Correct 148 ms 2760 KB Output is correct
40 Correct 125 ms 2652 KB Output is correct
41 Correct 123 ms 2652 KB Output is correct
42 Correct 131 ms 2648 KB Output is correct
43 Correct 171 ms 2652 KB Output is correct
44 Correct 167 ms 2648 KB Output is correct
45 Correct 131 ms 2652 KB Output is correct
46 Correct 65 ms 2652 KB Output is correct
47 Correct 72 ms 2648 KB Output is correct
48 Correct 64 ms 2652 KB Output is correct