Submission
Status:
[PPPP-SSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: devilpoohs
Problemset: อัศวินขี่ม้าขาว
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-05 21:04:53
#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int ar[N][N];
int n,m;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>ar[i][j];
}
}
double dp[n][m];
dp[0][0]=ar[0][0];
// cout<<'\n';
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(i!=0 or j!=0){
double ans=LLONG_MIN;
if(i-1>=0)
ans=max(ans,ar[i][j]+dp[i-1][j]);
if(j-1>=0)
ans=max(ans,ar[i][j]+dp[i][j-1]);
dp[i][j]=ans;
}
// cout<<dp[i][j]<<'|';
}
// cout<<'\n';
}
// cout<<'\n';
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(i!=0 or j!=0){
double temp=dp[i][j];
dp[i][j]=LLONG_MIN;
if(i-1>=0)
dp[i][j]=max(dp[i][j],dp[i-1][j]);
if(j-1>=0)
dp[i][j]=max(dp[i][j],dp[i][j-1]);
dp[i][j]=min(dp[i][j],temp);
}
// cout<<dp[i][j]<<'|';
}
// cout<<'\n';
}
double one=2;
cout<<fixed<<setprecision(0)<<max(1-dp[n-1][m-1],one);
return 0;
}
/*
4 3
-3 -6 -3
2 2 -3
-8 -8 -8
1 1 1
4 3
-3 -6 -3
2 2 -3
-8 -8 -8
1 1 1
*/