#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mxn = 305;
ll n, m, w[mxn][mxn], ps[mxn][mxn], dp[2][mxn][mxn][mxn], mx, res = 0;
ll get(ll x, ll y, ll y2) {
return (y <= y2 ? ps[x][y2] - ps[x][y] : 0);
}
ll calc(ll p, ll h2, ll h1, ll h) {
return get(p, h1, max(h, h2));
}
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N, m = M;
for (int i = 0; i < m; i++) w[X[i] + 1][Y[i] + 1] = W[i];
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) ps[i][j] = ps[i][j - 1] + w[i][j];
if (n < 3) return max(ps[1][n], ps[2][n]);
for (int h = 0; h <= n; h++) for (int h1 = 0; h1 <= n; h1++) for (int h2 = 0; h2 <= n; h2++) dp[1][h2][h1][h] = calc(1, 0, h2, h1) + calc(2, h2, h1, h);
for (int i = 4; i <= n; i++) {
mx = 0;
for (int h1 = 0; h1 <= n; h1++) for (int h2 = 0; h2 <= n; h2++) for (int h3 = 0; h3 <= n; h3++) mx = max(mx, dp[1 - i % 2][h3][h2][h1]);
for (int h = 0; h <= n; h++) for (int h1 = 0; h1 <= n; h1++) for (int h2 = 0; h2 <= n; h2++) dp[i % 2][h2][h1][h] = max(dp[i % 2][h2][h1][h], mx + calc(i - 1, h2, h1, h));
}
for (int h = 0; h <= n; h++) for (int h1 = 0; h1 <= n; h1++) for (int h2 = 0; h2 <= n; h2++) res = max(res, dp[n % 2][h2][h1][h] + calc(n, h1, h, 0));
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
7140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
60 ms |
11000 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
1876 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Execution timed out |
1088 ms |
110916 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Execution timed out |
1088 ms |
110916 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Execution timed out |
1088 ms |
110916 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
1876 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
35 ms |
7140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |