#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 500;
int dp1[MAXN], dp2[MAXN],dp3[MAXN];
long long query(int ty, int l, int r){
if (l>r) return 0;
long long hh = 0;
if (ty==2){
hh = dp2[r];
if (l) hh-=dp2[l-1];
}
else if (ty==3){
hh = dp3[r];
if (l) hh-=dp3[l-1];
}
else {
hh = dp1[r];
if (l) hh-=dp1[l-1];
}
return hh;
}
long long calc(int al, int ar, int bl, int br){
if (max(al,bl)<=min(ar,br)){
long long ret = query(3,max(al,bl),min(ar,br));
ret+=query(1,al,max(al,bl)-1);
ret+=query(1,min(ar,br)+1,ar);
ret+=query(2,bl,max(al,bl)-1);
ret+=query(2,min(ar,br)+1,br);
return ret;
}
else {
return query(1,al,ar)+query(2,bl,br);
}
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
dp1[X]=0,dp2[Y]=0;
long long cur = 0;
for (int i = X-1; i >= 0; i--){
cur+=W[i];
dp1[i]=cur;
}
cur=0;
for (int i = X+1; i < N; i++){
cur+=W[i-1];
dp1[i]=cur;
}
cur = 0;
for (int i = Y-1; i >= 0; i--){
cur+=W[i];
dp2[i]=cur;
}
cur=0;
for (int i = Y+1; i < N; i++){
cur+=W[i-1];
dp2[i]=cur;
}
for (int i = 0; i < N; i++){
dp3[i]=max(dp1[i],dp2[i]);
if (i) dp3[i]+=dp3[i-1];
if (i) dp2[i]+=dp2[i-1];
if (i) dp1[i]+=dp1[i-1];
}
int ans = 0;
for (int al = 0; al <= X; al++){
for (int ar = X; ar < N; ar++){
for (int bl = 0; bl <= Y; bl++){
if (calc(al,ar,bl,Y)>K) continue;
int l = Y, r = N-1;
while (l<r){
int mid = l+(r-l+1)/2;
if (calc(al,ar,bl,mid)>K){
r=mid-1;
}
else l=mid;
}
ans=max(ans,ar-al+1+l-bl+1);
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
69 ms |
10064 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '18', found: '198' |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '18', found: '198' |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |