답안 #153907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153907 2019-09-17T12:33:01 Z arnold518 도넛 (JOI14_ho_t3) C++14
100 / 100
241 ms 4004 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;

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

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

    vector<ll> SA(N), SB(N);
    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:15: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 12 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 10 ms 376 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 12 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 10 ms 376 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 11 ms 504 KB Output is correct
22 Correct 11 ms 504 KB Output is correct
23 Correct 12 ms 548 KB Output is correct
24 Correct 9 ms 504 KB Output is correct
25 Correct 12 ms 508 KB Output is correct
26 Correct 17 ms 504 KB Output is correct
27 Correct 16 ms 504 KB Output is correct
28 Correct 16 ms 504 KB Output is correct
29 Correct 17 ms 508 KB Output is correct
30 Correct 17 ms 588 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 504 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 12 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 10 ms 376 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 11 ms 504 KB Output is correct
22 Correct 11 ms 504 KB Output is correct
23 Correct 12 ms 548 KB Output is correct
24 Correct 9 ms 504 KB Output is correct
25 Correct 12 ms 508 KB Output is correct
26 Correct 17 ms 504 KB Output is correct
27 Correct 16 ms 504 KB Output is correct
28 Correct 16 ms 504 KB Output is correct
29 Correct 17 ms 508 KB Output is correct
30 Correct 17 ms 588 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 504 KB Output is correct
35 Correct 10 ms 504 KB Output is correct
36 Correct 239 ms 3668 KB Output is correct
37 Correct 235 ms 3824 KB Output is correct
38 Correct 241 ms 3788 KB Output is correct
39 Correct 236 ms 3704 KB Output is correct
40 Correct 231 ms 3656 KB Output is correct
41 Correct 238 ms 4004 KB Output is correct
42 Correct 234 ms 3752 KB Output is correct
43 Correct 232 ms 3776 KB Output is correct
44 Correct 229 ms 3656 KB Output is correct
45 Correct 232 ms 3676 KB Output is correct
46 Correct 123 ms 3056 KB Output is correct
47 Correct 124 ms 2888 KB Output is correct
48 Correct 127 ms 3012 KB Output is correct