답안 #776464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776464 2023-07-08T00:45:40 Z tvladm2009 Candies (JOI18_candies) C++17
100 / 100
449 ms 29656 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll
const int N = (int) 2e5 + 7;
const ll INF = (ll) 1e18;
int n, sol[N];

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  // freopen("input", "r", stdin);

  cin >> n;
  set<pair<int, int>> s, revs;
  for (int i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    s.insert({-x, i});
    revs.insert({i, -x});
  }
  s.insert({INF, 0});
  revs.insert({0, INF});
  s.insert({INF, n + 1});
  revs.insert({n + 1, INF});
  sol[0] = 0;
  for (int i = 1; i <= (n + 1) / 2; i++) {
    pair<int, int> now = *s.begin();
    sol[i] = sol[i - 1] - now.first;

    auto it = revs.lower_bound({now.second, -INF});
    it--;
    pair<int, int> x = *it;
    s.erase(s.find({x.second, x.first}));
    revs.erase(it++);

    pair<int, int> y = *it;
    s.erase(s.find({y.second, y.first}));
    revs.erase(it++);

    pair<int, int> z = *it;
    s.erase(s.find({z.second, z.first}));
    revs.erase(it++);

    revs.insert({y.first, x.second + z.second - y.second});
    s.insert({x.second + z.second - y.second, y.first});
  }

  for (int i = 1; i <= (n + 1) / 2; i++) {
    cout << sol[i] << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 576 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 580 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 576 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 580 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 449 ms 29476 KB Output is correct
22 Correct 403 ms 29452 KB Output is correct
23 Correct 401 ms 29444 KB Output is correct
24 Correct 165 ms 29312 KB Output is correct
25 Correct 173 ms 29312 KB Output is correct
26 Correct 170 ms 29312 KB Output is correct
27 Correct 185 ms 29488 KB Output is correct
28 Correct 176 ms 29504 KB Output is correct
29 Correct 177 ms 29564 KB Output is correct
30 Correct 186 ms 29492 KB Output is correct
31 Correct 186 ms 29508 KB Output is correct
32 Correct 188 ms 29656 KB Output is correct
33 Correct 292 ms 29328 KB Output is correct
34 Correct 260 ms 29280 KB Output is correct
35 Correct 273 ms 29292 KB Output is correct
36 Correct 386 ms 29468 KB Output is correct
37 Correct 378 ms 29532 KB Output is correct
38 Correct 384 ms 29468 KB Output is correct
39 Correct 164 ms 29348 KB Output is correct
40 Correct 176 ms 29352 KB Output is correct
41 Correct 177 ms 29388 KB Output is correct
42 Correct 174 ms 29472 KB Output is correct
43 Correct 182 ms 29644 KB Output is correct
44 Correct 175 ms 29524 KB Output is correct
45 Correct 192 ms 29524 KB Output is correct
46 Correct 192 ms 29560 KB Output is correct
47 Correct 201 ms 29580 KB Output is correct
48 Correct 250 ms 29300 KB Output is correct
49 Correct 296 ms 29372 KB Output is correct
50 Correct 252 ms 29364 KB Output is correct