Submission #1078128

#TimeUsernameProblemLanguageResultExecution timeMemory
1078128idasClosing Time (IOI23_closing)C++17
43 / 100
73 ms25684 KiB
#include "bits/stdc++.h" #include "closing.h" #define FOR(i, begin, end) for(int i=(begin); i<(end); i++) #define pb push_back #define s second #define f first using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; const int N=2e5+10; ll k, c[N], d[N][2]; vector<pii> ad[N]; bool v[N][2]; int n, x, y; 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; x=X; y=Y; k=K; FOR(i, 0, n) { c[i]=d[i][0]=d[i][1]=v[i][0]=v[i][1]=0; ad[i].clear(); } FOR(i, 0, n-1) { ad[U[i]].pb({V[i],W[i]}); ad[V[i]].pb({U[i],W[i]}); } int ans=2; v[x][0]=v[y][1]=true; vi a, b; a.pb(x); b.pb(y); while(true) { ll mn=1e18, mn_in=-1; for(auto it : a) { for(auto [u, w] : ad[it]) { if(!v[u][0]) { ll now=d[it][0]+w-c[u]; if(mn>now) { mn=now; mn_in=u; } } } } ll mn2=1e18, mn_in2=-1; for(auto it : b) { for(auto [u, w] : ad[it]) { if(!v[u][1]) { ll now=d[it][1]+w-c[u]; if(mn2>now) { mn2=now; mn_in2=u; } } } } // cout << mn << " " << mn2 << ":\n"; // for(auto it : a) cout << it << " "; // cout << endl; // for(auto it : b) cout << it << " "; // cout << endl; if(mn_in==-1 && mn_in2==-1) break; if(mn<=mn2) { if(mn>k) break; k-=mn; d[mn_in][0]=mn+c[mn_in]; v[mn_in][0]=true; c[mn_in]+=mn; a.pb(mn_in); } else if(mn>mn2) { if(mn2>k) break; k-=mn2; d[mn_in2][1]=mn2+c[mn_in2]; v[mn_in2][1]=true; c[mn_in2]+=mn2; b.pb(mn_in2); } else assert(false); ans++; } // FOR(i, 0, n) { // cout << c[i] << " "; // } return ans; } /* 1 7 0 2 10 0 1 2 0 3 3 1 2 4 2 4 2 2 5 5 5 6 3 */
#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...