I just made a mistake while participating in a coding contest in Vietnam and I came across a simple dp problem, the problem was: https://lqdoj.edu.vn/problem/dutpc2a : test of the contest organizers that I participated in https://atcoder.jp/contests/dp/submissions/me : The problem I encountered is the same as the one on atcoder
But I accepted this problem on atcoder but when I submitted the test from the contest organizer that I joined, I was wrong. And the problem I have is when I compare with the character '.' I got wrong but compare with '#' then accepted. Can someone explain to me why when I compare the character '.' wrong?
this my code wrong:
include <bits/stdc++.h>
using namespace std;
define int long long
define INF 0x3f3f3f3f3f3f3f3f
define FASTIO std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
define nax (int) (1005)
const int mod = 1e9 + 7;
char v[nax][nax]; int dp[nax][nax]; int32_t main() { FASTIO
int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> v[i][j]; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (i == 1 && j == 1) { dp[i][j]=1; } else if (v[i][j] == '.') { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; } } } cout << dp[n][m]; return 0;
}
and my code accepted:
include <bits/stdc++.h>
using namespace std;
define int long long
define INF 0x3f3f3f3f3f3f3f3f
define FASTIO std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
define nax (int) (1005)
const int mod = 1e9 + 7;
char v[nax][nax]; int dp[nax][nax]; int32_t main() { FASTIO
int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> v[i][j]; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (i == 1 && j == 1) { dp[i][j]=1; } else { if (v[i][j] != '#') { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; } } } } cout << dp[n][m]; return 0;
}
Thanks for the help and sorry for my english!