#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;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
4520 KB |
Output is correct |
2 |
Correct |
30 ms |
5564 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
89 ms |
17204 KB |
Output is correct |
6 |
Correct |
92 ms |
17516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
666576 KB |
Output is correct |
2 |
Correct |
50 ms |
10172 KB |
Output is correct |
3 |
Correct |
73 ms |
12304 KB |
Output is correct |
4 |
Correct |
23 ms |
4540 KB |
Output is correct |
5 |
Correct |
33 ms |
5568 KB |
Output is correct |
6 |
Correct |
254 ms |
666572 KB |
Output is correct |
7 |
Correct |
261 ms |
666480 KB |
Output is correct |
8 |
Correct |
245 ms |
666532 KB |
Output is correct |
9 |
Correct |
249 ms |
666536 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
24 ms |
5936 KB |
Output is correct |
13 |
Correct |
34 ms |
7072 KB |
Output is correct |
14 |
Correct |
26 ms |
5908 KB |
Output is correct |
15 |
Correct |
29 ms |
6596 KB |
Output is correct |
16 |
Correct |
26 ms |
5936 KB |
Output is correct |
17 |
Correct |
31 ms |
6504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
16 ms |
6652 KB |
Output is correct |
4 |
Correct |
13 ms |
5832 KB |
Output is correct |
5 |
Correct |
29 ms |
9372 KB |
Output is correct |
6 |
Correct |
36 ms |
8600 KB |
Output is correct |
7 |
Correct |
28 ms |
9252 KB |
Output is correct |
8 |
Correct |
30 ms |
9248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
267 ms |
666600 KB |
Output is correct |
2 |
Correct |
250 ms |
666712 KB |
Output is correct |
3 |
Correct |
274 ms |
666480 KB |
Output is correct |
4 |
Correct |
267 ms |
666552 KB |
Output is correct |
5 |
Correct |
246 ms |
666544 KB |
Output is correct |
6 |
Correct |
252 ms |
666580 KB |
Output is correct |
7 |
Correct |
260 ms |
666524 KB |
Output is correct |
8 |
Correct |
244 ms |
666704 KB |
Output is correct |
9 |
Correct |
288 ms |
721188 KB |
Output is correct |
10 |
Correct |
527 ms |
883500 KB |
Output is correct |
11 |
Correct |
297 ms |
721108 KB |
Output is correct |
12 |
Correct |
462 ms |
883524 KB |
Output is correct |
13 |
Correct |
275 ms |
680424 KB |
Output is correct |
14 |
Correct |
467 ms |
883316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
267 ms |
666600 KB |
Output is correct |
2 |
Correct |
250 ms |
666712 KB |
Output is correct |
3 |
Correct |
274 ms |
666480 KB |
Output is correct |
4 |
Correct |
267 ms |
666552 KB |
Output is correct |
5 |
Correct |
246 ms |
666544 KB |
Output is correct |
6 |
Correct |
252 ms |
666580 KB |
Output is correct |
7 |
Correct |
260 ms |
666524 KB |
Output is correct |
8 |
Correct |
244 ms |
666704 KB |
Output is correct |
9 |
Correct |
288 ms |
721188 KB |
Output is correct |
10 |
Correct |
527 ms |
883500 KB |
Output is correct |
11 |
Correct |
297 ms |
721108 KB |
Output is correct |
12 |
Correct |
462 ms |
883524 KB |
Output is correct |
13 |
Correct |
275 ms |
680424 KB |
Output is correct |
14 |
Correct |
467 ms |
883316 KB |
Output is correct |
15 |
Correct |
531 ms |
883332 KB |
Output is correct |
16 |
Correct |
249 ms |
680472 KB |
Output is correct |
17 |
Correct |
463 ms |
885836 KB |
Output is correct |
18 |
Correct |
545 ms |
885680 KB |
Output is correct |
19 |
Correct |
514 ms |
885800 KB |
Output is correct |
20 |
Correct |
498 ms |
885600 KB |
Output is correct |
21 |
Correct |
476 ms |
885692 KB |
Output is correct |
22 |
Correct |
516 ms |
888012 KB |
Output is correct |
23 |
Correct |
579 ms |
883884 KB |
Output is correct |
24 |
Correct |
488 ms |
885064 KB |
Output is correct |
25 |
Correct |
513 ms |
883308 KB |
Output is correct |
26 |
Correct |
472 ms |
883692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
267 ms |
666600 KB |
Output is correct |
2 |
Correct |
250 ms |
666712 KB |
Output is correct |
3 |
Correct |
274 ms |
666480 KB |
Output is correct |
4 |
Correct |
267 ms |
666552 KB |
Output is correct |
5 |
Correct |
246 ms |
666544 KB |
Output is correct |
6 |
Correct |
252 ms |
666580 KB |
Output is correct |
7 |
Correct |
260 ms |
666524 KB |
Output is correct |
8 |
Correct |
244 ms |
666704 KB |
Output is correct |
9 |
Correct |
288 ms |
721188 KB |
Output is correct |
10 |
Correct |
527 ms |
883500 KB |
Output is correct |
11 |
Correct |
297 ms |
721108 KB |
Output is correct |
12 |
Correct |
462 ms |
883524 KB |
Output is correct |
13 |
Correct |
275 ms |
680424 KB |
Output is correct |
14 |
Correct |
467 ms |
883316 KB |
Output is correct |
15 |
Correct |
531 ms |
883332 KB |
Output is correct |
16 |
Correct |
249 ms |
680472 KB |
Output is correct |
17 |
Correct |
463 ms |
885836 KB |
Output is correct |
18 |
Correct |
545 ms |
885680 KB |
Output is correct |
19 |
Correct |
514 ms |
885800 KB |
Output is correct |
20 |
Correct |
498 ms |
885600 KB |
Output is correct |
21 |
Correct |
476 ms |
885692 KB |
Output is correct |
22 |
Correct |
516 ms |
888012 KB |
Output is correct |
23 |
Correct |
579 ms |
883884 KB |
Output is correct |
24 |
Correct |
488 ms |
885064 KB |
Output is correct |
25 |
Correct |
513 ms |
883308 KB |
Output is correct |
26 |
Correct |
472 ms |
883692 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
16 ms |
6652 KB |
Output is correct |
4 |
Correct |
13 ms |
5832 KB |
Output is correct |
5 |
Correct |
29 ms |
9372 KB |
Output is correct |
6 |
Correct |
36 ms |
8600 KB |
Output is correct |
7 |
Correct |
28 ms |
9252 KB |
Output is correct |
8 |
Correct |
30 ms |
9248 KB |
Output is correct |
9 |
Incorrect |
25 ms |
5160 KB |
1st lines differ - on the 1st token, expected: '99999', found: '0' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
4520 KB |
Output is correct |
2 |
Correct |
30 ms |
5564 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
312 KB |
Output is correct |
5 |
Correct |
89 ms |
17204 KB |
Output is correct |
6 |
Correct |
92 ms |
17516 KB |
Output is correct |
7 |
Correct |
297 ms |
666576 KB |
Output is correct |
8 |
Correct |
50 ms |
10172 KB |
Output is correct |
9 |
Correct |
73 ms |
12304 KB |
Output is correct |
10 |
Correct |
23 ms |
4540 KB |
Output is correct |
11 |
Correct |
33 ms |
5568 KB |
Output is correct |
12 |
Correct |
254 ms |
666572 KB |
Output is correct |
13 |
Correct |
261 ms |
666480 KB |
Output is correct |
14 |
Correct |
245 ms |
666532 KB |
Output is correct |
15 |
Correct |
249 ms |
666536 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
24 ms |
5936 KB |
Output is correct |
19 |
Correct |
34 ms |
7072 KB |
Output is correct |
20 |
Correct |
26 ms |
5908 KB |
Output is correct |
21 |
Correct |
29 ms |
6596 KB |
Output is correct |
22 |
Correct |
26 ms |
5936 KB |
Output is correct |
23 |
Correct |
31 ms |
6504 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
16 ms |
6652 KB |
Output is correct |
27 |
Correct |
13 ms |
5832 KB |
Output is correct |
28 |
Correct |
29 ms |
9372 KB |
Output is correct |
29 |
Correct |
36 ms |
8600 KB |
Output is correct |
30 |
Correct |
28 ms |
9252 KB |
Output is correct |
31 |
Correct |
30 ms |
9248 KB |
Output is correct |
32 |
Correct |
267 ms |
666600 KB |
Output is correct |
33 |
Correct |
250 ms |
666712 KB |
Output is correct |
34 |
Correct |
274 ms |
666480 KB |
Output is correct |
35 |
Correct |
267 ms |
666552 KB |
Output is correct |
36 |
Correct |
246 ms |
666544 KB |
Output is correct |
37 |
Correct |
252 ms |
666580 KB |
Output is correct |
38 |
Correct |
260 ms |
666524 KB |
Output is correct |
39 |
Correct |
244 ms |
666704 KB |
Output is correct |
40 |
Correct |
288 ms |
721188 KB |
Output is correct |
41 |
Correct |
527 ms |
883500 KB |
Output is correct |
42 |
Correct |
297 ms |
721108 KB |
Output is correct |
43 |
Correct |
462 ms |
883524 KB |
Output is correct |
44 |
Correct |
275 ms |
680424 KB |
Output is correct |
45 |
Correct |
467 ms |
883316 KB |
Output is correct |
46 |
Correct |
531 ms |
883332 KB |
Output is correct |
47 |
Correct |
249 ms |
680472 KB |
Output is correct |
48 |
Correct |
463 ms |
885836 KB |
Output is correct |
49 |
Correct |
545 ms |
885680 KB |
Output is correct |
50 |
Correct |
514 ms |
885800 KB |
Output is correct |
51 |
Correct |
498 ms |
885600 KB |
Output is correct |
52 |
Correct |
476 ms |
885692 KB |
Output is correct |
53 |
Correct |
516 ms |
888012 KB |
Output is correct |
54 |
Correct |
579 ms |
883884 KB |
Output is correct |
55 |
Correct |
488 ms |
885064 KB |
Output is correct |
56 |
Correct |
513 ms |
883308 KB |
Output is correct |
57 |
Correct |
472 ms |
883692 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 |
- |