Submission #11063628
Source Code Expand
Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int H, W; string S[101];
int dp[101][101];
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> H >> W;
rep(y, 0, H) cin >> S[y];
rep(y, 0, H) rep(x, 0, W) dp[y][x] = inf;
dp[0][0] = 0;
if (S[0][0] == '#') dp[0][0] = 1;
rep(y, 0, H) rep(x, 0, W) {
if (y + 1 < H) {
if (S[y][x] == '.' && S[y + 1][x] == '#') chmin(dp[y + 1][x], dp[y][x] + 1);
else chmin(dp[y + 1][x], dp[y][x]);
}
if (x + 1 < W) {
if (S[y][x] == '.' && S[y][x + 1] == '#') chmin(dp[y][x + 1], dp[y][x] + 1);
else chmin(dp[y][x + 1], dp[y][x]);
}
}
cout << dp[H - 1][W - 1] << endl;
}
Submission Info
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_00, example_01, example_02, example_03 |
All |
corner_00, corner_01, example_00, example_01, example_02, example_03, kuronuri_00, max_answer_00, max_answer_01, max_answer_02, max_random_00, max_random_01, max_random_02, max_random_03, one_path_00, one_path_01, one_path_02 |
Case Name |
Status |
Exec Time |
Memory |
corner_00 |
AC |
1 ms |
256 KB |
corner_01 |
AC |
1 ms |
256 KB |
example_00 |
AC |
1 ms |
256 KB |
example_01 |
AC |
1 ms |
256 KB |
example_02 |
AC |
1 ms |
256 KB |
example_03 |
AC |
1 ms |
256 KB |
kuronuri_00 |
AC |
1 ms |
256 KB |
max_answer_00 |
AC |
1 ms |
256 KB |
max_answer_01 |
AC |
1 ms |
256 KB |
max_answer_02 |
AC |
1 ms |
256 KB |
max_random_00 |
AC |
1 ms |
384 KB |
max_random_01 |
AC |
1 ms |
256 KB |
max_random_02 |
AC |
1 ms |
384 KB |
max_random_03 |
AC |
1 ms |
256 KB |
one_path_00 |
AC |
1 ms |
256 KB |
one_path_01 |
AC |
1 ms |
256 KB |
one_path_02 |
AC |
1 ms |
256 KB |