Submission #1070778

#TimeUsernameProblemLanguageResultExecution timeMemory
1070778MohamedFaresNebiliClosing Time (IOI23_closing)C++17
0 / 100
1012 ms27728 KiB
#include <bits/stdc++.h> #include "closing.h" using namespace std; vector<pair<int, int>> adj[200005]; long long D[200005][2]; void dfs(int X, int p, int st) { for(auto u : adj[X]) { if(u.first == p) continue; D[u.first][st] = D[X][st] + u.second; dfs(u.first, X, st); } } int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) { for(int l = 0; l < N; l++) D[l][0] = D[l][1] = 1e9 + 7, adj[l].clear(); for(int l = 0; l < N - 1; l++) { adj[U[l]].push_back({V[l], W[l]}); adj[V[l]].push_back({U[l], W[l]}); } if(X > Y) swap(X, Y); D[X][0] = 0, D[Y][1] = 0; dfs(X, X, 0); dfs(Y, Y, 1); int res = 0; for(int l = X; l >= 0; l--) { for(int i = X; i < N; i++) { for(int j = Y; j >= 0; j--) { for(int e = Y; e < N; e++) { int lo = max(l, j), hi = min(i, e); long long calc = 0; if(lo > hi) { for(int f = l; f <= i; f++) calc += D[f][0]; for(int f = j; f <= e; f++) calc += D[f][1]; } else { for(int f = l; f < lo; f++) calc += D[f][0]; for(int f = lo; f <= hi; f++) calc += max(D[f][0], D[f][1]); for(int f = hi + 1; f <= e; f++) calc += D[f][1]; } if(calc <= K) res = max(res, i - l + e - j + 2); } } } } return res; }
#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...