제출 #1028000

#제출 시각아이디문제언어결과실행 시간메모리
1028000Mr_HusanboyClosing Time (IOI23_closing)C++17
21 / 100
1055 ms24668 KiB
#include "closing.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second #define all(a) (a).begin(), (a).end() const long long infl = 2e18 + 10; template<typename T> int len(T &a){return a.size();} int max_score(int n, int x, int y, long long k, vector<int> U, vector<int> V, vector<int> W) { vector<vector<pair<int,int>>> g(n); for(int i = 0; i < n - 1; i ++){ g[U[i]].push_back({V[i], W[i]}); g[V[i]].push_back({U[i], W[i]}); } vector<ll> dx(n), dy(n); auto dfs = [&](auto &dfs, int i, int p = -1)->void{ for(auto [u, w] : g[i]){ if(u == p) continue; dx[u] = dx[i] + w; dfs(dfs, u, i); } }; dfs(dfs, x); swap(dx, dy); dfs(dfs, y); swap(dx, dy); int ans = 0; for(int l = x; l < n; l ++){ for(int r = y; r >= 0; r --){ ll tot = 0; for(int j = r; j <= l; j ++){ tot += max(dx[j], dy[j]); } for(int j = x; j < min(l + 1, r); j ++) tot += dx[j]; for(int j = y; j > max(r - 1, l); j --) tot += dy[j]; // cout << tot << endl; if(tot > k){ break; } vector<ll> one; for(int j = 0; j < min(r, x); j ++){ one.push_back(dx[j]); } for(int j = max(l, y) + 1; j < n; j ++){ one.push_back(dy[j]); } sort(all(one)); int i = 0; while(i < len(one)){ tot += one[i]; if(tot > k) break; i ++; } //cout << l << ' ' << r << ' ' << l - x + 1 + y - r + 1 + i + max(0, x - r) + max(0, l - y) << endl; ans = max(ans, l - x + 1 + y - r + 1 + i + max(0, x - r) + max(0, l - y)); } } 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...