답안 #58176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58176 2018-07-17T05:52:30 Z 노영훈(#1688) Candies (JOI18_candies) C++11
100 / 100
664 ms 17968 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int MX=500010, inf=2e9;

int n;
ll A[MX];
int nxt[MX], prv[MX];

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++) cin>>A[i];
    iota(nxt+1, nxt+n+1, 2);
    iota(prv+1, prv+n+1, 0);
    nxt[0]=1, prv[n+1]=n; // by no mean

    set<pli> S;    

    for(int i=1; i<=n; i++) S.insert({A[i], i});

    ll ans=0;
    for(int j=1; j<=(n+1)/2; j++){
        pli now=*S.rbegin();
        S.erase(now);

        ans+=now.first;
        cout<<ans<<'\n';

        int i=now.second, l=prv[i], r=nxt[i];

        if(l==0){
            S.erase({A[r], r});
            prv[nxt[r]]=0;
            continue;
        }
        if(r==n+1){
            S.erase({A[l], l});
            nxt[prv[l]]=n+1;
            continue;
        }
        S.erase({A[r], r});
        S.erase({A[l], l});
        A[i] = A[l] + A[r] - A[i];
        S.insert({A[i], i});

        prv[nxt[r]]=i;
        nxt[prv[l]]=i;
        nxt[i]=nxt[r];
        prv[i]=prv[l];
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
4 Correct 3 ms 780 KB Output is correct
5 Correct 4 ms 824 KB Output is correct
6 Correct 4 ms 892 KB Output is correct
7 Correct 5 ms 892 KB Output is correct
8 Correct 7 ms 892 KB Output is correct
9 Correct 3 ms 892 KB Output is correct
10 Correct 5 ms 892 KB Output is correct
11 Correct 4 ms 956 KB Output is correct
12 Correct 4 ms 956 KB Output is correct
13 Correct 4 ms 956 KB Output is correct
14 Correct 3 ms 956 KB Output is correct
15 Correct 4 ms 956 KB Output is correct
16 Correct 5 ms 956 KB Output is correct
17 Correct 4 ms 956 KB Output is correct
18 Correct 4 ms 956 KB Output is correct
19 Correct 3 ms 956 KB Output is correct
20 Correct 3 ms 956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 640 KB Output is correct
3 Correct 3 ms 720 KB Output is correct
4 Correct 3 ms 780 KB Output is correct
5 Correct 4 ms 824 KB Output is correct
6 Correct 4 ms 892 KB Output is correct
7 Correct 5 ms 892 KB Output is correct
8 Correct 7 ms 892 KB Output is correct
9 Correct 3 ms 892 KB Output is correct
10 Correct 5 ms 892 KB Output is correct
11 Correct 4 ms 956 KB Output is correct
12 Correct 4 ms 956 KB Output is correct
13 Correct 4 ms 956 KB Output is correct
14 Correct 3 ms 956 KB Output is correct
15 Correct 4 ms 956 KB Output is correct
16 Correct 5 ms 956 KB Output is correct
17 Correct 4 ms 956 KB Output is correct
18 Correct 4 ms 956 KB Output is correct
19 Correct 3 ms 956 KB Output is correct
20 Correct 3 ms 956 KB Output is correct
21 Correct 483 ms 17776 KB Output is correct
22 Correct 485 ms 17828 KB Output is correct
23 Correct 438 ms 17860 KB Output is correct
24 Correct 186 ms 17860 KB Output is correct
25 Correct 229 ms 17860 KB Output is correct
26 Correct 230 ms 17860 KB Output is correct
27 Correct 212 ms 17860 KB Output is correct
28 Correct 238 ms 17860 KB Output is correct
29 Correct 217 ms 17880 KB Output is correct
30 Correct 310 ms 17880 KB Output is correct
31 Correct 288 ms 17880 KB Output is correct
32 Correct 261 ms 17880 KB Output is correct
33 Correct 327 ms 17884 KB Output is correct
34 Correct 425 ms 17884 KB Output is correct
35 Correct 321 ms 17884 KB Output is correct
36 Correct 664 ms 17884 KB Output is correct
37 Correct 498 ms 17944 KB Output is correct
38 Correct 508 ms 17944 KB Output is correct
39 Correct 201 ms 17944 KB Output is correct
40 Correct 183 ms 17968 KB Output is correct
41 Correct 179 ms 17968 KB Output is correct
42 Correct 236 ms 17968 KB Output is correct
43 Correct 196 ms 17968 KB Output is correct
44 Correct 188 ms 17968 KB Output is correct
45 Correct 280 ms 17968 KB Output is correct
46 Correct 208 ms 17968 KB Output is correct
47 Correct 193 ms 17968 KB Output is correct
48 Correct 328 ms 17968 KB Output is correct
49 Correct 305 ms 17968 KB Output is correct
50 Correct 307 ms 17968 KB Output is correct