#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 3003;
const long long INF = 1e18 + 18;
using pli = pair<long long, int>;
int n, x, y;
long long k;
long long dist[2][N];
long long dp[N][N * 2][6];
vector<pair<int, int>> g[N];
void dijkstra(int ver, int src) {
for (int i = 0; i < n; ++i) {
dist[ver][i] = INF;
}
dist[ver][src] = 0;
priority_queue<pli, vector<pli>, greater<pli>> pq;
pq.emplace(0, src);
while (!pq.empty()) {
auto [c, v] = pq.top();
pq.pop();
if (c != dist[ver][v]) {
continue;
}
for (auto [u, w] : g[v]) {
if (c + w < dist[ver][u]) {
dist[ver][u] = c + w;
pq.emplace(dist[ver][u], u);
}
}
}
}
void init() {
for (int i = 0; i < n; ++i) {
g[i].clear();
}
}
int max_score(int N_, int X_, int Y_, long long K_, vector<int> U, vector<int> V, vector<int> W) {
n = N_, x = X_, y = Y_, k = K_;
for (int i = 0; i < n - 1; ++i) {
g[U[i]].emplace_back(V[i], W[i]);
g[V[i]].emplace_back(U[i], W[i]);
}
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n * 2; ++j) {
for (int l = 0; l < 6; ++l) {
dp[i][j][l] = INF;
}
}
}
dijkstra(0, x);
dijkstra(1, y);
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j) {
return min(dist[0][i], dist[1][i]) < min(dist[0][j], dist[1][j]);
});
int tmp = 0, sum = 0;
for (int i = 0; i < n; ++i) {
if (sum + min(dist[0][ord[i]], dist[1][ord[i]]) <= k) {
sum += min(dist[0][ord[i]], dist[1][ord[i]]);
tmp++;
}
}
dp[0][0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int curans = 0; curans < n * 2; ++curans) {
for (int f = 0; f < 5; ++f) {//0 nothing, 1 x, 2 xy, 3 y, 4 nothing
dp[i][curans][f + 1] = min(dp[i][curans][f + 1], dp[i][curans][f]);
if (i == x && f != 1 && f != 2) continue;
if (i == y && f != 2 && f != 3) continue;
if (f == 2) {
dp[i + 1][curans + 2][f] = min(dp[i + 1][curans + 2][f], dp[i][curans][f] + max(dist[0][i], dist[1][i]));
} else if (f == 0 || f == 4) {
dp[i + 1][curans][f] = min(dp[i + 1][curans][f], dp[i][curans][f]);
} else {
dp[i + 1][curans + 1][f] = min(dp[i + 1][curans + 1][f], dp[i][curans][f] + dist[f / 2][i]);
}
}
}
}
int ans = 0;
for (int curans = 0; curans <= 2 * n; ++curans) {
for (int j = 0; j <= 4; ++j) {
if (dp[n][curans][j] <= k) {
ans = max(ans, curans);
}
}
}
ans = max(ans, tmp);
init();
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
480936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
0 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
0 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
1884 KB |
Output is correct |
13 |
Correct |
2 ms |
1884 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
2 ms |
1884 KB |
Output is correct |
17 |
Correct |
1 ms |
1884 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
17 ms |
26204 KB |
Output is correct |
20 |
Correct |
14 ms |
22108 KB |
Output is correct |
21 |
Correct |
15 ms |
24268 KB |
Output is correct |
22 |
Correct |
18 ms |
25924 KB |
Output is correct |
23 |
Incorrect |
17 ms |
26340 KB |
1st lines differ - on the 1st token, expected: '420', found: '500' |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
860 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
0 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
1884 KB |
Output is correct |
13 |
Correct |
2 ms |
1884 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
2 ms |
1884 KB |
Output is correct |
17 |
Correct |
1 ms |
1884 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
17 ms |
26204 KB |
Output is correct |
20 |
Correct |
14 ms |
22108 KB |
Output is correct |
21 |
Correct |
15 ms |
24268 KB |
Output is correct |
22 |
Correct |
18 ms |
25924 KB |
Output is correct |
23 |
Incorrect |
17 ms |
26340 KB |
1st lines differ - on the 1st token, expected: '420', found: '500' |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |