Submission #744302

#TimeUsernameProblemLanguageResultExecution timeMemory
744302b00norpFireworks (APIO16_fireworks)C++14
0 / 100
12 ms1872 KiB
#include <bits/stdc++.h> using namespace std; #define int long long mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 1e18, N = 305; vector<array<int, 2> > g[N]; int dp[N][N]; void dfs(int node, int par = -1, int parent_weight = 0) { bool isLeaf = true; for(auto [to, wt]: g[node]) { dfs(to, node, wt); isLeaf = false; } // cout << "node = " << node << ", parent_weight = " << parent_weight << ", isLeaf = " << isLeaf << "\n"; if(isLeaf) { dp[node][parent_weight] = 0; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { dp[node][i] = min(dp[node][i], dp[node][j] + abs(j - i)); } } return; } for(int i = 0; i < N; i++) { dp[node][i] = INF; } vector<int> holyf(N); bool omk = true; for(auto [to, temp]: g[node]) { for(int i = 0; i < N - parent_weight; i++) { holyf[i] = INF; for(int j = 0; j < N; j++) { holyf[i] = min(holyf[i], dp[to][j] + abs(j - i)); } if(omk) { dp[node][i + parent_weight] = holyf[i]; } else { dp[node][i + parent_weight] += holyf[i]; } } omk = false; } for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { dp[node][i] = min(dp[node][i], dp[node][j] + abs(j - i)); } } } void Solve() { int n, m; cin >> n >> m; for(int i = 2; i <= n + m; i++) { int par, wt; cin >> par >> wt; // cout << "edge: {" << par << ", " << i << ", " << wt << "}\n"; g[par].push_back({i, wt}); } for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { dp[i][j] = INF; } } dfs(1); // for(int i = 1; i <= 10; i++) // { // for(int j = 0; j <= 20; j++) // { // cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << "\n"; // } // cout << "\n\n\n\n"; // } int ans = INF; for(int i = 0; i < N; i++) { ans = min(ans, dp[1][i]); } cout << ans << "\n"; } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); //cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }

Compilation message (stderr)

fireworks.cpp: In function 'void dfs(long long int, long long int, long long int)':
fireworks.cpp:14:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |  for(auto [to, wt]: g[node])
      |           ^
fireworks.cpp:38:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |  for(auto [to, temp]: g[node])
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...