#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, x, y, k;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> k) {
vector< vector<ll> > v(n, vector<ll>(n));
int mx = 0;
for (int i = 0; i < m; i++) {
v[x[i]][y[i]] += k[i];
mx = max(mx, y[i]);
}
mx++;
mx++;
// cout << "DEBUG" << endl;
vector< vector< vector< vector<ll> > > > dp(n, vector< vector< vector<ll> > > (mx, vector< vector<ll> > (mx, vector<ll>(mx))));
for (int i = 0; i < mx; i++) {
for (int j = 0; j < mx; j++) {
for (int i1 = i; i1 < j; i1++) {
// cout << mx << ' ' << i << ' ' << j << ' ' << i1 << endl;
dp[0][0][i][j] += v[0][i1];
}
// cout << dp[0][0][i][j] << endl;
}
}
// cout << "DEBUG" << endl;
ll ans = 0;
for (int x = 1; x < n; x++) {
for (int i = 0; i < mx; i++) {
for (int j = 0; j < mx; j++) {
ll mx1 = 0;
for (int k = 0; k < mx; k++) {
mx1 = max(mx1, dp[x - 1][k][i][j]);
}
for (int k = 0; k < (x == n - 1 ? 1 : mx); k++) {
dp[x][i][j][k] = mx1;
// if (x == 1 && i == 0 && j == 3 && k == 5) {
// cout << mx1 << endl;
// }
for (int i1 = j; i1 < max(i, k); i1++) {
dp[x][i][j][k] += v[x][i1];
}
if (x == n - 1) {
ans = max(ans, dp[x][i][j][k]);
}
}
}
}
}
// cout << endl;
// cout << dp[0][0][0][3] << endl;
// cout << dp[1][0][3][5] << endl;
// cout << dp[2][3][5][0] << endl;
// cout << dp[3][5][0][4] << endl;
// cout << dp[4][0][4][0] << endl;
return ans;
}
//void solve() {
// cin >> n >> m;
// vector<int> x(m);
// vector<int> y(m);
// vector<int> k(m);
// for (int i = 0; i < m; i++) {
// cin >> x[i] >> y[i] >> k[i];
// }
// cout << max_weights(n, m, x, y, k) << '\n';
//}
//
//int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
// solve();
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
746 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
750 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
718 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
3540 KB |
Output is correct |
11 |
Correct |
3 ms |
1748 KB |
Output is correct |
12 |
Correct |
5 ms |
3540 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
3540 KB |
Output is correct |
11 |
Correct |
3 ms |
1748 KB |
Output is correct |
12 |
Correct |
5 ms |
3540 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
2260 KB |
Output is correct |
15 |
Runtime error |
896 ms |
2097152 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
724 KB |
Output is correct |
10 |
Correct |
5 ms |
3540 KB |
Output is correct |
11 |
Correct |
3 ms |
1748 KB |
Output is correct |
12 |
Correct |
5 ms |
3540 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
2260 KB |
Output is correct |
15 |
Runtime error |
896 ms |
2097152 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
718 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
746 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |