This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
bitset <505> dp[505][5005], grid[505];
void Solve()
{
int n, m, q; cin >> n >> m >> q;
vector <string> a(n);
for (auto &x : a) cin >> x;
string s; cin >> s;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (a[i - 1][j - 1] == '.') {
grid[i][j] = 1;
dp[i][0][j] = 1;
}
}
}
int c = 1;
for (auto &x : s){
for (int i = 1; i <= n; i++){
if (x == 'N' || x == '?') dp[i][c] |= (dp[i + 1][c - 1] & grid[i]);
if (x == 'S' || x == '?') dp[i][c] |= (dp[i - 1][c - 1] & grid[i]);
if (x == 'E' || x == '?') dp[i][c] |= ((dp[i][c - 1] << 1) & grid[i]);
if (x == 'W' || x == '?') dp[i][c] |= ((dp[i][c - 1] >> 1) & grid[i]);
}
c++;
}
int ans = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
ans += dp[i][q][j];
}
}
cout << ans << "\n";
}
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// freopen("in", "r", stdin);
// freopen("out", "w", stdout);
// cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |