#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll int, ll int>
#define ff first
#define ss second
#define pb push_back
vector<int> x, y, w;
int n, m;
ll int st1() {
ll int ans = 0;
for (int &cur : w) ans += cur;
return ans;
}
ll int st2() {
ll int fin[n][2], ps[n][2];
for (int i = 0; i < n; i++) {
fin[i][0] = 0;
fin[i][1] = 0;
}
for (int i = 0; i < m; i++) {
fin[y[i]][x[i]] = w[i];
}
if (n == 2) {
return max({fin[0][0] + fin[1][0], fin[0][1] + fin[1][1]});
}
ps[0][0] = fin[0][0];
ps[0][1] = fin[0][1];
for (int i = 1; i < n; i++) {
ps[i][0] = ps[i - 1][0] + fin[i][0];
ps[i][1] = ps[i - 1][1] + fin[i][1];
}
ll int ans = max(ps[n - 1][0], ps[n - 1][1]);
for (int stop = 0; stop < n; stop++) {
ans = max(ans, ps[stop][0] + (ps[n - 1][1] - ps[stop][1]));
}
return ans;
}
ll int st3() {
ll int a[n + 1];
for (int i = 0; i <= n; i++) a[i] = 0;
for (int i = 0; i < m; i++) a[x[i] + 1] = w[i];
ll int dp[n + 1][4];
dp[2][0] = 0;
dp[2][1] = a[1];
dp[2][2] = a[2];
dp[2][3] = 0;
for (int i = 3; i <= n; i++) {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][2]);
dp[i][1] = max(dp[i - 1][0] + a[i - 1], dp[i - 1][2]);
dp[i][2] = max(dp[i - 1][1] + a[i], dp[i - 1][3] + a[i]);
dp[i][3] = max(dp[i - 1][1], dp[i - 1][3]);
}
ll int ans = 0;
ans = max(max(dp[n][0], dp[n][1]), max(dp[n][2], dp[n][3]));
return ans;
}
const ll int MIN = -1e16;
ll int st4() {
ll int a[n + 1][n + 1], ps[n + 1][n + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
a[i][j] = 0;
}
}
for (int i = 0; i < m; i++) {
a[x[i] + 1][y[i] + 1] = w[i];
}
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= n; j++) {
// cout << a[i][j] << ' ';
// }
// cout << endl;
// }
for (int i = 1; i <= n; i++) {
ps[i][0] = 0;
for (int j = 1; j <= n; j++) {
ps[i][j] = ps[i][j - 1] + a[i][j];
}
}
ll int dp[n + 1][11][11];
ll int cur;
for (int i = 0; i <= 10; i++) {
for (int j = 0; j <= 10; j++) {
if (i == j) dp[1][i][j] = 0;
else dp[1][i][j] = MIN;
}
}
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= 10; j++) {
for (int k = 0; k <= 10; k++) {
dp[i][j][k] = MIN;
}
}
for (int j = 0; j <= 10; j++) {
for (int k = j; k <= 10; k++) {
for (int l = 0; l <= 10; l++) {
int cover = max(j, l);
cur = dp[i - 1][j][k];
if (l > k) {
cur += ps[i - 1][l] - ps[i - 1][k];
} else if (j > l) {
cur += ps[i][j] - ps[i][l];
}
dp[i][l][cover] = max(dp[i][l][cover], cur);
}
}
}
}
ll int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 10; j++) {
for (int k = 0; k <= 10; k++) {
ans = max(ans, dp[i][j][k]);
}
}
}
return ans;
}
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N; m = M;
x = X; y = Y; w = W;
bool isst4 = (n <= 300);
bool isst3 = true;
for (int &cur : Y) {
isst4 &= (cur <= 8);
isst3 &= (cur == 0);
}
if (isst3) return st3();
bool isst1 = true, isst2 = true;
for (int &cur : X) {
if ((cur & 1) != (X[0] & 1)) {
isst1 = false;
}
if (cur > 1) {
isst2 = false;
}
}
if (isst2) return st2();
if (isst1) return st1();
if (isst4) return st4();
throw runtime_error("wrong");
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5860 KB |
Output is correct |
2 |
Correct |
30 ms |
6892 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
3416 KB |
Output is correct |
5 |
Correct |
92 ms |
10864 KB |
Output is correct |
6 |
Correct |
87 ms |
10852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
47 ms |
8736 KB |
Output is correct |
3 |
Correct |
56 ms |
10464 KB |
Output is correct |
4 |
Correct |
23 ms |
5864 KB |
Output is correct |
5 |
Correct |
31 ms |
6856 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 |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
26 ms |
6004 KB |
Output is correct |
13 |
Correct |
28 ms |
6864 KB |
Output is correct |
14 |
Correct |
25 ms |
5964 KB |
Output is correct |
15 |
Correct |
30 ms |
6592 KB |
Output is correct |
16 |
Correct |
25 ms |
5964 KB |
Output is correct |
17 |
Correct |
26 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
15 ms |
5716 KB |
Output is correct |
4 |
Correct |
11 ms |
5480 KB |
Output is correct |
5 |
Correct |
27 ms |
7680 KB |
Output is correct |
6 |
Correct |
28 ms |
7636 KB |
Output is correct |
7 |
Correct |
26 ms |
7624 KB |
Output is correct |
8 |
Correct |
35 ms |
7620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
2 ms |
2004 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
2004 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
2004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
2 ms |
2004 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
2004 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
2004 KB |
Output is correct |
15 |
Runtime error |
2 ms |
508 KB |
Execution killed with signal 6 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
2 ms |
2004 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
2004 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
3 ms |
2004 KB |
Output is correct |
15 |
Runtime error |
2 ms |
508 KB |
Execution killed with signal 6 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
15 ms |
5716 KB |
Output is correct |
4 |
Correct |
11 ms |
5480 KB |
Output is correct |
5 |
Correct |
27 ms |
7680 KB |
Output is correct |
6 |
Correct |
28 ms |
7636 KB |
Output is correct |
7 |
Correct |
26 ms |
7624 KB |
Output is correct |
8 |
Correct |
35 ms |
7620 KB |
Output is correct |
9 |
Runtime error |
38 ms |
7620 KB |
Execution killed with signal 6 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5860 KB |
Output is correct |
2 |
Correct |
30 ms |
6892 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
3416 KB |
Output is correct |
5 |
Correct |
92 ms |
10864 KB |
Output is correct |
6 |
Correct |
87 ms |
10852 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
47 ms |
8736 KB |
Output is correct |
9 |
Correct |
56 ms |
10464 KB |
Output is correct |
10 |
Correct |
23 ms |
5864 KB |
Output is correct |
11 |
Correct |
31 ms |
6856 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
26 ms |
6004 KB |
Output is correct |
19 |
Correct |
28 ms |
6864 KB |
Output is correct |
20 |
Correct |
25 ms |
5964 KB |
Output is correct |
21 |
Correct |
30 ms |
6592 KB |
Output is correct |
22 |
Correct |
25 ms |
5964 KB |
Output is correct |
23 |
Correct |
26 ms |
6480 KB |
Output is correct |
24 |
Correct |
3 ms |
4180 KB |
Output is correct |
25 |
Correct |
2 ms |
4180 KB |
Output is correct |
26 |
Correct |
15 ms |
5716 KB |
Output is correct |
27 |
Correct |
11 ms |
5480 KB |
Output is correct |
28 |
Correct |
27 ms |
7680 KB |
Output is correct |
29 |
Correct |
28 ms |
7636 KB |
Output is correct |
30 |
Correct |
26 ms |
7624 KB |
Output is correct |
31 |
Correct |
35 ms |
7620 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
724 KB |
Output is correct |
41 |
Correct |
2 ms |
2004 KB |
Output is correct |
42 |
Correct |
1 ms |
724 KB |
Output is correct |
43 |
Correct |
2 ms |
2004 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
3 ms |
2004 KB |
Output is correct |
46 |
Runtime error |
2 ms |
508 KB |
Execution killed with signal 6 |
47 |
Halted |
0 ms |
0 KB |
- |