Submission #722540

# Submission time Handle Problem Language Result Execution time Memory
722540 2023-04-12T09:04:00 Z minhnhatnoe Worst Reporter 4 (JOI21_worst_reporter4) C++14
0 / 100
2000 ms 852 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 = (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();
    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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Execution timed out 2083 ms 852 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Execution timed out 2083 ms 852 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Execution timed out 2083 ms 852 KB Time limit exceeded
6 Halted 0 ms 0 KB -