Submission #1076370

#TimeUsernameProblemLanguageResultExecution timeMemory
1076370MarwenElarbiClosing Time (IOI23_closing)C++17
8 / 100
114 ms34180 KiB
#include <bits/stdc++.h> #include "closing.h" using namespace std; #define pb push_back #define fi first #define se second const int nax = 2e5+5; const int MOD = 1e9+7; vector<pair<int,int>> adj[nax]; vector<long long> a,b; void dfs(int x,int p,long long cur,int type){ (type ? b : a).pb(cur); for(auto u:adj[x]){ if(u.fi==p) continue; dfs(u.fi,x,cur+u.se,type); } return; } int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { a.clear(); b.clear(); for(int i=0 ; i < N ;i++) adj[i].clear(); for (int i = 0; i < N-1; ++i) { adj[U[i]].pb({V[i],W[i]}); adj[V[i]].pb({U[i],W[i]}); } dfs(X,-1,0,0); dfs(Y,-1,0,1); sort(a.begin(),a.end()); sort(b.begin(),b.end()); long long pre[N]; memset(pre,0,sizeof pre); for (int i = 1; i < N; ++i) pre[i]=b[i]+pre[i-1]; int ans=0; for (int i = 0; i < N; ++i) { int l=0; int r=N; K-=a[i]; if(K<0) break; while(r-l>1){ int mid=(r+l)/2; if(pre[mid]>K) r=mid; else l=mid; } ans=max(ans,l+i+2); } return ans; }
#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...