Submission #1207759

#TimeUsernameProblemLanguageResultExecution timeMemory
1207759NeltClosing Time (IOI23_closing)C++20
0 / 100
1012 ms2162688 KiB
#include "closing.h" #include <bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; const ll N = 2e5 + 5; vector<pair<ll, ll>> g[N]; void dfs(ll v, ll par, vector<ll> &depth) { for (auto [to, w] : g[v]) if (to != par) { depth[to] = depth[v] + w; dfs(to, v, depth); } } ll n; int max_score(int N, int X, int Y, long long k, std::vector<int> U, std::vector<int> V, std::vector<int> W) { n = N; for (ll i = 0; i < n; i++) g[i].clear(); for (ll i = 0; i + 1 < n; i++) g[U[i]].push_back(make_pair(V[i], W[i])), g[V[i]].push_back(make_pair(U[i], W[i])); vector<ll> a(n), b(n); dfs(X, 0, a); dfs(Y, 0, b); a.insert(a.begin(), 0); b.insert(b.begin(), 0); ll dp[n + 1][2 * n + 1]; for (ll i = 0; i <= n; i++) for (ll j = 0; j <= 2 * n; j++) dp[i][j] = 1e18 + 1; dp[0][0] = 0; for (ll i = 1; i <= n; i++) for (ll j = 0; j <= 2 * n; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j + 1 <= 2 * n) dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + min(a[i], b[i])); if (j + 2 <= 2 * n) dp[i][j + 2] = min(dp[i][j + 2], dp[i - 1][j] + max(a[i], b[i])); } for (ll j = 2 * n; j >= 0; j--) if (dp[n][j] <= k) return j; }

Compilation message (stderr)

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...