#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 302;
int n;
int a[N][N];
int pref[N][N];
int max_m, max_n;
long long dp[N][N][N];
long long bt(int col, int last, int last2) {
if (col > n) {
return 0;
}
long long& ret = dp[col][last][last2];
if (ret != -1) {
return ret;
}
long long sum = 0;
long long ps = pref[col][last];
for (int nlast = 0; nlast <= n; ++nlast) {
if (nlast > last2 && nlast > last) sum += a[col - 1][nlast];
if (nlast <= last) ps -= a[col][nlast];
if (sum) assert(ps == 0);
ret = max(ret, bt(col + 1, nlast, last) + sum + ps);
}
return ret;
}
long long max_weights(int N_, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N_;
for (int i = 0; i < M; ++i) {
max_m = max(max_m, X[i] + 1);
max_n = max(max_n, Y[i] + 1);
a[X[i] + 1][Y[i] + 1] = W[i];
}
for (int i = 1; i <= max_m; ++i) {
for (int j = 1; j <= max_n; ++j) {
pref[i][j] = pref[i][j - 1] + a[i][j];
}
}
memset(dp, -1, sizeof dp);
return bt(1, 0, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
279 ms |
442812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
215876 KB |
Output is correct |
2 |
Runtime error |
283 ms |
449532 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
252 ms |
437584 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
215888 KB |
Output is correct |
2 |
Correct |
73 ms |
215824 KB |
Output is correct |
3 |
Correct |
71 ms |
215836 KB |
Output is correct |
4 |
Correct |
84 ms |
215876 KB |
Output is correct |
5 |
Correct |
86 ms |
215856 KB |
Output is correct |
6 |
Correct |
78 ms |
215908 KB |
Output is correct |
7 |
Correct |
75 ms |
215888 KB |
Output is correct |
8 |
Correct |
77 ms |
215792 KB |
Output is correct |
9 |
Runtime error |
279 ms |
438376 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
215888 KB |
Output is correct |
2 |
Correct |
73 ms |
215824 KB |
Output is correct |
3 |
Correct |
71 ms |
215836 KB |
Output is correct |
4 |
Correct |
84 ms |
215876 KB |
Output is correct |
5 |
Correct |
86 ms |
215856 KB |
Output is correct |
6 |
Correct |
78 ms |
215908 KB |
Output is correct |
7 |
Correct |
75 ms |
215888 KB |
Output is correct |
8 |
Correct |
77 ms |
215792 KB |
Output is correct |
9 |
Runtime error |
279 ms |
438376 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
215888 KB |
Output is correct |
2 |
Correct |
73 ms |
215824 KB |
Output is correct |
3 |
Correct |
71 ms |
215836 KB |
Output is correct |
4 |
Correct |
84 ms |
215876 KB |
Output is correct |
5 |
Correct |
86 ms |
215856 KB |
Output is correct |
6 |
Correct |
78 ms |
215908 KB |
Output is correct |
7 |
Correct |
75 ms |
215888 KB |
Output is correct |
8 |
Correct |
77 ms |
215792 KB |
Output is correct |
9 |
Runtime error |
279 ms |
438376 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
252 ms |
437584 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
279 ms |
442812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |