답안 #448250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448250 2021-07-29T12:37:33 Z JovanB 도넛 (JOI14_ho_t3) C++17
100 / 100
79 ms 4468 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
ll pre[200005];
 
int lp, rp;
 
ll ternary(int l, int r){
    if(r-l <= 3){
        ll mn = 1e18;
        for(int i=l; i<=r; i++){
            ll x = abs(pre[i]-pre[lp-1]-(pre[rp]-pre[i]));
            mn = min(mn, x);
        }
        return (pre[rp]-pre[lp-1]-mn)/2;
    }
    int a = l + (r-l)/3;
    int b = r - (r-l)/3;
    ll a1 = abs(pre[a]-pre[lp-1]-(pre[rp]-pre[a]));
    ll b1 = abs(pre[b]-pre[lp-1]-(pre[rp]-pre[b]));
    if(a1 == b1) return ternary(a, b);
    if(a1 < b1) return ternary(l, b);
    if(a1 > b1) return ternary(a, r);
}
 
ll a[200005];
 
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;
 
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        a[i+n] = a[i];
    }
    for(int i=1; i<=2*n; i++){
        pre[i] = pre[i-1]+a[i];
    }
    int r = 1;
    ll res = 0;
    for(int l=1; l<=n; l++){
        lp = r+1;
        rp = l+n-1;
        while(ternary(r+1, l+n-1) >= pre[r]-pre[l-1]){
            res = max(res, pre[r]-pre[l-1]);
            r++;
            lp = r+1;
            rp = l+n-1;
        }
    }
    cout << res << "\n";
    return 0;
}

Compilation message

2014_ho_t3.cpp: In function 'll ternary(int, int)':
2014_ho_t3.cpp:27:1: warning: control reaches end of non-void function [-Wreturn-type]
   27 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 5 ms 588 KB Output is correct
22 Correct 5 ms 588 KB Output is correct
23 Correct 5 ms 588 KB Output is correct
24 Correct 5 ms 588 KB Output is correct
25 Correct 5 ms 588 KB Output is correct
26 Correct 5 ms 588 KB Output is correct
27 Correct 5 ms 588 KB Output is correct
28 Correct 5 ms 584 KB Output is correct
29 Correct 5 ms 588 KB Output is correct
30 Correct 5 ms 588 KB Output is correct
31 Correct 4 ms 588 KB Output is correct
32 Correct 4 ms 588 KB Output is correct
33 Correct 4 ms 588 KB Output is correct
34 Correct 4 ms 588 KB Output is correct
35 Correct 5 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 5 ms 588 KB Output is correct
22 Correct 5 ms 588 KB Output is correct
23 Correct 5 ms 588 KB Output is correct
24 Correct 5 ms 588 KB Output is correct
25 Correct 5 ms 588 KB Output is correct
26 Correct 5 ms 588 KB Output is correct
27 Correct 5 ms 588 KB Output is correct
28 Correct 5 ms 584 KB Output is correct
29 Correct 5 ms 588 KB Output is correct
30 Correct 5 ms 588 KB Output is correct
31 Correct 4 ms 588 KB Output is correct
32 Correct 4 ms 588 KB Output is correct
33 Correct 4 ms 588 KB Output is correct
34 Correct 4 ms 588 KB Output is correct
35 Correct 5 ms 588 KB Output is correct
36 Correct 77 ms 4300 KB Output is correct
37 Correct 77 ms 4300 KB Output is correct
38 Correct 78 ms 4396 KB Output is correct
39 Correct 76 ms 4396 KB Output is correct
40 Correct 77 ms 4300 KB Output is correct
41 Correct 78 ms 4468 KB Output is correct
42 Correct 79 ms 4392 KB Output is correct
43 Correct 75 ms 4300 KB Output is correct
44 Correct 78 ms 4396 KB Output is correct
45 Correct 78 ms 4300 KB Output is correct
46 Correct 62 ms 3652 KB Output is correct
47 Correct 64 ms 3532 KB Output is correct
48 Correct 61 ms 3532 KB Output is correct