답안 #61256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61256 2018-07-25T14:03:09 Z Diuven Candies (JOI18_candies) C++11
100 / 100
701 ms 74656 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 5 ms 504 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 4 ms 816 KB Output is correct
5 Correct 4 ms 816 KB Output is correct
6 Correct 4 ms 816 KB Output is correct
7 Correct 4 ms 816 KB Output is correct
8 Correct 5 ms 956 KB Output is correct
9 Correct 6 ms 976 KB Output is correct
10 Correct 5 ms 976 KB Output is correct
11 Correct 4 ms 976 KB Output is correct
12 Correct 6 ms 976 KB Output is correct
13 Correct 5 ms 976 KB Output is correct
14 Correct 5 ms 976 KB Output is correct
15 Correct 5 ms 1116 KB Output is correct
16 Correct 4 ms 1140 KB Output is correct
17 Correct 5 ms 1140 KB Output is correct
18 Correct 5 ms 1220 KB Output is correct
19 Correct 5 ms 1220 KB Output is correct
20 Correct 6 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 6 ms 760 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 4 ms 816 KB Output is correct
5 Correct 4 ms 816 KB Output is correct
6 Correct 4 ms 816 KB Output is correct
7 Correct 4 ms 816 KB Output is correct
8 Correct 5 ms 956 KB Output is correct
9 Correct 6 ms 976 KB Output is correct
10 Correct 5 ms 976 KB Output is correct
11 Correct 4 ms 976 KB Output is correct
12 Correct 6 ms 976 KB Output is correct
13 Correct 5 ms 976 KB Output is correct
14 Correct 5 ms 976 KB Output is correct
15 Correct 5 ms 1116 KB Output is correct
16 Correct 4 ms 1140 KB Output is correct
17 Correct 5 ms 1140 KB Output is correct
18 Correct 5 ms 1220 KB Output is correct
19 Correct 5 ms 1220 KB Output is correct
20 Correct 6 ms 1236 KB Output is correct
21 Correct 580 ms 20132 KB Output is correct
22 Correct 699 ms 22148 KB Output is correct
23 Correct 701 ms 24236 KB Output is correct
24 Correct 238 ms 25784 KB Output is correct
25 Correct 252 ms 27628 KB Output is correct
26 Correct 217 ms 29328 KB Output is correct
27 Correct 272 ms 31440 KB Output is correct
28 Correct 218 ms 33292 KB Output is correct
29 Correct 212 ms 35400 KB Output is correct
30 Correct 280 ms 37228 KB Output is correct
31 Correct 252 ms 39248 KB Output is correct
32 Correct 276 ms 41252 KB Output is correct
33 Correct 459 ms 42812 KB Output is correct
34 Correct 424 ms 44592 KB Output is correct
35 Correct 411 ms 46460 KB Output is correct
36 Correct 690 ms 48444 KB Output is correct
37 Correct 661 ms 50412 KB Output is correct
38 Correct 645 ms 52296 KB Output is correct
39 Correct 247 ms 54032 KB Output is correct
40 Correct 274 ms 55836 KB Output is correct
41 Correct 278 ms 57500 KB Output is correct
42 Correct 255 ms 59580 KB Output is correct
43 Correct 272 ms 61508 KB Output is correct
44 Correct 259 ms 63480 KB Output is correct
45 Correct 283 ms 65436 KB Output is correct
46 Correct 266 ms 67488 KB Output is correct
47 Correct 288 ms 69348 KB Output is correct
48 Correct 415 ms 71192 KB Output is correct
49 Correct 422 ms 72932 KB Output is correct
50 Correct 430 ms 74656 KB Output is correct