#include "closing.h"
#include <vector>
using namespace std;
#include <bits/stdc++.h>
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef set<ii> sii;
typedef vector<sii> vsii;
typedef tuple<int, int, int, bool> item;
#define ALL(x) (x).begin(), x.end()
#define loop(x, i) for (int i = 0; i < x; i++)
typedef long long ll;
void getDist(int i, int 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, vi U, vi V, vi 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 max = 0;
vb visX(N);
vb visY(N);
for (int xleft = 0; X - xleft >= 0; xleft++)
{
for (int xright = 0; X + xright < N; xright++)
{
for (int yleft = 0; yleft <= Y; yleft++)
{
ll sum = 0;
for (int i = 0; i < Y; i++)
{
int v = 0;
if (X - xleft <= i && i <= X + xright)
{
v = std::max(v, distX[i]);
}
if (Y - yleft <= i)
{
v = std::max(v, distY[i]);
}
sum += v;
}
int yright = 0;
for (; Y + yright < N; yright++)
{
int v = distY[Y + yright];
if (X + xright >= Y + yright)
v = std::max(v, distX[Y + yright]);
sum += v;
if (K - sum < 0)
break;
int count = 2 + xright + yright + xleft + yleft;
if (count > max)
{
cerr << "Solution has: " << xleft << ' ' << xright << ' ' << yleft << ' ' << yright << endl;
max = count;
}
}
}
}
}
cerr << endl;
return max;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '6', found: '9' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
38112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
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: '9' |
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: '9' |
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: '9' |
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: '9' |
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: '9' |
2 |
Halted |
0 ms |
0 KB |
- |