Submission #722541

# Submission time Handle Problem Language Result Execution time Memory
722541 2023-04-12T09:05:22 Z minhnhatnoe Worst Reporter 4 (JOI21_worst_reporter4) C++14
14 / 100
593 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> h, c;
vector<vector<int>> g;
void get_input(){
    int n; cin >> n;
    g.resize(n), h.resize(n), c.resize(n);
    for (int i=0; i<n; i++){
        int p; cin >> p; p--;
        if (i != 0) g[p].push_back(i);
        cin >> h[i] >> c[i];
    }
    vector<int> l = h; sort(l.begin(), l.end()); l.resize(unique(l.begin(), l.end()) - l.begin());
    for (int i=0; i<h.size(); i++){
        h[i] = lower_bound(l.begin(), l.end(), h[i]) - l.begin();
    }
}
vector<vector<ll>> dp;
ll get_cost(int v, int min_value){
    if (min_value == g.size()) return 1e18;
    ll &result = dp[v][min_value];
    if (result != -1) return result;
    result = (min_value == h[v] ? 0 : c[v]);
    for (int u: g[v]){
        result += get_cost(u, min_value);
    }
    return result = min(result, get_cost(v, min_value+1));
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    get_input();
    dp.assign(g.size(), vector<ll> (g.size(), -1));
    cout << get_cost(0, 0) << "\n";
}

Compilation message

worst_reporter2.cpp: In function 'void get_input()':
worst_reporter2.cpp:15:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i=0; i<h.size(); i++){
      |                   ~^~~~~~~~~
worst_reporter2.cpp: In function 'll get_cost(int, int)':
worst_reporter2.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     if (min_value == g.size()) return 1e18;
      |         ~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 363 ms 196556 KB Output is correct
6 Correct 364 ms 196556 KB Output is correct
7 Correct 388 ms 196700 KB Output is correct
8 Correct 359 ms 196840 KB Output is correct
9 Correct 353 ms 196692 KB Output is correct
10 Correct 376 ms 196744 KB Output is correct
11 Correct 373 ms 196820 KB Output is correct
12 Correct 361 ms 197128 KB Output is correct
13 Correct 347 ms 197060 KB Output is correct
14 Correct 352 ms 196940 KB Output is correct
15 Correct 351 ms 197104 KB Output is correct
16 Correct 367 ms 196808 KB Output is correct
17 Correct 365 ms 196872 KB Output is correct
18 Correct 377 ms 196688 KB Output is correct
19 Correct 363 ms 196804 KB Output is correct
20 Correct 365 ms 196924 KB Output is correct
21 Correct 362 ms 196896 KB Output is correct
22 Correct 593 ms 196780 KB Output is correct
23 Correct 512 ms 196924 KB Output is correct
24 Correct 442 ms 196984 KB Output is correct
25 Correct 469 ms 196956 KB Output is correct
26 Correct 348 ms 197204 KB Output is correct
27 Correct 390 ms 196812 KB Output is correct
28 Correct 353 ms 196980 KB Output is correct
29 Correct 374 ms 197036 KB Output is correct
30 Correct 364 ms 196860 KB Output is correct
31 Correct 354 ms 196996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 363 ms 196556 KB Output is correct
6 Correct 364 ms 196556 KB Output is correct
7 Correct 388 ms 196700 KB Output is correct
8 Correct 359 ms 196840 KB Output is correct
9 Correct 353 ms 196692 KB Output is correct
10 Correct 376 ms 196744 KB Output is correct
11 Correct 373 ms 196820 KB Output is correct
12 Correct 361 ms 197128 KB Output is correct
13 Correct 347 ms 197060 KB Output is correct
14 Correct 352 ms 196940 KB Output is correct
15 Correct 351 ms 197104 KB Output is correct
16 Correct 367 ms 196808 KB Output is correct
17 Correct 365 ms 196872 KB Output is correct
18 Correct 377 ms 196688 KB Output is correct
19 Correct 363 ms 196804 KB Output is correct
20 Correct 365 ms 196924 KB Output is correct
21 Correct 362 ms 196896 KB Output is correct
22 Correct 593 ms 196780 KB Output is correct
23 Correct 512 ms 196924 KB Output is correct
24 Correct 442 ms 196984 KB Output is correct
25 Correct 469 ms 196956 KB Output is correct
26 Correct 348 ms 197204 KB Output is correct
27 Correct 390 ms 196812 KB Output is correct
28 Correct 353 ms 196980 KB Output is correct
29 Correct 374 ms 197036 KB Output is correct
30 Correct 364 ms 196860 KB Output is correct
31 Correct 354 ms 196996 KB Output is correct
32 Correct 367 ms 196860 KB Output is correct
33 Runtime error 321 ms 524288 KB Execution killed with signal 9
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 363 ms 196556 KB Output is correct
6 Correct 364 ms 196556 KB Output is correct
7 Correct 388 ms 196700 KB Output is correct
8 Correct 359 ms 196840 KB Output is correct
9 Correct 353 ms 196692 KB Output is correct
10 Correct 376 ms 196744 KB Output is correct
11 Correct 373 ms 196820 KB Output is correct
12 Correct 361 ms 197128 KB Output is correct
13 Correct 347 ms 197060 KB Output is correct
14 Correct 352 ms 196940 KB Output is correct
15 Correct 351 ms 197104 KB Output is correct
16 Correct 367 ms 196808 KB Output is correct
17 Correct 365 ms 196872 KB Output is correct
18 Correct 377 ms 196688 KB Output is correct
19 Correct 363 ms 196804 KB Output is correct
20 Correct 365 ms 196924 KB Output is correct
21 Correct 362 ms 196896 KB Output is correct
22 Correct 593 ms 196780 KB Output is correct
23 Correct 512 ms 196924 KB Output is correct
24 Correct 442 ms 196984 KB Output is correct
25 Correct 469 ms 196956 KB Output is correct
26 Correct 348 ms 197204 KB Output is correct
27 Correct 390 ms 196812 KB Output is correct
28 Correct 353 ms 196980 KB Output is correct
29 Correct 374 ms 197036 KB Output is correct
30 Correct 364 ms 196860 KB Output is correct
31 Correct 354 ms 196996 KB Output is correct
32 Correct 367 ms 196860 KB Output is correct
33 Runtime error 321 ms 524288 KB Execution killed with signal 9
34 Halted 0 ms 0 KB -