Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Neozaawwman1
Problemset: อัศวินขี่ม้าขาว
Language: cpp
Time: 0.058 second
Submitted On: 2026-03-11 11:32:53
#include <iostream>
#include <algorithm>
using namespace std;
int a[1005][1005];
int dp[1005][1005];
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin >> n >> m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin >> a[i][j];
}
}
dp[n-1][m-1] = max(1, 1 - a[n-1][m-1]);
for(int i=n-2;i>=0;i--){
dp[i][m-1] = max(1, dp[i+1][m-1] - a[i][m-1]);
}
for(int j=m-2;j>=0;j--){
dp[n-1][j] = max(1, dp[n-1][j+1] - a[n-1][j]);
}
for(int i=n-2;i>=0;i--){
for(int j=m-2;j>=0;j--){
int need = min(dp[i+1][j], dp[i][j+1]) - a[i][j];
dp[i][j] = max(1, need);
}
}
cout << dp[0][0] << "\n";
return 0;
}