#include <bits/stdc++.h>
using namespace std;
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)
template <class U, class V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <class U, class V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }
const int MAXN = 1e5 + 5;
namespace sub1 {
bool check(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
REP(i, M) if(X[i] % 2 == 1) return false;
return true;
}
long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
long long ans = 0;
REP(i, M) ans += W[i];
return ans;
}
}
namespace sub2 {
long long pre[2][MAXN];
bool check(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
REP(i, M) if(X[i] > 1) return false;
return true;
}
long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
long long ans = 0;
REP(i, M) pre[X[i]][Y[i]] += W[i];
FOR(i, 1, N - 1) {
pre[0][i] += pre[0][i - 1];
pre[1][i] += pre[1][i - 1];
}
ans = max(pre[0][N - 1], pre[1][N - 1]);
if(N == 2) return ans;
REP(i, N) {
long long val = pre[1][N - 1] - pre[1][i];
maximize(ans, val + pre[0][i]);
}
return ans;
}
}
namespace sub3 {
bool check (int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
REP(i, M) if(Y[i]) return false;
return true;
}
long long dp[MAXN][2][2], a[MAXN];
long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
long long ans = 0;
REP(i, M) a[X[i] + 1] += W[i];
FOR(i, 1, N) {
dp[i][1][0] = max({dp[i - 1][0][0] + a[i - 1] + a[i + 1], dp[i - 1][0][1] + a[i + 1], dp[i - 1][1][0] - a[i] + a[i + 1]});
dp[i][0][0] = max(dp[i - 1][0][0], dp[i - 1][0][1]);
dp[i][0][1] = dp[i - 1][1][0];
maximize(ans, dp[i][1][0]);
maximize(ans, dp[i][0][0]);
maximize(ans, dp[i][0][1]);
// cout << dp[i][1][0] << " \n"[i == N];
}
return ans;
}
}
namespace sub4 {
bool check (int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
if(N > 300) return false;
REP(i, M) if(Y[i] > 8) return false;
return true;
}
long long dp[MAXN][10][10], pre[MAXN][10];
long long get(int x, int l, int r) { if(l > r) return 0; return pre[x][r] - pre[x][l - 1]; }
long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
long long ans = 0;
int lim = min(9, N + 1);
REP(i, M) pre[X[i] + 1][Y[i] + 1] += W[i];
FOR(i, 1, N) FOR(j, 1, lim - 1) pre[i][j] += pre[i][j - 1];
FOR(i, 2, N) REP(l1, lim) REP(l2, lim) REP(l3, lim) {
long long val = 0, val2 = 0;
if(l2 < l3) val = get(i - 1, l2 + 1, l3);
else val = get(i, l3 + 1, l2);
if(l1 > l2 && l2 < l3) {
if(l1 < l3) maximize(dp[i][l2][l3], dp[i - 1][l1][l2] + get(i - 1, l1 + 1, l3));
else maximize(dp[i][l2][l3], dp[i - 1][l1][l2]);
}
else maximize(dp[i][l2][l3], dp[i - 1][l1][l2] + val);
maximize(ans, dp[i][l2][l3]);
}
return ans;
}
}
namespace sub5 {
const int MAX = 305;
long long dp[MAX][MAX][MAX], Max[3][MAX][MAX][MAX];
long long pre[MAX][MAX];
long long get(int i, int l, int r) { if(r < l) return 0; return pre[i][r] - pre[i][l - 1]; }
long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
long long ans = 0;
memset(Max, -0x3f, sizeof Max);
REP(i, M) pre[X[i] + 1][Y[i] + 1] += W[i];
FOR(i, 1, N) FOR(j, 1, N) pre[i][j] += pre[i][j - 1];
REP(i, 3) memset(Max[i][1], 0, sizeof Max[i][1]);
FOR(i, 2, N) {
REP(l1, N + 1) REP(l2, N + 1) {
if(l1 < l2) dp[i][l1][l2] = Max[0][i - 1][l1][l1] + get(i - 1, l1 + 1, l2);
else dp[i][l1][l2] = Max[0][i - 1][N][l1] + get(i, l2 + 1, l1);
if(l1 < l2) {
maximize(dp[i][l1][l2], Max[1][i - 1][l2][l1]);
maximize(dp[i][l1][l2], Max[2][i - 1][l2][l1] + get(i - 1, 1, l2));
}
maximize(ans, dp[i][l1][l2]);
maximize(Max[0][i][l1][l2], dp[i][l1][l2]);
maximize(Max[2][i][l1][l2], dp[i][l1][l2] - get(i, 1, max(l1, l2)));
if(l1 > 0) {
maximize(Max[0][i][l1][l2], Max[0][i][l1 - 1][l2]);
maximize(Max[2][i][l1][l2], Max[2][i][l1 - 1][l2]);
}
}
FORD(l1, N, 0) FORD(l2, l1, 0) {
maximize(Max[1][i][l1][l2], dp[i][l1][l2]);
if(l1 < N) maximize(Max[1][i][l1][l2], Max[1][i][l1 + 1][l2]);
}
}
// cout << dp[5][0][4] << '\n';
// cout << Max[2][2][5][3] << '\n';
return ans;
}
}
long long max_weights(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
if(N <= 300) return sub5::Main(N, M, X, Y, W);
if(sub1::check(N, M, X, Y, W)) return sub1::Main(N, M, X, Y, W);
if(sub2::check(N, M, X, Y, W)) return sub2::Main(N, M, X, Y, W);
if(sub3::check(N, M, X, Y, W)) return sub3::Main(N, M, X, Y, W);
if(sub4::check(N, M, X, Y, W)) return sub4::Main(N, M, X, Y, W);
return 0;
}
Compilation message
fish.cpp: In function 'long long int sub4::Main(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:85:32: warning: unused variable 'val2' [-Wunused-variable]
85 | long long val = 0, val2 = 0;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
4520 KB |
Output is correct |
2 |
Correct |
33 ms |
5572 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
105 ms |
15692 KB |
Output is correct |
6 |
Correct |
116 ms |
15780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
262 ms |
666512 KB |
Output is correct |
2 |
Correct |
54 ms |
10172 KB |
Output is correct |
3 |
Correct |
74 ms |
12288 KB |
Output is correct |
4 |
Correct |
24 ms |
4548 KB |
Output is correct |
5 |
Correct |
28 ms |
5520 KB |
Output is correct |
6 |
Correct |
273 ms |
666644 KB |
Output is correct |
7 |
Correct |
240 ms |
666652 KB |
Output is correct |
8 |
Correct |
263 ms |
666520 KB |
Output is correct |
9 |
Correct |
243 ms |
666580 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
28 ms |
5888 KB |
Output is correct |
13 |
Correct |
32 ms |
7068 KB |
Output is correct |
14 |
Correct |
34 ms |
5920 KB |
Output is correct |
15 |
Correct |
29 ms |
6624 KB |
Output is correct |
16 |
Correct |
26 ms |
5872 KB |
Output is correct |
17 |
Correct |
28 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
18 ms |
6656 KB |
Output is correct |
4 |
Correct |
12 ms |
5748 KB |
Output is correct |
5 |
Correct |
31 ms |
9348 KB |
Output is correct |
6 |
Correct |
34 ms |
8728 KB |
Output is correct |
7 |
Correct |
30 ms |
9228 KB |
Output is correct |
8 |
Correct |
39 ms |
9260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
666636 KB |
Output is correct |
2 |
Correct |
239 ms |
666700 KB |
Output is correct |
3 |
Correct |
274 ms |
666756 KB |
Output is correct |
4 |
Correct |
263 ms |
666596 KB |
Output is correct |
5 |
Correct |
244 ms |
666580 KB |
Output is correct |
6 |
Correct |
242 ms |
666568 KB |
Output is correct |
7 |
Correct |
246 ms |
666528 KB |
Output is correct |
8 |
Correct |
266 ms |
666604 KB |
Output is correct |
9 |
Correct |
304 ms |
721240 KB |
Output is correct |
10 |
Correct |
495 ms |
883632 KB |
Output is correct |
11 |
Correct |
288 ms |
721104 KB |
Output is correct |
12 |
Correct |
496 ms |
883636 KB |
Output is correct |
13 |
Correct |
244 ms |
680456 KB |
Output is correct |
14 |
Correct |
458 ms |
883392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
666636 KB |
Output is correct |
2 |
Correct |
239 ms |
666700 KB |
Output is correct |
3 |
Correct |
274 ms |
666756 KB |
Output is correct |
4 |
Correct |
263 ms |
666596 KB |
Output is correct |
5 |
Correct |
244 ms |
666580 KB |
Output is correct |
6 |
Correct |
242 ms |
666568 KB |
Output is correct |
7 |
Correct |
246 ms |
666528 KB |
Output is correct |
8 |
Correct |
266 ms |
666604 KB |
Output is correct |
9 |
Correct |
304 ms |
721240 KB |
Output is correct |
10 |
Correct |
495 ms |
883632 KB |
Output is correct |
11 |
Correct |
288 ms |
721104 KB |
Output is correct |
12 |
Correct |
496 ms |
883636 KB |
Output is correct |
13 |
Correct |
244 ms |
680456 KB |
Output is correct |
14 |
Correct |
458 ms |
883392 KB |
Output is correct |
15 |
Correct |
478 ms |
883344 KB |
Output is correct |
16 |
Correct |
267 ms |
680492 KB |
Output is correct |
17 |
Correct |
490 ms |
885104 KB |
Output is correct |
18 |
Correct |
481 ms |
885016 KB |
Output is correct |
19 |
Correct |
494 ms |
885084 KB |
Output is correct |
20 |
Correct |
521 ms |
884928 KB |
Output is correct |
21 |
Correct |
517 ms |
884996 KB |
Output is correct |
22 |
Correct |
509 ms |
886528 KB |
Output is correct |
23 |
Correct |
478 ms |
883544 KB |
Output is correct |
24 |
Correct |
488 ms |
884308 KB |
Output is correct |
25 |
Correct |
467 ms |
883348 KB |
Output is correct |
26 |
Correct |
477 ms |
883552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
666636 KB |
Output is correct |
2 |
Correct |
239 ms |
666700 KB |
Output is correct |
3 |
Correct |
274 ms |
666756 KB |
Output is correct |
4 |
Correct |
263 ms |
666596 KB |
Output is correct |
5 |
Correct |
244 ms |
666580 KB |
Output is correct |
6 |
Correct |
242 ms |
666568 KB |
Output is correct |
7 |
Correct |
246 ms |
666528 KB |
Output is correct |
8 |
Correct |
266 ms |
666604 KB |
Output is correct |
9 |
Correct |
304 ms |
721240 KB |
Output is correct |
10 |
Correct |
495 ms |
883632 KB |
Output is correct |
11 |
Correct |
288 ms |
721104 KB |
Output is correct |
12 |
Correct |
496 ms |
883636 KB |
Output is correct |
13 |
Correct |
244 ms |
680456 KB |
Output is correct |
14 |
Correct |
458 ms |
883392 KB |
Output is correct |
15 |
Correct |
478 ms |
883344 KB |
Output is correct |
16 |
Correct |
267 ms |
680492 KB |
Output is correct |
17 |
Correct |
490 ms |
885104 KB |
Output is correct |
18 |
Correct |
481 ms |
885016 KB |
Output is correct |
19 |
Correct |
494 ms |
885084 KB |
Output is correct |
20 |
Correct |
521 ms |
884928 KB |
Output is correct |
21 |
Correct |
517 ms |
884996 KB |
Output is correct |
22 |
Correct |
509 ms |
886528 KB |
Output is correct |
23 |
Correct |
478 ms |
883544 KB |
Output is correct |
24 |
Correct |
488 ms |
884308 KB |
Output is correct |
25 |
Correct |
467 ms |
883348 KB |
Output is correct |
26 |
Correct |
477 ms |
883552 KB |
Output is correct |
27 |
Incorrect |
1 ms |
340 KB |
1st lines differ - on the 1st token, expected: '2999', found: '0' |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
18 ms |
6656 KB |
Output is correct |
4 |
Correct |
12 ms |
5748 KB |
Output is correct |
5 |
Correct |
31 ms |
9348 KB |
Output is correct |
6 |
Correct |
34 ms |
8728 KB |
Output is correct |
7 |
Correct |
30 ms |
9228 KB |
Output is correct |
8 |
Correct |
39 ms |
9260 KB |
Output is correct |
9 |
Incorrect |
26 ms |
3812 KB |
1st lines differ - on the 1st token, expected: '99999', found: '0' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
4520 KB |
Output is correct |
2 |
Correct |
33 ms |
5572 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
105 ms |
15692 KB |
Output is correct |
6 |
Correct |
116 ms |
15780 KB |
Output is correct |
7 |
Correct |
262 ms |
666512 KB |
Output is correct |
8 |
Correct |
54 ms |
10172 KB |
Output is correct |
9 |
Correct |
74 ms |
12288 KB |
Output is correct |
10 |
Correct |
24 ms |
4548 KB |
Output is correct |
11 |
Correct |
28 ms |
5520 KB |
Output is correct |
12 |
Correct |
273 ms |
666644 KB |
Output is correct |
13 |
Correct |
240 ms |
666652 KB |
Output is correct |
14 |
Correct |
263 ms |
666520 KB |
Output is correct |
15 |
Correct |
243 ms |
666580 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
28 ms |
5888 KB |
Output is correct |
19 |
Correct |
32 ms |
7068 KB |
Output is correct |
20 |
Correct |
34 ms |
5920 KB |
Output is correct |
21 |
Correct |
29 ms |
6624 KB |
Output is correct |
22 |
Correct |
26 ms |
5872 KB |
Output is correct |
23 |
Correct |
28 ms |
6488 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
18 ms |
6656 KB |
Output is correct |
27 |
Correct |
12 ms |
5748 KB |
Output is correct |
28 |
Correct |
31 ms |
9348 KB |
Output is correct |
29 |
Correct |
34 ms |
8728 KB |
Output is correct |
30 |
Correct |
30 ms |
9228 KB |
Output is correct |
31 |
Correct |
39 ms |
9260 KB |
Output is correct |
32 |
Correct |
245 ms |
666636 KB |
Output is correct |
33 |
Correct |
239 ms |
666700 KB |
Output is correct |
34 |
Correct |
274 ms |
666756 KB |
Output is correct |
35 |
Correct |
263 ms |
666596 KB |
Output is correct |
36 |
Correct |
244 ms |
666580 KB |
Output is correct |
37 |
Correct |
242 ms |
666568 KB |
Output is correct |
38 |
Correct |
246 ms |
666528 KB |
Output is correct |
39 |
Correct |
266 ms |
666604 KB |
Output is correct |
40 |
Correct |
304 ms |
721240 KB |
Output is correct |
41 |
Correct |
495 ms |
883632 KB |
Output is correct |
42 |
Correct |
288 ms |
721104 KB |
Output is correct |
43 |
Correct |
496 ms |
883636 KB |
Output is correct |
44 |
Correct |
244 ms |
680456 KB |
Output is correct |
45 |
Correct |
458 ms |
883392 KB |
Output is correct |
46 |
Correct |
478 ms |
883344 KB |
Output is correct |
47 |
Correct |
267 ms |
680492 KB |
Output is correct |
48 |
Correct |
490 ms |
885104 KB |
Output is correct |
49 |
Correct |
481 ms |
885016 KB |
Output is correct |
50 |
Correct |
494 ms |
885084 KB |
Output is correct |
51 |
Correct |
521 ms |
884928 KB |
Output is correct |
52 |
Correct |
517 ms |
884996 KB |
Output is correct |
53 |
Correct |
509 ms |
886528 KB |
Output is correct |
54 |
Correct |
478 ms |
883544 KB |
Output is correct |
55 |
Correct |
488 ms |
884308 KB |
Output is correct |
56 |
Correct |
467 ms |
883348 KB |
Output is correct |
57 |
Correct |
477 ms |
883552 KB |
Output is correct |
58 |
Incorrect |
1 ms |
340 KB |
1st lines differ - on the 1st token, expected: '2999', found: '0' |
59 |
Halted |
0 ms |
0 KB |
- |