답안 #435695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
435695 2021-06-23T15:11:51 Z 2qbingxuan Worst Reporter 4 (JOI21_worst_reporter4) C++14
14 / 100
63 ms 22192 KB
#include <bits/stdc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) qqbx(#a, a)
#define pary(a...) danb(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (auto it = L; it != R; ++it)
        std::cerr << *it << ' ';
    std::cerr << "]\033[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)

using namespace std;
using ll = int64_t;
const int maxn = 100025, maxm = 10000;

int H[maxn], C[maxn];
vector<int> g[maxn];
map<int,ll,greater<>> sub[maxn];
void join(int a, int b) {
    if (sub[a].size() > sub[b].size())
        swap(sub[a], sub[b]);
    for (auto [h, val]: sub[a])
        sub[b][h] += val;
}
void dfs(int i) {
    for (int j: g[i]) {
        dfs(j);
        join(j, i);
    }
    sub[i][H[i]] += C[i];
    auto it = sub[i].upper_bound(H[i]);
    ll v = C[i];
    while (it != sub[i].end()) {
        if (it->second < v) {
            v -= it->second;
            sub[i].erase(it++);
        } else {
            it->second -= v;
            break;
        }
    }
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    ll tot = 0;
    for (int i = 0; i < n; i++) {
        int A;
        cin >> A >> H[i] >> C[i];
        tot += C[i];
        --A;
        if (i) g[A].push_back(i);
    }
    dfs(0);
    ll best = 0;
    for (auto [h, val]: sub[0]) {
        best += val;
    }
    cout << tot - best << '\n';
}

Compilation message

worst_reporter2.cpp: In function 'void join(int, int)':
worst_reporter2.cpp:34:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |     for (auto [h, val]: sub[a])
      |               ^
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:69:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |     for (auto [h, val]: sub[0]) {
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 7 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 6 ms 7244 KB Output is correct
5 Correct 11 ms 8396 KB Output is correct
6 Correct 10 ms 7972 KB Output is correct
7 Correct 9 ms 7756 KB Output is correct
8 Correct 16 ms 8396 KB Output is correct
9 Correct 10 ms 7980 KB Output is correct
10 Correct 9 ms 7780 KB Output is correct
11 Correct 8 ms 7628 KB Output is correct
12 Correct 9 ms 7884 KB Output is correct
13 Correct 8 ms 7884 KB Output is correct
14 Correct 9 ms 7772 KB Output is correct
15 Correct 8 ms 7756 KB Output is correct
16 Correct 13 ms 8780 KB Output is correct
17 Correct 10 ms 8140 KB Output is correct
18 Correct 9 ms 7628 KB Output is correct
19 Correct 10 ms 8012 KB Output is correct
20 Correct 10 ms 7756 KB Output is correct
21 Correct 8 ms 7756 KB Output is correct
22 Correct 9 ms 8012 KB Output is correct
23 Correct 8 ms 7756 KB Output is correct
24 Correct 10 ms 8068 KB Output is correct
25 Correct 8 ms 7892 KB Output is correct
26 Correct 10 ms 8392 KB Output is correct
27 Correct 9 ms 8144 KB Output is correct
28 Correct 12 ms 8180 KB Output is correct
29 Correct 10 ms 8268 KB Output is correct
30 Correct 10 ms 8256 KB Output is correct
31 Correct 10 ms 8268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 7 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 6 ms 7244 KB Output is correct
5 Correct 11 ms 8396 KB Output is correct
6 Correct 10 ms 7972 KB Output is correct
7 Correct 9 ms 7756 KB Output is correct
8 Correct 16 ms 8396 KB Output is correct
9 Correct 10 ms 7980 KB Output is correct
10 Correct 9 ms 7780 KB Output is correct
11 Correct 8 ms 7628 KB Output is correct
12 Correct 9 ms 7884 KB Output is correct
13 Correct 8 ms 7884 KB Output is correct
14 Correct 9 ms 7772 KB Output is correct
15 Correct 8 ms 7756 KB Output is correct
16 Correct 13 ms 8780 KB Output is correct
17 Correct 10 ms 8140 KB Output is correct
18 Correct 9 ms 7628 KB Output is correct
19 Correct 10 ms 8012 KB Output is correct
20 Correct 10 ms 7756 KB Output is correct
21 Correct 8 ms 7756 KB Output is correct
22 Correct 9 ms 8012 KB Output is correct
23 Correct 8 ms 7756 KB Output is correct
24 Correct 10 ms 8068 KB Output is correct
25 Correct 8 ms 7892 KB Output is correct
26 Correct 10 ms 8392 KB Output is correct
27 Correct 9 ms 8144 KB Output is correct
28 Correct 12 ms 8180 KB Output is correct
29 Correct 10 ms 8268 KB Output is correct
30 Correct 10 ms 8256 KB Output is correct
31 Correct 10 ms 8268 KB Output is correct
32 Correct 14 ms 8532 KB Output is correct
33 Runtime error 63 ms 22192 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 7 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 6 ms 7244 KB Output is correct
5 Correct 11 ms 8396 KB Output is correct
6 Correct 10 ms 7972 KB Output is correct
7 Correct 9 ms 7756 KB Output is correct
8 Correct 16 ms 8396 KB Output is correct
9 Correct 10 ms 7980 KB Output is correct
10 Correct 9 ms 7780 KB Output is correct
11 Correct 8 ms 7628 KB Output is correct
12 Correct 9 ms 7884 KB Output is correct
13 Correct 8 ms 7884 KB Output is correct
14 Correct 9 ms 7772 KB Output is correct
15 Correct 8 ms 7756 KB Output is correct
16 Correct 13 ms 8780 KB Output is correct
17 Correct 10 ms 8140 KB Output is correct
18 Correct 9 ms 7628 KB Output is correct
19 Correct 10 ms 8012 KB Output is correct
20 Correct 10 ms 7756 KB Output is correct
21 Correct 8 ms 7756 KB Output is correct
22 Correct 9 ms 8012 KB Output is correct
23 Correct 8 ms 7756 KB Output is correct
24 Correct 10 ms 8068 KB Output is correct
25 Correct 8 ms 7892 KB Output is correct
26 Correct 10 ms 8392 KB Output is correct
27 Correct 9 ms 8144 KB Output is correct
28 Correct 12 ms 8180 KB Output is correct
29 Correct 10 ms 8268 KB Output is correct
30 Correct 10 ms 8256 KB Output is correct
31 Correct 10 ms 8268 KB Output is correct
32 Correct 14 ms 8532 KB Output is correct
33 Runtime error 63 ms 22192 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -