답안 #153910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153910 2019-09-17T12:36:24 Z arnold518 도넛 (JOI14_ho_t3) C++14
100 / 100
193 ms 3704 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N;
ll A[MAXN+10], S;
ll SA[MAXN+10], SB[MAXN+10];

bool decide(ll x)
{
    int i, j;

    int pa=0, pb=N-1;
    ll suma=0, sumb=0;

    for(i=0; i<N; i++)
    {
        for(; suma<x; pa=(pa+1)%N) suma+=A[pa];
        SA[i]=suma;
        suma-=A[i];
    }
    for(i=N-1; i>=0; i--)
    {
        for(; sumb<x; pb=(pb+N-1)%N) sumb+=A[pb];
        SB[i]=sumb;
        sumb-=A[i];
    }
    for(i=0; i<N; i++) if(S-SA[i]-SB[(i+N-1)%N]>=x) return true;
    return false;
}

int main()
{
    int i, j;

    scanf("%d", &N);
    for(i=0; i<N; i++) scanf("%lld", &A[i]), S+=A[i];

    ll lo=0, hi=S;
    while(lo+1<hi)
    {
        ll mid=lo+hi>>1;
        if(decide(mid)) lo=mid;
        else hi=mid;
    }
    printf("%lld", lo);
}

Compilation message

2014_ho_t3.cpp: In function 'bool decide(ll)':
2014_ho_t3.cpp:16:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
2014_ho_t3.cpp: In function 'int main()':
2014_ho_t3.cpp:47:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         ll mid=lo+hi>>1;
                ~~^~~
2014_ho_t3.cpp:39:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
2014_ho_t3.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
2014_ho_t3.cpp:42:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=0; i<N; i++) scanf("%lld", &A[i]), S+=A[i];
                        ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 280 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 280 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 312 KB Output is correct
21 Correct 11 ms 504 KB Output is correct
22 Correct 11 ms 632 KB Output is correct
23 Correct 11 ms 504 KB Output is correct
24 Correct 11 ms 504 KB Output is correct
25 Correct 11 ms 504 KB Output is correct
26 Correct 16 ms 632 KB Output is correct
27 Correct 16 ms 640 KB Output is correct
28 Correct 16 ms 632 KB Output is correct
29 Correct 17 ms 760 KB Output is correct
30 Correct 17 ms 640 KB Output is correct
31 Correct 10 ms 504 KB Output is correct
32 Correct 10 ms 504 KB Output is correct
33 Correct 10 ms 504 KB Output is correct
34 Correct 10 ms 500 KB Output is correct
35 Correct 10 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 3 ms 348 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 280 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 312 KB Output is correct
21 Correct 11 ms 504 KB Output is correct
22 Correct 11 ms 632 KB Output is correct
23 Correct 11 ms 504 KB Output is correct
24 Correct 11 ms 504 KB Output is correct
25 Correct 11 ms 504 KB Output is correct
26 Correct 16 ms 632 KB Output is correct
27 Correct 16 ms 640 KB Output is correct
28 Correct 16 ms 632 KB Output is correct
29 Correct 17 ms 760 KB Output is correct
30 Correct 17 ms 640 KB Output is correct
31 Correct 10 ms 504 KB Output is correct
32 Correct 10 ms 504 KB Output is correct
33 Correct 10 ms 504 KB Output is correct
34 Correct 10 ms 500 KB Output is correct
35 Correct 10 ms 504 KB Output is correct
36 Correct 188 ms 3688 KB Output is correct
37 Correct 188 ms 3576 KB Output is correct
38 Correct 192 ms 3668 KB Output is correct
39 Correct 191 ms 3652 KB Output is correct
40 Correct 188 ms 3704 KB Output is correct
41 Correct 190 ms 3676 KB Output is correct
42 Correct 188 ms 3676 KB Output is correct
43 Correct 189 ms 3676 KB Output is correct
44 Correct 188 ms 3704 KB Output is correct
45 Correct 193 ms 3704 KB Output is correct
46 Correct 99 ms 2936 KB Output is correct
47 Correct 98 ms 2908 KB Output is correct
48 Correct 98 ms 2912 KB Output is correct