Submission #1008192

#TimeUsernameProblemLanguageResultExecution timeMemory
100819212345678봉쇄 시간 (IOI23_closing)C++17
21 / 100
1071 ms31412 KiB
#include "closing.h" #include <bits/stdc++.h> using namespace std; #define ll long long const int nx=2e5+5; vector<pair<ll, ll>> d[nx]; void dfs(int u, int p, ll cw, vector<ll> &x) { x[u]=cw; for (auto [v, w]:d[u]) if (v!=p) dfs(v, u, cw+w, x); } int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { if (X>Y) swap(X, Y); for (int i=0; i<N; i++) d[i].clear(); for (int i=0; i<N-1; i++) d[U[i]].push_back({V[i], W[i]}), d[V[i]].push_back({U[i], W[i]}); vector<ll> a(N), b(N); ll mx=0; dfs(X, X, 0, a); dfs(Y, Y, 0, b); //for (int i=0; i<N; i++) cout<<a[i]<<' '<<b[i]<<'\n'; priority_queue<ll, vector<ll>, greater<ll>> pq; for (int i=0; i<N; i++) pq.push(a[i]), pq.push(b[i]); ll tmp=K; while (!pq.empty()&&pq.top()<=tmp) mx++, tmp-=pq.top(), pq.pop(); for (int i=0; i<N; i++) { for (int j=i; j<N; j++) { ll c=K, res=2*(j-i+1); for (int k=i; k<=j; k++) c-=max(a[k], b[k]); for (int k=X; k<i; k++) res++, c-=a[k]; for (int k=j+1; k<=Y; k++) res++, c-=b[k]; if (c<0) continue; while (!pq.empty()) pq.pop(); for (int k=0; k<min(X, i); k++) pq.push(a[k]); for (int k=max(Y, j)+1; k<N; k++) pq.push(b[k]); while (!pq.empty()&&c>=pq.top()) c-=pq.top(), pq.pop(), res++; mx=max(mx, res); } } return mx; }
#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...