# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
841697 | 2023-09-01T22:35:09 Z | Pajaraja | 봉쇄 시간 (IOI23_closing) | C++17 | 1000 ms | 51952 KB |
#include "closing.h" #include <bits/stdc++.h> #include <vector> #define MAXN 200007 using namespace std; vector<int> g[MAXN],w[MAXN]; long long d[2][MAXN]; long long pm[2*MAXN]; void dfs(int br,int s,int f,long long dist) { d[br][s]=dist; for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(br,g[s][i],s,dist+w[s][i]); } int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W) { for(int i=0;i<N;i++) g[i].clear(); for(int i=0;i<N;i++) w[i].clear(); for(int i=0;i<N-1;i++) { g[U[i]].push_back(V[i]); g[V[i]].push_back(U[i]); w[U[i]].push_back(W[i]); w[V[i]].push_back(W[i]); } if(X>Y) swap(X,Y); dfs(0,X,X,0); dfs(1,Y,Y,0); vector<long long> vk; long long total=0; int br=0,ans; for(int i=0;i<N;i++) vk.push_back(d[0][i]); for(int i=0;i<N;i++) vk.push_back(d[1][i]); sort(vk.begin(),vk.end()); for(int i=0;i<vk.size();i++) { if(total+vk[i]<=K) { total+=vk[i]; br++; } } ans=br; vector<long long> p; vector<pair<long long,long long> > v; for(int i=0;i<N;i++) if(d[0][i]+d[1][i]!=d[0][Y]) { int a=min(d[0][i],d[1][i]),b=max(d[0][i],d[1][i]); if(2*a<=b) { v.push_back({2*a,0}); v.push_back({2*(b-a),0}); } else v.push_back({b,-a}); } sort(v.begin(),v.end()); p.push_back(0); if(v.size()!=0) { long long pmin=1000000000000000000LL; for(int i=v.size()-1;i>=0;i--) { if(v[i].second!=0) pmin=min(pmin,-v[i].second); pm[i]=pmin; } for(int i=0;i<v.size();i++) { if(!v[i].second) p.push_back(p.back()+v[i].first/2); else { long long cur=p.back(); p.push_back(cur+pm[i]); p.push_back(cur+v[i].first); } } } vector<pair<long long,int>> aux; vector<int> put; for(int i=0;i<N;i++) if(d[0][i]+d[1][i]==d[0][Y]) aux.push_back({d[0][i],i}); sort(aux.begin(),aux.end()); for(int i=0;i<aux.size();i++) put.push_back(aux[i].second); /*for(int i=0;i<p.size();i++) cout<<p[i]<<" "; cout<<endl;*/ for(int l=0;l<put.size();l++) { long long sum=0; for(int i=0;i<l;i++) sum+=d[0][put[i]]; for(int i=l;i<put.size();i++) sum+=d[1][put[i]]; for(int r=l;r<put.size();r++) { sum+=max(d[0][put[r]],d[1][put[r]])-d[1][put[r]]; int lt=0,rt=p.size()-1; if(sum>K) continue; while(lt!=rt) { int s=(lt+rt+1)/2; if(p[s]+sum>K) rt=s-1; else lt=s; } ans=max(ans,(int)put.size()+r-l+lt); } } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 13656 KB | 1st lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1057 ms | 51952 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 13656 KB | Output is correct |
2 | Incorrect | 3 ms | 13660 KB | 1st lines differ - on the 1st token, expected: '30', found: '29' |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 13656 KB | Output is correct |
2 | Incorrect | 3 ms | 13660 KB | 1st lines differ - on the 1st token, expected: '30', found: '29' |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 13656 KB | Output is correct |
2 | Incorrect | 3 ms | 13660 KB | 1st lines differ - on the 1st token, expected: '30', found: '29' |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 13656 KB | 1st lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 13656 KB | 1st lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 13656 KB | 1st lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 13656 KB | 1st lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 13656 KB | 1st lines differ - on the 1st token, expected: '6', found: '5' |
2 | Halted | 0 ms | 0 KB | - |