답안 #148101

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148101 2019-08-31T13:54:44 Z WhipppedCream Hacker (BOI15_hac) C++17
100 / 100
93 ms 14884 KB
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int maxn = 5e5+5;
int arr[2*maxn];
int qs[2*maxn];
int s[2*maxn];
int main()
{
    //#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
    int n; scanf("%d", &n);
    for(int i = 1; i<= n; i++) scanf("%d", arr+i);
    for(int i = 1; i<= n; i++) arr[n+i] = arr[i];
    for(int i = 1; i<= 2*n; i++) qs[i] = qs[i-1]+arr[i];
    int k = n/2;
    for(int i = 1; i+k-1<= 2*n; i++) s[i] = qs[i+k-1]-qs[i-1];
    int best = 2e9;
    deque< ii > dq;
    for(int i = 2; i< n-k+1; i++)
    {
        while(!dq.empty() && dq.back().X<= s[i]) dq.pop_back();
        dq.push_back(ii(s[i], i));
    }
    for(int i = 1; i<= n; i++)
    {
        while(!dq.empty() && dq.back().X<= s[n-k+i]) dq.pop_back();
        dq.push_back(ii(s[n-k+i], n-k+i));
        while(!dq.empty() && dq.front().Y<= i) dq.pop_front();
        best = min(best, dq.front().X);
    }
    printf("%d\n", qs[n]-best);
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:17:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d", &n);
            ~~~~~^~~~~~~~~~
hac.cpp:18:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i<= n; i++) scanf("%d", arr+i);
                                ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 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 376 KB Output is correct
5 Correct 2 ms 368 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 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 376 KB Output is correct
5 Correct 2 ms 368 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 3 ms 380 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 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 3 ms 504 KB Output is correct
4 Correct 17 ms 2424 KB Output is correct
5 Correct 36 ms 5368 KB Output is correct
6 Correct 48 ms 6752 KB Output is correct
7 Correct 56 ms 8156 KB Output is correct
8 Correct 93 ms 13304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 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 376 KB Output is correct
5 Correct 2 ms 368 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 3 ms 380 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 17 ms 2424 KB Output is correct
36 Correct 36 ms 5368 KB Output is correct
37 Correct 48 ms 6752 KB Output is correct
38 Correct 56 ms 8156 KB Output is correct
39 Correct 93 ms 13304 KB Output is correct
40 Correct 4 ms 632 KB Output is correct
41 Correct 6 ms 888 KB Output is correct
42 Correct 7 ms 1144 KB Output is correct
43 Correct 38 ms 5508 KB Output is correct
44 Correct 93 ms 13360 KB Output is correct
45 Correct 19 ms 2936 KB Output is correct
46 Correct 56 ms 8056 KB Output is correct
47 Correct 93 ms 13216 KB Output is correct
48 Correct 75 ms 13612 KB Output is correct
49 Correct 80 ms 14884 KB Output is correct
50 Correct 78 ms 14656 KB Output is correct