Submission #16017809
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int r,c;
cin>>r>>c;
ll mtr[3005][3005]={0};
int k;
cin>>k;
for(int i=0; i<k; i++){
int x,y,p;
cin>>x>>y>>p;
mtr[x][y]=p;
}
ll dp[3005][3005][4]={0};
if(mtr[1][1])
dp[1][1][1]=mtr[1][1];
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
if(i>1){
ll mx=0;
for(int x=0; x<4; x++)
mx=max(mx,dp[i-1][j][x]);
dp[i][j][0]=max(dp[i][j][0],mx);
if(mtr[i][j])
dp[i][j][1]=max(dp[i][j][1],mx+mtr[i][j]);
}
if(j>1){
for(int x=0; x<4; x++)
dp[i][j][x]=max(dp[i][j-1][x],dp[i][j][x]);
if(mtr[i][j]){
for(int x=1; x<4; x++)
dp[i][j][x]=max(dp[i][j-1][x-1]+mtr[i][j],dp[i][j][x]);
}
}
}
}
ll ans=0;
for(int x=0; x<4; x++)
ans=max(ans,dp[r][c][x]);
cout<<ans;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Picking Goods |
| User | saurav1717 |
| Language | C++ (GCC 9.2.1) |
| Score | 0 |
| Code Size | 876 Byte |
| Status | RE |
| Exec Time | 110 ms |
| Memory | 3248 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | RE | 110 ms | 3048 KiB |
| 02.txt | RE | 105 ms | 3048 KiB |
| 03.txt | RE | 106 ms | 3116 KiB |
| 04.txt | RE | 103 ms | 3244 KiB |
| 05.txt | RE | 104 ms | 3048 KiB |
| 06.txt | RE | 104 ms | 3116 KiB |
| 07.txt | RE | 104 ms | 3016 KiB |
| 08.txt | RE | 105 ms | 3116 KiB |
| 09.txt | RE | 108 ms | 3048 KiB |
| 10.txt | RE | 105 ms | 3016 KiB |
| 11.txt | RE | 105 ms | 3176 KiB |
| 12.txt | RE | 105 ms | 3176 KiB |
| 13.txt | RE | 103 ms | 2964 KiB |
| 14.txt | RE | 106 ms | 3120 KiB |
| 15.txt | RE | 105 ms | 3248 KiB |
| 16.txt | RE | 104 ms | 3052 KiB |
| 17.txt | RE | 104 ms | 3036 KiB |
| 18.txt | RE | 105 ms | 3132 KiB |
| 19.txt | RE | 103 ms | 3128 KiB |
| 20.txt | RE | 104 ms | 3176 KiB |
| 21.txt | RE | 104 ms | 3188 KiB |
| 22.txt | RE | 104 ms | 3176 KiB |
| 23.txt | RE | 104 ms | 2988 KiB |
| 24.txt | RE | 106 ms | 3124 KiB |
| 25.txt | RE | 102 ms | 3048 KiB |
| 26.txt | RE | 102 ms | 2984 KiB |
| 27.txt | RE | 105 ms | 3128 KiB |
| 28.txt | RE | 101 ms | 3184 KiB |
| 29.txt | RE | 102 ms | 3188 KiB |
| 30.txt | RE | 103 ms | 3120 KiB |
| 31.txt | RE | 102 ms | 3048 KiB |
| 32.txt | RE | 105 ms | 2968 KiB |
| 33.txt | RE | 103 ms | 3244 KiB |
| 34.txt | RE | 104 ms | 2968 KiB |
| s1.txt | RE | 105 ms | 3052 KiB |
| s2.txt | RE | 107 ms | 3044 KiB |
| s3.txt | RE | 102 ms | 3016 KiB |