답안 #1000021

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000021 2024-06-16T13:18:17 Z kunzaZa183 Fireworks (APIO16_fireworks) C++17
100 / 100
218 ms 105676 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int maxn = 300000;

vector<pair<int, int>> adjlist[maxn];

pair<int, multiset<int> *> pimi(int cur, int val) {
  vector<multiset<int> *> vm;
  int income = 0;
  for (auto a : adjlist[cur]) {
    auto b = pimi(a.first, a.second);
    income += b.first;
    vm.push_back(b.second);
  }
  multiset<int> *maxi = new multiset<int>;
  if (vm.empty()) {
    maxi->insert(val), maxi->insert(val);
    return {1, maxi};
  }
  for (auto a : vm)
    if (a->size() > maxi->size()) maxi = a;
  for (auto a : vm)
    if (a != maxi)
      for (auto b : *a) maxi->insert(b);
  while (income + 1 < maxi->size()) maxi->erase(maxi->find(*maxi->rbegin()));
  int second = *maxi->rbegin();
  maxi->erase(maxi->find(*maxi->rbegin()));
  int first = *maxi->rbegin();
  maxi->erase(maxi->find(*maxi->rbegin()));
  first += val, second += val;
  maxi->insert(first), maxi->insert(second);
  return {income, maxi};
}

int32_t main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for (int i = 0; i < n + m - 1; i++) {
    int dist, c;
    cin >> dist >> c;
    sum += c;
    adjlist[dist - 1].emplace_back(i + 1, c);
  }
  auto [a, b] = pimi(0, 0);
  b->erase(b->find(*b->rbegin()));
  int last = 0;
  int slope = a;
  for (auto x : *b) {
    sum -= (x - last) * slope;
    slope--;
    last = x;
  }
  cout << sum << "\n";
}

Compilation message

fireworks.cpp: In function 'std::pair<long long int, std::multiset<long long int>*> pimi(long long int, long long int)':
fireworks.cpp:27:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   while (income + 1 < maxi->size()) maxi->erase(maxi->find(*maxi->rbegin()));
      |          ~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 1 ms 7516 KB Output is correct
5 Correct 1 ms 7516 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 1 ms 7512 KB Output is correct
8 Correct 1 ms 7516 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7256 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 2 ms 7512 KB Output is correct
5 Correct 1 ms 7516 KB Output is correct
6 Correct 2 ms 7400 KB Output is correct
7 Correct 1 ms 7516 KB Output is correct
8 Correct 2 ms 7516 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 2 ms 7516 KB Output is correct
13 Correct 2 ms 7516 KB Output is correct
14 Correct 2 ms 7516 KB Output is correct
15 Correct 2 ms 7524 KB Output is correct
16 Correct 1 ms 7516 KB Output is correct
17 Correct 2 ms 7516 KB Output is correct
18 Correct 2 ms 7516 KB Output is correct
19 Correct 2 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 1 ms 7516 KB Output is correct
5 Correct 1 ms 7516 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 1 ms 7512 KB Output is correct
8 Correct 1 ms 7516 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 2 ms 7256 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7516 KB Output is correct
14 Correct 2 ms 7512 KB Output is correct
15 Correct 1 ms 7516 KB Output is correct
16 Correct 2 ms 7400 KB Output is correct
17 Correct 1 ms 7516 KB Output is correct
18 Correct 2 ms 7516 KB Output is correct
19 Correct 2 ms 7516 KB Output is correct
20 Correct 2 ms 7516 KB Output is correct
21 Correct 2 ms 7516 KB Output is correct
22 Correct 2 ms 7516 KB Output is correct
23 Correct 2 ms 7516 KB Output is correct
24 Correct 2 ms 7516 KB Output is correct
25 Correct 2 ms 7524 KB Output is correct
26 Correct 1 ms 7516 KB Output is correct
27 Correct 2 ms 7516 KB Output is correct
28 Correct 2 ms 7516 KB Output is correct
29 Correct 2 ms 7516 KB Output is correct
30 Correct 2 ms 7512 KB Output is correct
31 Correct 2 ms 7516 KB Output is correct
32 Correct 2 ms 7772 KB Output is correct
33 Correct 2 ms 7780 KB Output is correct
34 Correct 3 ms 8028 KB Output is correct
35 Correct 3 ms 7936 KB Output is correct
36 Correct 3 ms 8028 KB Output is correct
37 Correct 4 ms 8360 KB Output is correct
38 Correct 3 ms 8284 KB Output is correct
39 Correct 4 ms 8284 KB Output is correct
40 Correct 3 ms 8540 KB Output is correct
41 Correct 4 ms 8792 KB Output is correct
42 Correct 3 ms 8028 KB Output is correct
43 Correct 3 ms 8540 KB Output is correct
44 Correct 4 ms 8540 KB Output is correct
45 Correct 4 ms 8620 KB Output is correct
46 Correct 4 ms 8796 KB Output is correct
47 Correct 4 ms 8796 KB Output is correct
48 Correct 3 ms 8536 KB Output is correct
49 Correct 4 ms 8796 KB Output is correct
50 Correct 3 ms 8540 KB Output is correct
51 Correct 3 ms 8540 KB Output is correct
52 Correct 5 ms 8540 KB Output is correct
53 Correct 4 ms 8540 KB Output is correct
54 Correct 4 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 1 ms 7516 KB Output is correct
5 Correct 1 ms 7516 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 1 ms 7512 KB Output is correct
8 Correct 1 ms 7516 KB Output is correct
9 Correct 1 ms 7516 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 2 ms 7256 KB Output is correct
12 Correct 2 ms 7260 KB Output is correct
13 Correct 2 ms 7516 KB Output is correct
14 Correct 2 ms 7512 KB Output is correct
15 Correct 1 ms 7516 KB Output is correct
16 Correct 2 ms 7400 KB Output is correct
17 Correct 1 ms 7516 KB Output is correct
18 Correct 2 ms 7516 KB Output is correct
19 Correct 2 ms 7516 KB Output is correct
20 Correct 2 ms 7516 KB Output is correct
21 Correct 2 ms 7516 KB Output is correct
22 Correct 2 ms 7516 KB Output is correct
23 Correct 2 ms 7516 KB Output is correct
24 Correct 2 ms 7516 KB Output is correct
25 Correct 2 ms 7524 KB Output is correct
26 Correct 1 ms 7516 KB Output is correct
27 Correct 2 ms 7516 KB Output is correct
28 Correct 2 ms 7516 KB Output is correct
29 Correct 2 ms 7516 KB Output is correct
30 Correct 2 ms 7512 KB Output is correct
31 Correct 2 ms 7516 KB Output is correct
32 Correct 2 ms 7772 KB Output is correct
33 Correct 2 ms 7780 KB Output is correct
34 Correct 3 ms 8028 KB Output is correct
35 Correct 3 ms 7936 KB Output is correct
36 Correct 3 ms 8028 KB Output is correct
37 Correct 4 ms 8360 KB Output is correct
38 Correct 3 ms 8284 KB Output is correct
39 Correct 4 ms 8284 KB Output is correct
40 Correct 3 ms 8540 KB Output is correct
41 Correct 4 ms 8792 KB Output is correct
42 Correct 3 ms 8028 KB Output is correct
43 Correct 3 ms 8540 KB Output is correct
44 Correct 4 ms 8540 KB Output is correct
45 Correct 4 ms 8620 KB Output is correct
46 Correct 4 ms 8796 KB Output is correct
47 Correct 4 ms 8796 KB Output is correct
48 Correct 3 ms 8536 KB Output is correct
49 Correct 4 ms 8796 KB Output is correct
50 Correct 3 ms 8540 KB Output is correct
51 Correct 3 ms 8540 KB Output is correct
52 Correct 5 ms 8540 KB Output is correct
53 Correct 4 ms 8540 KB Output is correct
54 Correct 4 ms 8796 KB Output is correct
55 Correct 10 ms 9820 KB Output is correct
56 Correct 28 ms 17236 KB Output is correct
57 Correct 44 ms 24624 KB Output is correct
58 Correct 59 ms 29664 KB Output is correct
59 Correct 79 ms 36948 KB Output is correct
60 Correct 92 ms 44372 KB Output is correct
61 Correct 107 ms 49492 KB Output is correct
62 Correct 157 ms 54356 KB Output is correct
63 Correct 148 ms 64336 KB Output is correct
64 Correct 164 ms 65864 KB Output is correct
65 Correct 102 ms 82744 KB Output is correct
66 Correct 101 ms 82664 KB Output is correct
67 Correct 91 ms 40604 KB Output is correct
68 Correct 188 ms 80212 KB Output is correct
69 Correct 189 ms 77904 KB Output is correct
70 Correct 186 ms 77788 KB Output is correct
71 Correct 211 ms 105676 KB Output is correct
72 Correct 194 ms 105656 KB Output is correct
73 Correct 206 ms 93268 KB Output is correct
74 Correct 203 ms 93524 KB Output is correct
75 Correct 194 ms 92496 KB Output is correct
76 Correct 188 ms 92756 KB Output is correct
77 Correct 201 ms 90248 KB Output is correct
78 Correct 218 ms 86940 KB Output is correct
79 Correct 215 ms 94748 KB Output is correct