#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
long long max_weights(int n,int m,vector<int>x,vector<int>y,vector<int>w){
int mx = *max_element(y.begin(),y.end());
if(mx <= 8){
long long dp[n+1][mx+2][mx+2]{};
int sum[n+1][mx+2]{};
for(int i = 0; i < m; i++) x[i] += 1;
for(int i = 0; i < m; i++) y[i] += 1;
for(int i = 0; i < m; i++) sum[x[i]][y[i]] += w[i];
long long ans = 0;
for(int i = 0; i < 1; i++){
for(int j = 0; j < mx+2; j++){
for(int k = 0; k < mx+2; k++){
dp[i][j][k] = -1e18;
}
}
}
dp[0][0][0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < mx+2; j++){
for(int k = 0; k < mx+2; k++){
for(int v = 0; v < mx+2; v++){
long long now = dp[i-1][k][j];
int cur = v;
while(cur > max(j,k)) now += sum[i-1][cur--];
cur = k;
while(cur > v) now += sum[i][cur--];
dp[i][v][k] = max(dp[i][v][k],now);
ans = max(ans,now);
}
}
}
}
return ans;
}
mx = *max_element(x.begin(),x.end());
if(mx <= 1){
long long ans = 0;
long long ans2 = 0;
int cost[n][2]{};
for(int i = 0; i < m; i++){
if(x[i] == 1){cost[y[i]][1] = w[i]; ans += w[i];}
if(x[i] == 0){ans2 += w[i];cost[y[i]][0]=w[i];}
}
if(n == 2 || n == 1) return max(ans,ans2);
ans2 = max(ans,ans2);
for(int i = 1; i < n; i++){
ans -= cost[i-1][1];
ans += cost[i-1][0];
ans2 = max(ans2,ans);
}
return ans2;
}else{
long long sum = 0;
for(int i = 0; i < m; i++) sum += w[i];
return sum;
}
}
// int main(){
// cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3}) << '\n';
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2904 KB |
Output is correct |
2 |
Correct |
22 ms |
3420 KB |
Output is correct |
3 |
Correct |
7 ms |
4188 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
67 ms |
7288 KB |
Output is correct |
6 |
Correct |
72 ms |
7248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
36 ms |
4896 KB |
Output is correct |
3 |
Correct |
45 ms |
5896 KB |
Output is correct |
4 |
Correct |
23 ms |
2896 KB |
Output is correct |
5 |
Correct |
24 ms |
3412 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 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 |
5 ms |
4188 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
18 ms |
2936 KB |
Output is correct |
13 |
Correct |
24 ms |
3412 KB |
Output is correct |
14 |
Correct |
19 ms |
2908 KB |
Output is correct |
15 |
Correct |
21 ms |
3160 KB |
Output is correct |
16 |
Correct |
19 ms |
3160 KB |
Output is correct |
17 |
Correct |
22 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4188 KB |
Output is correct |
2 |
Correct |
5 ms |
4188 KB |
Output is correct |
3 |
Correct |
17 ms |
5176 KB |
Output is correct |
4 |
Correct |
13 ms |
5212 KB |
Output is correct |
5 |
Correct |
34 ms |
6492 KB |
Output is correct |
6 |
Correct |
24 ms |
6488 KB |
Output is correct |
7 |
Correct |
28 ms |
6492 KB |
Output is correct |
8 |
Correct |
27 ms |
6476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Incorrect |
1 ms |
492 KB |
1st lines differ - on the 1st token, expected: '741526820812', found: '1081125704581' |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Incorrect |
1 ms |
492 KB |
1st lines differ - on the 1st token, expected: '741526820812', found: '1081125704581' |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4188 KB |
Output is correct |
2 |
Correct |
5 ms |
4188 KB |
Output is correct |
3 |
Correct |
17 ms |
5176 KB |
Output is correct |
4 |
Correct |
13 ms |
5212 KB |
Output is correct |
5 |
Correct |
34 ms |
6492 KB |
Output is correct |
6 |
Correct |
24 ms |
6488 KB |
Output is correct |
7 |
Correct |
28 ms |
6492 KB |
Output is correct |
8 |
Correct |
27 ms |
6476 KB |
Output is correct |
9 |
Correct |
19 ms |
2652 KB |
Output is correct |
10 |
Correct |
30 ms |
8540 KB |
Output is correct |
11 |
Correct |
58 ms |
16720 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
4188 KB |
Output is correct |
19 |
Correct |
1 ms |
1112 KB |
Output is correct |
20 |
Correct |
5 ms |
4188 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Incorrect |
23 ms |
4672 KB |
1st lines differ - on the 1st token, expected: '45561826463480', found: '49789383639215' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2904 KB |
Output is correct |
2 |
Correct |
22 ms |
3420 KB |
Output is correct |
3 |
Correct |
7 ms |
4188 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
67 ms |
7288 KB |
Output is correct |
6 |
Correct |
72 ms |
7248 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
36 ms |
4896 KB |
Output is correct |
9 |
Correct |
45 ms |
5896 KB |
Output is correct |
10 |
Correct |
23 ms |
2896 KB |
Output is correct |
11 |
Correct |
24 ms |
3412 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
4188 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
18 ms |
2936 KB |
Output is correct |
19 |
Correct |
24 ms |
3412 KB |
Output is correct |
20 |
Correct |
19 ms |
2908 KB |
Output is correct |
21 |
Correct |
21 ms |
3160 KB |
Output is correct |
22 |
Correct |
19 ms |
3160 KB |
Output is correct |
23 |
Correct |
22 ms |
3164 KB |
Output is correct |
24 |
Correct |
5 ms |
4188 KB |
Output is correct |
25 |
Correct |
5 ms |
4188 KB |
Output is correct |
26 |
Correct |
17 ms |
5176 KB |
Output is correct |
27 |
Correct |
13 ms |
5212 KB |
Output is correct |
28 |
Correct |
34 ms |
6492 KB |
Output is correct |
29 |
Correct |
24 ms |
6488 KB |
Output is correct |
30 |
Correct |
28 ms |
6492 KB |
Output is correct |
31 |
Correct |
27 ms |
6476 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
2 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Incorrect |
1 ms |
492 KB |
1st lines differ - on the 1st token, expected: '741526820812', found: '1081125704581' |
48 |
Halted |
0 ms |
0 KB |
- |