#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
ll max_weights(int n,int m,vector<int>x,vector<int>y,vector<int>w){
int even=0,X=0,Y=0;
for(int i=0;i<m;i++){
X=max(X,x[i]);
Y=max(Y,y[i]);
if(x[i]%2==0) even++;
}
if(even==m){
ll ans=0;
for(int i=0;i<m;i++){
ans+=w[i];
}
return ans;
}
if(X<=1){
ll ans=0,cur=0;
for(int i=0;i<m;i++){
if(x[i]==0){
ans+=w[i];
}
else{
cur+=w[i];
}
}
if(n==2) return max(ans,cur);
ll sum[n][2];
memset(sum,0,sizeof sum);
for(int i=0;i<m;i++){
sum[y[i]][x[i]]+=w[i];
}
for(int i=1;i<n;i++){
sum[i][0]+=sum[i-1][0];
sum[i][1]+=sum[i-1][1];
}
ans=max(ans,cur);
for(int i=0;i<n;i++){
ans=max(ans,sum[i][0]+sum[n-1][1]-sum[i][1]);
}
return ans;
}
if(Y==0){
ll sum[n];
fill(sum,sum+n,0);
for(int i=0;i<m;i++){
sum[x[i]]=w[i];
}
ll dp[n][2][2];
dp[1][0][0]=0;
dp[1][1][0]=sum[0];
dp[1][0][1]=sum[1];
dp[1][1][1]=0;
for(ll i=2;i<n;i++){
dp[i][1][1]=max(dp[i-1][1][0],dp[i-1][1][1]);
dp[i][1][0]=max(dp[i-1][0][1],dp[i-1][0][0]+sum[i-1]);
dp[i][0][1]=max(dp[i-1][1][0],dp[i-1][1][1])+sum[i];
dp[i][0][0]=max(dp[i-1][0][1],dp[i-1][0][0]);
}
return max({dp[n-1][0][0],dp[n-1][0][1],dp[n-1][1][0],dp[n-1][1][1]});
}
if(n<=300&&Y<=8){
ll dp[n][9][9];
memset(dp,0,sizeof dp);
ll sum[n][9];
memset(sum,0,sizeof sum);
for(ll i=0;i<m;i++){
sum[x[i]][y[i]]=w[i];
}
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
if(i<=j){
for(int k=i;k<j;k++){
dp[1][i][j]+=sum[0][k];
}
}
else{
for(int k=j;k<i;k++){
dp[1][i][j]+=sum[1][k];
}
}
}
}
for(int col=2;col<n;col++){
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
for(int k=0;k<9;k++){
ll tot=0;
if(j<k){
if(i<k){
for(int r=max(i,j);r<k;r++){
tot+=sum[col-1][r];
}
}
}
else{
for(int r=k;r<j;r++){
tot+=sum[col][r];
}
}
dp[col][j][k]=max(dp[col][j][k],dp[col-1][i][j]+tot);
}
}
}
}
ll ans=0;
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
ans=max(ans,dp[n-1][i][j]);
}
}
return ans;
}
return 0ll;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
3676 KB |
Output is correct |
2 |
Correct |
22 ms |
4392 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
73 ms |
13800 KB |
Output is correct |
6 |
Correct |
75 ms |
14032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
39 ms |
8216 KB |
Output is correct |
3 |
Correct |
47 ms |
10148 KB |
Output is correct |
4 |
Correct |
18 ms |
3672 KB |
Output is correct |
5 |
Correct |
23 ms |
4436 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
19 ms |
5096 KB |
Output is correct |
13 |
Correct |
23 ms |
5852 KB |
Output is correct |
14 |
Correct |
20 ms |
4952 KB |
Output is correct |
15 |
Correct |
22 ms |
5724 KB |
Output is correct |
16 |
Correct |
25 ms |
4944 KB |
Output is correct |
17 |
Correct |
29 ms |
5716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
4188 KB |
Output is correct |
3 |
Correct |
14 ms |
5980 KB |
Output is correct |
4 |
Correct |
11 ms |
5724 KB |
Output is correct |
5 |
Correct |
28 ms |
8284 KB |
Output is correct |
6 |
Correct |
21 ms |
7512 KB |
Output is correct |
7 |
Correct |
25 ms |
8020 KB |
Output is correct |
8 |
Correct |
25 ms |
8128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
500 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
684 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
500 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
684 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '299', found: '0' |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
500 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
684 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '299', found: '0' |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
4188 KB |
Output is correct |
3 |
Correct |
14 ms |
5980 KB |
Output is correct |
4 |
Correct |
11 ms |
5724 KB |
Output is correct |
5 |
Correct |
28 ms |
8284 KB |
Output is correct |
6 |
Correct |
21 ms |
7512 KB |
Output is correct |
7 |
Correct |
25 ms |
8020 KB |
Output is correct |
8 |
Correct |
25 ms |
8128 KB |
Output is correct |
9 |
Incorrect |
20 ms |
4036 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 |
23 ms |
3676 KB |
Output is correct |
2 |
Correct |
22 ms |
4392 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
73 ms |
13800 KB |
Output is correct |
6 |
Correct |
75 ms |
14032 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
39 ms |
8216 KB |
Output is correct |
9 |
Correct |
47 ms |
10148 KB |
Output is correct |
10 |
Correct |
18 ms |
3672 KB |
Output is correct |
11 |
Correct |
23 ms |
4436 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
19 ms |
5096 KB |
Output is correct |
19 |
Correct |
23 ms |
5852 KB |
Output is correct |
20 |
Correct |
20 ms |
4952 KB |
Output is correct |
21 |
Correct |
22 ms |
5724 KB |
Output is correct |
22 |
Correct |
25 ms |
4944 KB |
Output is correct |
23 |
Correct |
29 ms |
5716 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
4188 KB |
Output is correct |
26 |
Correct |
14 ms |
5980 KB |
Output is correct |
27 |
Correct |
11 ms |
5724 KB |
Output is correct |
28 |
Correct |
28 ms |
8284 KB |
Output is correct |
29 |
Correct |
21 ms |
7512 KB |
Output is correct |
30 |
Correct |
25 ms |
8020 KB |
Output is correct |
31 |
Correct |
25 ms |
8128 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
2 ms |
500 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
684 KB |
Output is correct |
44 |
Correct |
1 ms |
600 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '299', found: '0' |
47 |
Halted |
0 ms |
0 KB |
- |