#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
int mask = 0, mx = 0;
for(int i=0; i<M; i++) mask |= (1 << (X[i] % 2));
for(int i=0; i<M; i++) mx = max(mx, Y[i]);
if(mask == 1) {
ll ans = 0;
for(int &x : W) ans += x;
return ans;
}
if(mx == 0) {
vector<ll> val(N+5), dp(N+5);
for(int i=0; i<M; i++) val[X[i]] = W[i];
ll ans = 0;
vector<ll> MX(N+5); MX[0] = val[1];
for(int i=1; i<N; i++) {
dp[i] = max(dp[i-1], val[i-1]);
if(i >= 3) dp[i] = max(dp[i], MX[i-3] + val[i-1]);
if(i >= 2) dp[i] = max(dp[i], dp[i-2] + val[i-1]);
MX[i] = max(MX[i-1], dp[i] + val[i+1]);
}
for(int i=0; i<N; i++) ans = max(ans, dp[i] + val[i+1]);
return ans;
}
if(mx <= 8) {
vector<vector<ll> > val(N+5, vector<ll>(mx+1));
vector<vector<ll> > dp(N+5, vector<ll>(mx+1));
for(int i=0; i<M; i++) val[X[i]][Y[i]] = W[i];
for(int i=0; i<N; i++)
for(int j=1; j<=mx; j++) val[i][j] += val[i][j-1];
//dp here, gl&hf
for(int i=1; i<N; i++) {
for(int j=0; j<=mx; j++) {
dp[i][j] = val[i-1][j];
// //i-1
// if(i >= 2) {
// }
//i-2
if(i >= 2) for(int k=0; k<=mx; k++) dp[i][j] = max(dp[i][j], dp[i-2][k] + max(val[i-1][j], val[i-1][k]));
//<=i-3
for(int k=i-3; k>=0; k--)
for(int l=0; l<=mx; l++) dp[i][j] = max(dp[i][j], dp[k][l] + val[k+1][l] + val[i-1][j]);
}
}
ll ans = 0;
for(int i=0; i<N; i++)
for(int j=0; j<=mx; j++) ans = max(ans, dp[i][j] + val[i+1][j]);
return ans;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2136 KB |
Output is correct |
2 |
Correct |
14 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
50 ms |
7288 KB |
Output is correct |
6 |
Correct |
45 ms |
7252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
8 ms |
3672 KB |
Output is correct |
4 |
Correct |
10 ms |
3420 KB |
Output is correct |
5 |
Correct |
14 ms |
4956 KB |
Output is correct |
6 |
Correct |
12 ms |
4952 KB |
Output is correct |
7 |
Correct |
14 ms |
4952 KB |
Output is correct |
8 |
Correct |
14 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
8 ms |
3672 KB |
Output is correct |
4 |
Correct |
10 ms |
3420 KB |
Output is correct |
5 |
Correct |
14 ms |
4956 KB |
Output is correct |
6 |
Correct |
12 ms |
4952 KB |
Output is correct |
7 |
Correct |
14 ms |
4952 KB |
Output is correct |
8 |
Correct |
14 ms |
4952 KB |
Output is correct |
9 |
Incorrect |
12 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '99999', found: '0' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2136 KB |
Output is correct |
2 |
Correct |
14 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
50 ms |
7288 KB |
Output is correct |
6 |
Correct |
45 ms |
7252 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
8 |
Halted |
0 ms |
0 KB |
- |