답안 #232616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232616 2020-05-17T16:25:32 Z AlexLuchianov Candies (JOI18_candies) C++14
100 / 100
622 ms 27512 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <set>

using namespace std;

using ll = long long;
int const nmax = 200000;
ll v[1 + nmax];

set<int> myset;
set<pair<ll,int>> pq;

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  ll result = 0;
  for(int i = 1;i <= n; i++){
    cin >> v[i];
    myset.insert(i);
    pq.insert({v[i], i});
  }
  int lim = (n + 1) / 2;

  for(int i = 1;i <= lim; i++){
    set<pair<ll, int>>::iterator itpq = pq.end();
    itpq--;

    result += itpq->first;
    cout << result << '\n';
    int id = itpq->second;
    pq.erase(itpq);

    set<int>::iterator it, it2;
    myset.erase(id);
    it = myset.lower_bound(id);

    if(it == myset.end()){
      if(0 < myset.size()) {
        it--;
        pq.erase({v[*it], *it});
        myset.erase(it);
      }
      continue;
    }
    if(it == myset.begin()){
      pq.erase({v[*it], *it});
      myset.erase(it);
      continue;
    }
    it2 = it;
    it2--;

    v[id] = v[*it2] + v[*it] - v[id];
    pq.erase({v[*it2], *it2});
    pq.erase({v[*it], *it});
    pq.insert({v[id], id});

    myset.erase(it);
    myset.erase(it2);
    myset.insert(id);
  }
  cout << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 6 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 640 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 6 ms 640 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 640 KB Output is correct
5 Correct 7 ms 640 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 6 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 640 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 6 ms 640 KB Output is correct
20 Correct 6 ms 640 KB Output is correct
21 Correct 596 ms 26360 KB Output is correct
22 Correct 585 ms 27256 KB Output is correct
23 Correct 622 ms 27332 KB Output is correct
24 Correct 264 ms 27384 KB Output is correct
25 Correct 259 ms 27128 KB Output is correct
26 Correct 249 ms 27128 KB Output is correct
27 Correct 260 ms 27260 KB Output is correct
28 Correct 258 ms 27260 KB Output is correct
29 Correct 266 ms 27256 KB Output is correct
30 Correct 275 ms 27256 KB Output is correct
31 Correct 276 ms 27512 KB Output is correct
32 Correct 287 ms 27384 KB Output is correct
33 Correct 415 ms 27384 KB Output is correct
34 Correct 405 ms 27132 KB Output is correct
35 Correct 405 ms 27128 KB Output is correct
36 Correct 582 ms 27384 KB Output is correct
37 Correct 571 ms 27340 KB Output is correct
38 Correct 587 ms 27256 KB Output is correct
39 Correct 243 ms 27128 KB Output is correct
40 Correct 245 ms 27128 KB Output is correct
41 Correct 246 ms 27260 KB Output is correct
42 Correct 265 ms 27384 KB Output is correct
43 Correct 257 ms 27256 KB Output is correct
44 Correct 267 ms 27384 KB Output is correct
45 Correct 269 ms 27256 KB Output is correct
46 Correct 271 ms 27384 KB Output is correct
47 Correct 272 ms 27256 KB Output is correct
48 Correct 395 ms 27128 KB Output is correct
49 Correct 374 ms 27000 KB Output is correct
50 Correct 383 ms 27000 KB Output is correct