#include "closing.h"
using namespace std;
#include <bits/stdc++.h>
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef set<ii> sii;
typedef vector<sii> vsii;
typedef tuple<ll, ll, ll, bool> item;
#define ALL(x) (x).begin(), x.end()
#define loop(x, i) for (int i = 0; i < x; i++)
void getDist(int i, ll d, vi &dist, const vsii &adj)
{
dist[i] = d;
for (auto [j, w] : adj[i])
{
if (dist[j] != -1)
continue;
getDist(j, dist[i] + w, dist, adj);
}
}
int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W)
{
vsii adj(N);
loop(N - 1, i)
{
adj[U[i]].insert({V[i], W[i]});
adj[V[i]].insert({U[i], W[i]});
}
vi distX(N, -1), distY(N, -1);
distX[X] = 0;
distY[Y] = 0;
getDist(X, 0, distX, adj);
getDist(Y, 0, distY, adj);
int res = 0;
vb visX(N);
vb visY(N);
for (int xleft = X; xleft >= 0; xleft--)
{
for (int xright = X; xright < N; xright++)
{
for (int yleft = Y; yleft >= 0; yleft--)
{
for (int yright = Y; yright < N; yright++)
{
ll sum = 0;
for (int p = 0; p < N; p++)
{
ll v = 0;
if (xleft <= p && p <= xright)
v = max(v, distX[p]);
if (yleft <= p && p <= yright)
v = max(v, distY[p]);
sum += v;
}
if (sum <= K)
{
res = max(res, 2 + yright + xright - xleft - yleft);
}
}
}
}
}
cerr << endl;
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 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 |
1061 ms |
45924 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 |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
52 ms |
416 KB |
Output is correct |
7 |
Correct |
39 ms |
344 KB |
Output is correct |
8 |
Correct |
15 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
344 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 |
344 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 |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
52 ms |
416 KB |
Output is correct |
7 |
Correct |
39 ms |
344 KB |
Output is correct |
8 |
Correct |
15 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
175 ms |
444 KB |
Output is correct |
13 |
Correct |
110 ms |
428 KB |
Output is correct |
14 |
Correct |
405 ms |
348 KB |
Output is correct |
15 |
Correct |
161 ms |
432 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
13 ms |
456 KB |
Output is correct |
19 |
Execution timed out |
1022 ms |
344 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
52 ms |
416 KB |
Output is correct |
7 |
Correct |
39 ms |
344 KB |
Output is correct |
8 |
Correct |
15 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
175 ms |
444 KB |
Output is correct |
13 |
Correct |
110 ms |
428 KB |
Output is correct |
14 |
Correct |
405 ms |
348 KB |
Output is correct |
15 |
Correct |
161 ms |
432 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
13 ms |
456 KB |
Output is correct |
19 |
Execution timed out |
1022 ms |
344 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 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 |
0 ms |
344 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 |
0 ms |
344 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 |
0 ms |
344 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 |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |