Submission #810178

#TimeUsernameProblemLanguageResultExecution timeMemory
810178vjudge1Worst Reporter 4 (JOI21_worst_reporter4)C++17
14 / 100
185 ms197096 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 5e3 + 10; int n; vector<int> G[N]; int a[N], h[N], c[N]; void compress() { map<int, int> mp; for(int i = 1; i <= n; i++) mp[h[i]] = 1; int k = 0; for(auto &c : mp) { c.second = k++; } for(int i = 1; i <= n; i++) h[i] = mp[h[i]]; } ll f[N][N]; int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; cin >> h[i]; cin >> c[i]; if(a[i] < i) G[a[i]].push_back(i); } compress(); // for(int i = 1; i <= n; i++) // cout << h[i] << ' '; // cout << '\n'; for(int i = n; i >= 1; i--) { vector<ll> g(n, c[i]); g[h[i]] = 0; for(int to : G[i]) { for(int x = 0; x < n; x++) { g[x] += f[to][x]; } } for(int x = n - 1; x >= 0; x--) { f[i][x] = g[x]; if(x < n - 1) f[i][x] = min(f[i][x], f[i][x + 1]); } } ll res = 1e18; for(int x = 0; x < n - 1; x++) res = min(res, f[1][x]); cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...