#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
const int MAXN = 300100;
int n, w[MAXN], m;
pii a[MAXN];
namespace A{
ll solve(){
ll ans = 0;
for(int i=1; i<=m; i++){
ans += w[i];
}
return ans;
}
}
namespace B{
ll d[3001][3001];
ll dp[3001][3001];
ll pref[3001][3001];
ll ddp[3001][3001];
ll suf[3001];
ll solve(){
for(int i=1; i<=m; i++){
d[a[i].ff][a[i].ss] += w[i];
}
for(int i=1; i<=n; i++){
dp[0][i] = -1e18;
ddp[0][i] = -1e18;
}
dp[0][0] = 0;
ddp[0][0] = 0;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
pref[i][j] = pref[i][j - 1] + d[i][j];
}
ll mx = -1e18;
for(int j=n; j>=0; j--){
mx = max(mx, dp[i-1][j] + pref[i][j]);
suf[j] = mx;
}
ll pddp = -1e18, pdp = -1e18;
mx = -1e18;
for(int j=0; j<=n; j++) mx = max(mx, dp[i-1][j]);
for(int j=0; j<=n; j++){
ddp[i][j] = mx;
dp[i][j] = 0;
pddp = max(pddp, ddp[i-1][j]-pref[i-1][j]);
ddp[i][j] = max(ddp[i][j], pddp + pref[i-1][j]);
dp[i][j] = ddp[i][j];
dp[i][j] = max(dp[i][j], suf[j]-pref[i][j]);
pdp = max(pdp, ddp[i-1][j]-pref[i-1][j]);
dp[i][j] = max(dp[i][j], pdp+pref[i-1][j]);
}
}
//for(int i=1; i<=n; i++){
// for(int j=0; j<=n; j++){
// cout<<dp[i][j]<<' ';
// }
// cout<<'\n';
//}
ll ans = 0;
for(int i=0; i<=n; i++) ans = max(ans, dp[n][i]);
return ans;
}
}
namespace C{
ll d[5][100100];
ll dp[5][100100];
ll pref[5][100100];
ll ddp[5][100100];
ll suf[100100];
ll solve(){
for(int i=1; i<=m; i++){
d[a[i].ff][a[i].ss] += w[i];
}
for(int i=1; i<=n; i++){
dp[0][i] = -1e18;
ddp[0][i] = -1e18;
}
dp[0][0] = 0;
ddp[0][0] = 0;
for(int i=1; i<=3; i++){
for(int j=1; j<=n; j++){
pref[i][j] = pref[i][j - 1] + d[i][j];
}
ll mx = -1e18;
for(int j=n; j>=0; j--){
mx = max(mx, dp[i-1][j] + pref[i][j]);
suf[j] = mx;
}
ll pddp = -1e18, pdp = -1e18;
mx = -1e18;
for(int j=0; j<=n; j++) mx = max(mx, dp[i-1][j]);
for(int j=0; j<=n; j++){
ddp[i][j] = mx;
dp[i][j] = 0;
pddp = max(pddp, ddp[i-1][j]-pref[i-1][j]);
ddp[i][j] = max(ddp[i][j], pddp + pref[i-1][j]);
dp[i][j] = ddp[i][j];
dp[i][j] = max(dp[i][j], suf[j]-pref[i][j]);
pdp = max(pdp, ddp[i-1][j]-pref[i-1][j]);
dp[i][j] = max(dp[i][j], pdp+pref[i-1][j]);
}
}
//for(int i=1; i<=n; i++){
// for(int j=0; j<=n; j++){
// cout<<dp[i][j]<<' ';
// }
// cout<<'\n';
//}
ll ans = 0;
for(int i=0; i<=n; i++) ans = max(ans, dp[3][i]);
return ans;
}
}
namespace D{
ll d[100100][10];
ll dp[100100][10];
ll pref[100100][10];
ll ddp[100100][10];
ll suf[10];
ll solve(){
for(int i=1; i<=m; i++){
d[a[i].ff][a[i].ss] += w[i];
}
for(int i=1; i<=5; i++){
dp[0][i] = -1e18;
ddp[0][i] = -1e18;
}
dp[0][0] = 0;
ddp[0][0] = 0;
for(int i=1; i<=n; i++){
for(int j=1; j<=5; j++){
pref[i][j] = pref[i][j - 1] + d[i][j];
}
ll mx = -1e18;
for(int j=5; j>=0; j--){
mx = max(mx, dp[i-1][j] + pref[i][j]);
suf[j] = mx;
}
ll pdp = -1e18;
mx = -1e18;
for(int j=0; j<=5; j++) mx = max(mx, dp[i-1][j]);
for(int j=0; j<=5; j++){
ddp[i][j] = mx;
dp[i][j] = 0;
pdp = max(pdp, ddp[i-1][j]-pref[i-1][j]);
ddp[i][j] = max(ddp[i][j], pdp + pref[i-1][j]);
dp[i][j] = ddp[i][j];
dp[i][j] = max(dp[i][j], suf[j]-pref[i][j]);
dp[i][j] = max(dp[i][j], pdp+pref[i-1][j]);
}
}
//for(int i=1; i<=n; i++){
// for(int j=0; j<=n; j++){
// cout<<dp[i][j]<<' ';
// }
// cout<<'\n';
//}
ll ans = 0;
for(int i=0; i<=5; i++) ans = max(ans, dp[n][i]);
return ans;
}
}
long long max_weights(int N, int M, vector<int> X, vector<int> Y,
vector<int> W) {
n = N;
m = M;
for(int i=1; i<=m; i++){
a[i] = {X[i-1]+1, Y[i-1]+1};
}
for(int i=1; i<=m; i++){
w[i] = W[i-1];
}
int ok1 = 1;
int ok2 = 1, ok3 = 1;
for(int i=1; i<=m; i++){
ok1 &= (a[i].ff % 2 == 1);
ok2 &= (a[i].ff <= 2);
ok3 &= (a[i].ss == 1);
}
if(ok1) return A::solve();
if(n <= 3000) return B::solve();
if(ok2) return C::solve();
if(ok3) return D::solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4700 KB |
Output is correct |
2 |
Correct |
18 ms |
5724 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
59 ms |
17140 KB |
Output is correct |
6 |
Correct |
65 ms |
17492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
37 ms |
18840 KB |
Output is correct |
3 |
Correct |
45 ms |
21840 KB |
Output is correct |
4 |
Correct |
16 ms |
4692 KB |
Output is correct |
5 |
Correct |
19 ms |
5460 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
23 ms |
13816 KB |
Output is correct |
13 |
Correct |
24 ms |
15708 KB |
Output is correct |
14 |
Correct |
20 ms |
13916 KB |
Output is correct |
15 |
Correct |
22 ms |
15460 KB |
Output is correct |
16 |
Correct |
20 ms |
13904 KB |
Output is correct |
17 |
Correct |
25 ms |
15196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
13 ms |
23900 KB |
Output is correct |
3 |
Correct |
25 ms |
29100 KB |
Output is correct |
4 |
Correct |
23 ms |
30556 KB |
Output is correct |
5 |
Correct |
38 ms |
36796 KB |
Output is correct |
6 |
Correct |
33 ms |
36172 KB |
Output is correct |
7 |
Correct |
36 ms |
36708 KB |
Output is correct |
8 |
Correct |
40 ms |
36652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
528 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
3272 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
11 |
Correct |
2 ms |
3420 KB |
Output is correct |
12 |
Correct |
4 ms |
7392 KB |
Output is correct |
13 |
Correct |
1 ms |
1624 KB |
Output is correct |
14 |
Correct |
4 ms |
7352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
528 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
3272 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
11 |
Correct |
2 ms |
3420 KB |
Output is correct |
12 |
Correct |
4 ms |
7392 KB |
Output is correct |
13 |
Correct |
1 ms |
1624 KB |
Output is correct |
14 |
Correct |
4 ms |
7352 KB |
Output is correct |
15 |
Correct |
3 ms |
7256 KB |
Output is correct |
16 |
Correct |
1 ms |
1624 KB |
Output is correct |
17 |
Correct |
13 ms |
9820 KB |
Output is correct |
18 |
Correct |
12 ms |
9560 KB |
Output is correct |
19 |
Correct |
15 ms |
10076 KB |
Output is correct |
20 |
Correct |
12 ms |
10072 KB |
Output is correct |
21 |
Correct |
11 ms |
10076 KB |
Output is correct |
22 |
Correct |
20 ms |
12812 KB |
Output is correct |
23 |
Correct |
6 ms |
8540 KB |
Output is correct |
24 |
Correct |
10 ms |
9480 KB |
Output is correct |
25 |
Correct |
4 ms |
7516 KB |
Output is correct |
26 |
Correct |
6 ms |
8028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
528 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
3272 KB |
Output is correct |
10 |
Correct |
4 ms |
7516 KB |
Output is correct |
11 |
Correct |
2 ms |
3420 KB |
Output is correct |
12 |
Correct |
4 ms |
7392 KB |
Output is correct |
13 |
Correct |
1 ms |
1624 KB |
Output is correct |
14 |
Correct |
4 ms |
7352 KB |
Output is correct |
15 |
Correct |
3 ms |
7256 KB |
Output is correct |
16 |
Correct |
1 ms |
1624 KB |
Output is correct |
17 |
Correct |
13 ms |
9820 KB |
Output is correct |
18 |
Correct |
12 ms |
9560 KB |
Output is correct |
19 |
Correct |
15 ms |
10076 KB |
Output is correct |
20 |
Correct |
12 ms |
10072 KB |
Output is correct |
21 |
Correct |
11 ms |
10076 KB |
Output is correct |
22 |
Correct |
20 ms |
12812 KB |
Output is correct |
23 |
Correct |
6 ms |
8540 KB |
Output is correct |
24 |
Correct |
10 ms |
9480 KB |
Output is correct |
25 |
Correct |
4 ms |
7516 KB |
Output is correct |
26 |
Correct |
6 ms |
8028 KB |
Output is correct |
27 |
Correct |
132 ms |
224032 KB |
Output is correct |
28 |
Correct |
55 ms |
37504 KB |
Output is correct |
29 |
Correct |
199 ms |
231012 KB |
Output is correct |
30 |
Correct |
252 ms |
274020 KB |
Output is correct |
31 |
Correct |
206 ms |
274516 KB |
Output is correct |
32 |
Correct |
60 ms |
34132 KB |
Output is correct |
33 |
Correct |
206 ms |
298580 KB |
Output is correct |
34 |
Correct |
206 ms |
298480 KB |
Output is correct |
35 |
Correct |
156 ms |
232840 KB |
Output is correct |
36 |
Correct |
187 ms |
244304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
13 ms |
23900 KB |
Output is correct |
3 |
Correct |
25 ms |
29100 KB |
Output is correct |
4 |
Correct |
23 ms |
30556 KB |
Output is correct |
5 |
Correct |
38 ms |
36796 KB |
Output is correct |
6 |
Correct |
33 ms |
36172 KB |
Output is correct |
7 |
Correct |
36 ms |
36708 KB |
Output is correct |
8 |
Correct |
40 ms |
36652 KB |
Output is correct |
9 |
Incorrect |
17 ms |
5200 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 |
16 ms |
4700 KB |
Output is correct |
2 |
Correct |
18 ms |
5724 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
59 ms |
17140 KB |
Output is correct |
6 |
Correct |
65 ms |
17492 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
37 ms |
18840 KB |
Output is correct |
9 |
Correct |
45 ms |
21840 KB |
Output is correct |
10 |
Correct |
16 ms |
4692 KB |
Output is correct |
11 |
Correct |
19 ms |
5460 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
23 ms |
13816 KB |
Output is correct |
19 |
Correct |
24 ms |
15708 KB |
Output is correct |
20 |
Correct |
20 ms |
13916 KB |
Output is correct |
21 |
Correct |
22 ms |
15460 KB |
Output is correct |
22 |
Correct |
20 ms |
13904 KB |
Output is correct |
23 |
Correct |
25 ms |
15196 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
13 ms |
23900 KB |
Output is correct |
26 |
Correct |
25 ms |
29100 KB |
Output is correct |
27 |
Correct |
23 ms |
30556 KB |
Output is correct |
28 |
Correct |
38 ms |
36796 KB |
Output is correct |
29 |
Correct |
33 ms |
36172 KB |
Output is correct |
30 |
Correct |
36 ms |
36708 KB |
Output is correct |
31 |
Correct |
40 ms |
36652 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
528 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
3272 KB |
Output is correct |
41 |
Correct |
4 ms |
7516 KB |
Output is correct |
42 |
Correct |
2 ms |
3420 KB |
Output is correct |
43 |
Correct |
4 ms |
7392 KB |
Output is correct |
44 |
Correct |
1 ms |
1624 KB |
Output is correct |
45 |
Correct |
4 ms |
7352 KB |
Output is correct |
46 |
Correct |
3 ms |
7256 KB |
Output is correct |
47 |
Correct |
1 ms |
1624 KB |
Output is correct |
48 |
Correct |
13 ms |
9820 KB |
Output is correct |
49 |
Correct |
12 ms |
9560 KB |
Output is correct |
50 |
Correct |
15 ms |
10076 KB |
Output is correct |
51 |
Correct |
12 ms |
10072 KB |
Output is correct |
52 |
Correct |
11 ms |
10076 KB |
Output is correct |
53 |
Correct |
20 ms |
12812 KB |
Output is correct |
54 |
Correct |
6 ms |
8540 KB |
Output is correct |
55 |
Correct |
10 ms |
9480 KB |
Output is correct |
56 |
Correct |
4 ms |
7516 KB |
Output is correct |
57 |
Correct |
6 ms |
8028 KB |
Output is correct |
58 |
Correct |
132 ms |
224032 KB |
Output is correct |
59 |
Correct |
55 ms |
37504 KB |
Output is correct |
60 |
Correct |
199 ms |
231012 KB |
Output is correct |
61 |
Correct |
252 ms |
274020 KB |
Output is correct |
62 |
Correct |
206 ms |
274516 KB |
Output is correct |
63 |
Correct |
60 ms |
34132 KB |
Output is correct |
64 |
Correct |
206 ms |
298580 KB |
Output is correct |
65 |
Correct |
206 ms |
298480 KB |
Output is correct |
66 |
Correct |
156 ms |
232840 KB |
Output is correct |
67 |
Correct |
187 ms |
244304 KB |
Output is correct |
68 |
Incorrect |
17 ms |
5200 KB |
1st lines differ - on the 1st token, expected: '99999', found: '0' |
69 |
Halted |
0 ms |
0 KB |
- |