This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "closing.h"
#include "bits/stdc++.h"
using namespace std;
using i32 = int;
#define int long long
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define inf 1000'000'000'000'000'000LL
#define bit(x, i) (((x) >> i) & 1)
template<typename T>
using vec = vector<T>;
i32 max_score(i32 N, i32 X, i32 Y, int K, std::vector<i32> U, std::vector<i32> V, std::vector<i32> W) {
i32 ans = 0;
vec<vec<pair<int, int>>> g(N);
for (int i = 0; i < len(U); i++) {
g[U[i]].emplace_back(V[i], W[i]);
g[V[i]].emplace_back(U[i], W[i]);
}
auto dijkstra = [&](int start) {
priority_queue<pair<int, int>, vec<pair<int, int>>, greater<>> pq;
pq.emplace(0, start);
vec<int> dists(N, inf);
dists[start] = 0;
while (!pq.empty()) {
auto [cost, v] = pq.top();
pq.pop();
if (cost != dists[v]) continue;
for (auto [u, w]: g[v]) {
if (dists[u] > dists[v] + w) {
dists[u] = dists[v] + w;
pq.emplace(dists[u], u);
}
}
}
return dists;
};
auto dX = dijkstra(X);
auto dY = dijkstra(Y);
vec<pair<int, int>> v;
for (int i = 0; i < N; i++) {
v.emplace_back(min(dX[i], dY[i]), max(dX[i], dY[i]) - min(dX[i], dY[i]));
}
vec<int> rg(dX);
for(auto h : dY) rg.push_back(h);
sort(all(rg));
int best = 0;
int tK = K;
for(int x : rg) {
if(tK < x) break;
tK -= x;
best++;
}
for (int L = 0; L < N; L++) {
for (int r = min(L, (int) X); r < N; r++) {
int curK = K;
vec<int> t;
int cnt = 0;
for (int k = L; k <= r; k++) {
curK -= v[k].first;
t.push_back(v[k].second);
cnt++;
}
for (int k = r + 1; k <= Y; k++) {
curK -= v[k].first;
cnt++;
}
for (int k = r + 1; k < N; k++) {
t.push_back(v[k].first);
}
if (curK < 0) break;
sort(all(t));
for (int x: t) {
if (curK < x) break;
curK -= x;
cnt++;
}
best = max(best, cnt);
}
}
return best;
}
Compilation message (stderr)
closing.cpp: In function 'i32 max_score(i32, i32, i32, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:17:9: warning: unused variable 'ans' [-Wunused-variable]
17 | i32 ans = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |