Submission #893864

#TimeUsernameProblemLanguageResultExecution timeMemory
893864danikoynovWorst Reporter 4 (JOI21_worst_reporter4)C++14
0 / 100
1 ms348 KiB
/** ____ ____ ____ ____ ____ ____ ||l |||e |||i |||n |||a |||d || ||__|||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\|/__\| **/ #include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 5010; const ll inf = 1e18; int n, a[maxn], h[maxn]; ll c[maxn]; vector < int > adj[maxn]; void input() { cin >> n; for (int i = 1; i <= n; i ++) { cin >> a[i] >> h[i] >> c[i]; if (a[i] != i) adj[a[i]].push_back(i); } } unordered_map < int, int > tag; void compress() { vector < int > values; for (int i = 1; i <= n; i ++) values.push_back(h[i]); sort(values.begin(), values.end()); for (int i = 0; i < n; i ++) tag[values[i]] = i + 1; } ll dp[maxn][maxn], temp[maxn]; int used[maxn]; void dfs(int v) { for (int j = tag[h[v]] + 1; j <= n; j ++) { dp[v][j] = c[v]; } used[v] = 1; for (int u : adj[v]) { dfs(u); for (int j = n; j >= 1; j --) { dp[v][j] += dp[u][j]; } } for (int j = n - 1; j > 0; j --) { dp[v][j] = min(dp[v][j], dp[v][j + 1]); } cout << "state " << v << " " << h[v] << endl; for (int j = 1; j <= n; j ++) cout << dp[v][j] << " "; cout << endl; } void calculate_states() { ll ans = 0; for (int i = 1; i <= n; i ++) { if (used[i]) continue; dfs(i); ll best = inf; for (int j = 1; j <= n; j ++) { best = min(best, dp[i][j]); } ans += best; } cout << ans << endl; } void solve() { input(); compress(); calculate_states(); } int main() { solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...