Submission
Status:
[PPPPPPPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: Gump2011
Problemset: อัศวินขี่ม้าขาว
Language: cpp
Time: 0.057 second
Submitted On: 2026-03-08 16:42:38
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin>>n>>m;
vector<vector<int>> a(n+2, vector<int>(m+2));
vector<vector<int>> dp(n+2, vector<int>(m+2, 1e9));
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
dp[n][m] = max(1, 1 - a[n][m]);
for(int i=n;i>=1;i--){
for(int j=m;j>=1;j--){
if(i==n && j==m) continue;
int need = min(dp[i+1][j], dp[i][j+1]) - a[i][j];
dp[i][j] = max(1, need);
}
}
cout<<dp[1][1];
}