답안 #172466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172466 2020-01-01T15:20:08 Z mhy908 Candies (JOI18_candies) C++14
100 / 100
163 ms 11972 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const LL llinf=9000000000000000000;
const int inf=2000000000;
int n;
LL arr[200010], pr[200010], ne[200010];
priority_queue<pair<LL, int> > pq;
int main()
{
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%lld", &arr[i]);
        pq.push(mp(arr[i], i));
        if(i>1)pr[i]=i-1;
        if(i<n)ne[i]=i+1;
    }
    LL ans=0;
    for(int i=1; i<=(n+1)/2; i++){
        while(pq.top().F!=arr[pq.top().S])pq.pop();
        int t=pq.top().S;
        ans+=arr[t];
        printf("%lld\n", ans);
        int l=pr[t];
        int r=ne[t];
        ne[t]=ne[r];
        pr[t]=pr[l];
        pr[ne[r]]=t;
        ne[pr[l]]=t;
        if(l&&r)arr[t]=max(arr[l]+arr[r]-arr[t], -llinf);
        else arr[t]=-llinf;
        arr[l]=arr[r]=-llinf;
        pq.push(mp(arr[t], t));
    }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 484 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 484 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 160 ms 9948 KB Output is correct
22 Correct 161 ms 11800 KB Output is correct
23 Correct 160 ms 11740 KB Output is correct
24 Correct 110 ms 11612 KB Output is correct
25 Correct 113 ms 11612 KB Output is correct
26 Correct 111 ms 11592 KB Output is correct
27 Correct 127 ms 11872 KB Output is correct
28 Correct 131 ms 11712 KB Output is correct
29 Correct 128 ms 11972 KB Output is correct
30 Correct 127 ms 11828 KB Output is correct
31 Correct 131 ms 11740 KB Output is correct
32 Correct 129 ms 11804 KB Output is correct
33 Correct 138 ms 11572 KB Output is correct
34 Correct 134 ms 11484 KB Output is correct
35 Correct 141 ms 11636 KB Output is correct
36 Correct 163 ms 11776 KB Output is correct
37 Correct 162 ms 11740 KB Output is correct
38 Correct 159 ms 11740 KB Output is correct
39 Correct 109 ms 11660 KB Output is correct
40 Correct 108 ms 11612 KB Output is correct
41 Correct 108 ms 11572 KB Output is correct
42 Correct 124 ms 11736 KB Output is correct
43 Correct 126 ms 11936 KB Output is correct
44 Correct 126 ms 11796 KB Output is correct
45 Correct 125 ms 11740 KB Output is correct
46 Correct 129 ms 11792 KB Output is correct
47 Correct 127 ms 11788 KB Output is correct
48 Correct 138 ms 11488 KB Output is correct
49 Correct 136 ms 11484 KB Output is correct
50 Correct 138 ms 11592 KB Output is correct