#include "closing.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define ll long long
const int mxn = 2e5+10;
vector<pii> tree[mxn];
ll dp[mxn],arr[mxn],brr[mxn],need[mxn];
int N;
int X,Y;
void init(){
for(int i = 0;i<=N;i++)tree[i].clear();
}
void dfs(int now,int par){
if(now == par)dp[now] = 0;
for(auto [nxt,w]:tree[now]){
if(nxt == par)continue;
dp[nxt] = dp[now]+w;
dfs(nxt,now);
}
return;
}
int check(ll lim){
for(int i = N;i>=1;i--)need[i] = need[i-1];
need[0] = 0;
for(int i = 1;i<=N;i++)need[i] += need[i-1];
int rp = N;
int re = 0;
for(int i = Y;i>=0;i--){
while(need[rp]-need[i]>lim)rp--;
if(rp<=Y)break;
re = max(re,rp-i);
//cerr<<lim<<":"<<i<<','<<rp<<endl;
}
return re;
}
int max_score(int NN, int XX, int YY, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W){
X = XX,Y = YY;
init();
N = NN;
for(int i = 0;i<U.size();i++){
int a = U[i],b = V[i],w = W[i];
tree[a].push_back(pii(b,w));
tree[b].push_back(pii(a,w));
}
dfs(X,X);
for(int i = 0;i<N;i++)arr[i] = dp[i];
dfs(Y,Y);
for(int i = 0;i<N;i++)brr[i] = dp[i];
//for(int i = 0;i<N;i++)cerr<<arr[i]<<' ';cerr<<endl;
//for(int i = 0;i<N;i++)cerr<<brr[i]<<' ';cerr<<endl;
int ans = 0;
for(int i = 0;i<=X;i++){
for(int j = X;j<N;j++){
ll sum = 0;
for(int k = 0;k<N;k++)need[k] = brr[k];
for(int k = i;k<=j;k++){
sum += arr[k];
need[k] = max(0ll,brr[k]-arr[k]);
}
if(sum>K)continue;
ans = max(ans,j-i+1+check(K-sum));
}
}
return ans;
}
Compilation message
closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i = 0;i<U.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1040 ms |
27684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5064 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5064 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4952 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
3 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
34 ms |
5208 KB |
Output is correct |
20 |
Correct |
5 ms |
5208 KB |
Output is correct |
21 |
Correct |
32 ms |
5232 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
3 ms |
5212 KB |
Output is correct |
24 |
Correct |
2 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
5064 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
2 ms |
4956 KB |
Output is correct |
6 |
Correct |
2 ms |
4956 KB |
Output is correct |
7 |
Correct |
2 ms |
4952 KB |
Output is correct |
8 |
Correct |
2 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4952 KB |
Output is correct |
13 |
Correct |
3 ms |
4956 KB |
Output is correct |
14 |
Correct |
3 ms |
4956 KB |
Output is correct |
15 |
Correct |
3 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4952 KB |
Output is correct |
18 |
Correct |
3 ms |
4956 KB |
Output is correct |
19 |
Correct |
34 ms |
5208 KB |
Output is correct |
20 |
Correct |
5 ms |
5208 KB |
Output is correct |
21 |
Correct |
32 ms |
5232 KB |
Output is correct |
22 |
Correct |
3 ms |
5212 KB |
Output is correct |
23 |
Correct |
3 ms |
5212 KB |
Output is correct |
24 |
Correct |
2 ms |
5212 KB |
Output is correct |
25 |
Correct |
6 ms |
5208 KB |
Output is correct |
26 |
Execution timed out |
1092 ms |
5468 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |