Submission #398731

#TimeUsernameProblemLanguageResultExecution timeMemory
398731ChrisTWorst Reporter 4 (JOI21_worst_reporter4)C++17
14 / 100
143 ms201468 KiB
#include <bits/stdc++.h> using namespace std; const int MN = 2e5 + 5, SUB = 5e3 + 1; int a[MN], h[MN], c[MN]; long long dp[SUB][SUB]; vector<int> adj[MN], xs; int getx (int x) {return lower_bound(xs.begin(),xs.end(),x) - xs.begin() + 1;} void dfs (int cur) { for (int i : adj[cur]) { dfs(i); for (int j = 1; j <= (int)xs.size(); j++) dp[cur][j] += dp[i][j]; } for (int j = 1; j <= (int)xs.size(); j++) dp[cur][j] += c[cur]; dp[cur][h[cur]] -= c[cur]; for (int j = h[cur]-1; j >= 1; j--) dp[cur][j] = min(dp[cur][j],dp[cur][h[cur]]); } int main () { int n; scanf ("%d",&n); for (int i = 1; i <= n; i++) { scanf ("%d %d %d",&a[i],&h[i],&c[i]); xs.push_back(h[i]); if (i > 1) adj[a[i]].push_back(i); } sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end()); for (int i = 1; i <= n; i++) h[i] = getx(h[i]); dfs(1); long long ret = 1e18; for (int i = 1; i <= (int)xs.size(); i++) ret = min(ret,dp[1][i]); printf ("%lld\n",ret); return 0; }

Compilation message (stderr)

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:18:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  int n; scanf ("%d",&n);
      |         ~~~~~~^~~~~~~~~
worst_reporter2.cpp:20:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   scanf ("%d %d %d",&a[i],&h[i],&c[i]);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...