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;
const int MAX_N = 500;
const int MAX_M = 500;
const int MAX_K = 5000;
char mat[MAX_N + 2][MAX_M];
bitset<MAX_M> dp[MAX_K + 1][MAX_N + 2], line[MAX_N + 2];
int main() {
int n, m, k;
cin >> n >> m >> k;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 0; c < m; c++ )
cin >> mat[l][c];
}
string moves;
cin >> moves;
moves = " " + moves;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 0; c < m; c++ ) {
if ( mat[l][c] == '.' )
dp[0][l][c] = line[l][c] = true;
}
}
for ( int i = 1; i <= k; i++ ) {
for ( int l = 1; l <= n; l++ ) {
dp[i][l].reset();
if ( moves[i] == 'N' )
dp[i][l] |= dp[i - 1][l + 1];
else if ( moves[i] == 'S' )
dp[i][l] |= dp[i - 1][l - 1];
else if ( moves[i] == 'W' )
dp[i][l] |= (dp[i - 1][l] >> 1);
else if ( moves[i] == 'E' )
dp[i][l] |= (dp[i - 1][l] << 1);
else {
dp[i][l] |= dp[i - 1][l + 1];
dp[i][l] |= dp[i - 1][l - 1];
dp[i][l] |= (dp[i - 1][l] >> 1);
dp[i][l] |= (dp[i - 1][l] << 1);
}
dp[i][l] &= line[l];
}
}
int ans = 0;
for ( int l = 1; l <= n; l++ )
ans += dp[k][l].count();
cout << ans;
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... |