#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<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++;
}
{
int curK = K;
int cnt = 0;
vec<int> to_add;
for (int i = X; i <= Y; i++) {
curK -= min(dX[i], dY[i]);
cnt++;
to_add.push_back(max(dX[i], dY[i]) - min(dX[i], dY[i]));
}
for (int i = 0; i < X; i++) {
to_add.push_back(min(dX[i], dY[i]));
}
for (int i = Y + 1; i < N; i++) {
to_add.push_back(min(dX[i], dY[i]));
}
if (curK >= 0) {
sort(all(to_add));
for (int x: to_add) {
if (curK < x) break;
curK -= x;
cnt++;
}
best = max(best, cnt);
}
}
{
int curK = K;
int cnt = 0;
vec<int> to_add1;
for (int i = X; i <= Y; i++) {
curK -= min(dX[i], dY[i]);
cnt++;
if (dX[i] > dY[i]) {
to_add1.push_back(max(dX[i], dY[i]) - min(dX[i], dY[i]));
} else {
curK -= max(dX[i], dY[i]) - min(dX[i], dY[i]);
cnt++;
}
}
for (int i = Y + 1; i < N; i++) {
to_add1.push_back(min(dX[i], dY[i]));
}
for (int i = X - 1; i >= 0; i--) {
int tcnt = cnt;
int tcurK = curK;
if (curK < 0) break;
auto to_add = to_add1;
for (int j = i - 1; j >= 0; j--) {
to_add.push_back(dX[j]);
}
sort(all(to_add));
for (int x: to_add) {
if (tcurK < x) break;
tcurK -= x;
tcnt++;
}
best = max(best, tcnt);
cnt += 2;
curK -= dY[i];
}
if (curK >= 0) {
auto to_add = to_add1;
sort(all(to_add));
for (int x: to_add) {
if (curK < x) break;
curK -= x;
cnt++;
}
best = max(best, cnt);
}
}
{
int curK = K;
int cnt = 0;
vec<int> to_add1;
for (int i = X; i <= Y; i++) {
curK -= min(dX[i], dY[i]);
cnt++;
if (dX[i] < dY[i]) {
to_add1.push_back(max(dX[i], dY[i]) - min(dX[i], dY[i]));
} else {
curK -= max(dX[i], dY[i]) - min(dX[i], dY[i]);
cnt++;
}
}
for (int i = 0; i < X; i++) {
to_add1.push_back(min(dX[i], dY[i]));
}
for (int i = Y + 1; i < N; i++) {
int tcnt = cnt;
int tcurK = curK;
if (curK < 0) break;
auto to_add = to_add1;
for (int j = i + 1; j < N; j++) {
to_add.push_back(dY[j]);
}
sort(all(to_add));
for (int x: to_add) {
if (tcurK < x) break;
tcurK -= x;
tcnt++;
}
best = max(best, tcnt);
cnt += 2;
curK -= dX[i];
}
if (curK >= 0) {
auto to_add = to_add1;
sort(all(to_add));
for (int x: to_add) {
if (curK < x) break;
curK -= x;
cnt++;
}
best = max(best, cnt);
}
}
{
int curK = K;
int cnt = 0;
for (int i = X; i <= Y; i++) {
curK -= max(dX[i], dY[i]);
cnt += 2;
}
set<int> used;
vec<pair<int, int>> tgr;
for (int i = 0; i < X; i++) {
tgr.emplace_back(min(dX[i], dY[i]), i);
}
for (int i = Y + 1; i < N; i++) {
tgr.emplace_back(min(dX[i], dY[i]), i);
}
sort(all(tgr));
for (auto [t, id]: tgr) {
vec<int> to_add;
for (int i = 0; i < N; i++) {
if (i >= X and i <= Y) continue;
if (used.count(i)) continue;
to_add.push_back(min(dX[i], dY[i]));
}
if (curK >= 0) {
int tcnt = cnt;
int tcurK =curK;
sort(all(to_add));
for (int x: to_add) {
if (tcurK < x) break;
tcurK -= x;
tcnt++;
}
best = max(best, tcnt);
}
used.insert(id);
curK -= max(dX[id], dY[id]);
cnt += 2;
}
if (curK >= 0) {
best = max(best, cnt);
}
}
return best;
}
Compilation message
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 |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
36132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
6 ms |
516 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
436 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
6 ms |
516 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
360 ms |
1184 KB |
Output is correct |
27 |
Correct |
135 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
58 ms |
860 KB |
Output is correct |
30 |
Correct |
75 ms |
952 KB |
Output is correct |
31 |
Correct |
2 ms |
856 KB |
Output is correct |
32 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
516 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
444 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
516 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
444 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
348 KB |
Output is correct |
27 |
Correct |
360 ms |
1184 KB |
Output is correct |
28 |
Correct |
135 ms |
856 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
58 ms |
860 KB |
Output is correct |
31 |
Correct |
75 ms |
952 KB |
Output is correct |
32 |
Correct |
2 ms |
856 KB |
Output is correct |
33 |
Correct |
2 ms |
860 KB |
Output is correct |
34 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
516 KB |
Output is correct |
21 |
Correct |
3 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
444 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
348 KB |
Output is correct |
27 |
Correct |
360 ms |
1184 KB |
Output is correct |
28 |
Correct |
135 ms |
856 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
58 ms |
860 KB |
Output is correct |
31 |
Correct |
75 ms |
952 KB |
Output is correct |
32 |
Correct |
2 ms |
856 KB |
Output is correct |
33 |
Correct |
2 ms |
860 KB |
Output is correct |
34 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
35 |
Halted |
0 ms |
0 KB |
- |