#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 3e3 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
int n, m;
long long val[N][N], pref[N][N];
// dp[row_i][row_j][i - 1 > or = or <]
long long dp[N][N][2];
long long 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++){
val[_x[i] + 1][_y[i] + 1] += (long long)_w[i];
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++) pref[i][j] = pref[i][j - 1] + val[i][j];
}
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
dp[i][j][0] = dp[i][j][1] = -oo;
}
}
//dp[0][0][0] = 0;
//15206896898496
for(int i = 0; i <= n; i++){
//dp[2][i][0] = pref[1][i];// 0 -> <=
//dp[2][i][1] = pref[2][i;
dp[1][i][0] = 0;
}
for(int i = 2; i <= n + 1; i++){
// calculate (i - 1)
for(int lst = 0; lst <= n; lst++){
// 0 - 0
for(int nxt = lst; nxt <= n; nxt++){
dp[i][nxt][0] = max(dp[i][nxt][0], dp[i - 1][lst][0] + (pref[i - 1][nxt] - pref[i - 1][lst]));
}
// 1 - 1
for(int nxt = lst - 1; nxt >= 0; nxt--){
dp[i][nxt][1] = max(dp[i][nxt][1], dp[i - 1][lst][1] + pref[i][lst] - pref[i][nxt]);
}
// 0 - 1
if(lst == n){
for(int nxt = 0; nxt < n; nxt++) dp[i][nxt][1] = max(dp[i][nxt][1], dp[i - 1][n][0] + pref[i][n] - pref[i][nxt]);
}
// 1 - 0
if(!lst){
dp[i][0][0] = max(dp[i][0][0], dp[i - 1][0][1]);
for(int nxt = 1; nxt <= n; nxt++) dp[i][nxt][0] = max(dp[i][nxt][0], max(dp[i - 1][0][0] + pref[i - 1][nxt], dp[i - 1][0][1]));
}
}
}
return max(dp[n + 1][0][0], dp[n + 1][0][1]);
}
/*
void process(){
int n, m;
vector<int> a, b, c;
cin >> n >> m;
for(int i = 1; i <= m; i++){
int x, y, z;
cin >> x >> y >> z;
a.pb(x), b.pb(y), c.pb(z);
}
cout << max_weights(n, m, a, b, c) << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
//freopen("fish.inp", "r", stdin);
//freopen("fish.out", "w", stdout);
//cout << "OK\n";
//return 0;
process();
}
*/
Compilation message
fish.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
| ~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
878 ms |
150616 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Runtime error |
933 ms |
155984 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
933 ms |
143792 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
6 ms |
2620 KB |
Output is correct |
10 |
Correct |
35 ms |
6172 KB |
Output is correct |
11 |
Correct |
5 ms |
2620 KB |
Output is correct |
12 |
Correct |
32 ms |
6100 KB |
Output is correct |
13 |
Correct |
2 ms |
1236 KB |
Output is correct |
14 |
Correct |
45 ms |
6080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
6 ms |
2620 KB |
Output is correct |
10 |
Correct |
35 ms |
6172 KB |
Output is correct |
11 |
Correct |
5 ms |
2620 KB |
Output is correct |
12 |
Correct |
32 ms |
6100 KB |
Output is correct |
13 |
Correct |
2 ms |
1236 KB |
Output is correct |
14 |
Correct |
45 ms |
6080 KB |
Output is correct |
15 |
Correct |
35 ms |
6084 KB |
Output is correct |
16 |
Correct |
2 ms |
1256 KB |
Output is correct |
17 |
Correct |
45 ms |
7932 KB |
Output is correct |
18 |
Correct |
49 ms |
7764 KB |
Output is correct |
19 |
Correct |
49 ms |
8256 KB |
Output is correct |
20 |
Correct |
55 ms |
8244 KB |
Output is correct |
21 |
Correct |
47 ms |
8136 KB |
Output is correct |
22 |
Correct |
57 ms |
10316 KB |
Output is correct |
23 |
Correct |
36 ms |
6976 KB |
Output is correct |
24 |
Correct |
43 ms |
8012 KB |
Output is correct |
25 |
Correct |
37 ms |
6108 KB |
Output is correct |
26 |
Correct |
38 ms |
6704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
6 ms |
2620 KB |
Output is correct |
10 |
Correct |
35 ms |
6172 KB |
Output is correct |
11 |
Correct |
5 ms |
2620 KB |
Output is correct |
12 |
Correct |
32 ms |
6100 KB |
Output is correct |
13 |
Correct |
2 ms |
1236 KB |
Output is correct |
14 |
Correct |
45 ms |
6080 KB |
Output is correct |
15 |
Correct |
35 ms |
6084 KB |
Output is correct |
16 |
Correct |
2 ms |
1256 KB |
Output is correct |
17 |
Correct |
45 ms |
7932 KB |
Output is correct |
18 |
Correct |
49 ms |
7764 KB |
Output is correct |
19 |
Correct |
49 ms |
8256 KB |
Output is correct |
20 |
Correct |
55 ms |
8244 KB |
Output is correct |
21 |
Correct |
47 ms |
8136 KB |
Output is correct |
22 |
Correct |
57 ms |
10316 KB |
Output is correct |
23 |
Correct |
36 ms |
6976 KB |
Output is correct |
24 |
Correct |
43 ms |
8012 KB |
Output is correct |
25 |
Correct |
37 ms |
6108 KB |
Output is correct |
26 |
Correct |
38 ms |
6704 KB |
Output is correct |
27 |
Execution timed out |
1080 ms |
224176 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
933 ms |
143792 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
878 ms |
150616 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |