#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
using namespace std;
const long long oo = 1000000000000000000;
long long int sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
string s;
int n, m, k;
char c[ 501 ][ 501 ];
int mp[ 501 ][ 501 ], mpp[ 501 ][ 501 ];
int main () {
cin >> n >> m >> k;
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
cin >> c[ i ][ j ];
if ( c[ i ][ j ] == '.' )
mp[ i ][ j ] = 1;
}
}
cin >> s;
for ( auto cc : s ) {
if ( cc == 'W' || cc == 'N' ) {
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
if ( !mp[ i ][ j ] )
continue;
if ( cc == 'W' && j > 1 && c[ i ][ j - 1 ] == '.' ) {
mp[ i][ j - 1 ] = 1;
}
else if ( cc == 'N' && i > 1 && c[ i - 1 ][ j ] == '.' )
mp[ i - 1 ][ j ] = 1;
mp[ i ][ j ] = 0;
}
}
}
else if ( cc == 'S' || cc == 'E' ) {
for ( int i = n; i >= 1; i -- ) {
for ( int j = m; j >= 1; j -- ) {
if ( !mp[ i ][ j ] )
continue;
if ( cc == 'E' && j < m && c[ i ][ j + 1 ] == '.' ) {
mp[ i][ j + 1 ] = 1;
}
else if ( cc == 'S' && i < n && c[ i + 1 ][ j ] == '.' )
mp[ i + 1 ][ j ] = 1;
mp[ i ][ j ] = 0;
}
}
}
else {
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
if ( mp[ i ][ j ] ) {
if ( i > 1 && c[ i - 1 ][ j ] == '.' )
mpp[ i - 1 ][ j ] = 1;
if ( j < m && c[ i ][ j + 1 ] == '.' )
mpp[ i ][ j + 1 ] = 1;
if ( j > 1 && c[ i ][ j - 1 ] == '.' )
mpp[ i ][ j - 1 ] = 1;
if ( i < n && c[ i + 1 ][ j ] == '.' )
mpp[ i + 1 ][ j ] = 1;
}
}
}
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
if ( mpp[ i ][ j ] )
mp[ i ][ j ] = 1;
else
mp[ i ][ j ] = 0;
mpp[ i ][ j ] = 0;
}
}
}
}
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ )
ans += mp[ i ][ j ];
}
cout << ans;
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WSEEN
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
556 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
556 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
4 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
2 ms |
716 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
9 ms |
716 KB |
Output is correct |
14 |
Correct |
9 ms |
752 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
4 ms |
716 KB |
Output is correct |
18 |
Correct |
8 ms |
752 KB |
Output is correct |
19 |
Correct |
8 ms |
752 KB |
Output is correct |
20 |
Correct |
4 ms |
716 KB |
Output is correct |
21 |
Correct |
3 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
556 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
4 ms |
748 KB |
Output is correct |
9 |
Correct |
3 ms |
716 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
11 |
Correct |
2 ms |
716 KB |
Output is correct |
12 |
Correct |
4 ms |
716 KB |
Output is correct |
13 |
Correct |
9 ms |
716 KB |
Output is correct |
14 |
Correct |
9 ms |
752 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
4 ms |
716 KB |
Output is correct |
18 |
Correct |
8 ms |
752 KB |
Output is correct |
19 |
Correct |
8 ms |
752 KB |
Output is correct |
20 |
Correct |
4 ms |
716 KB |
Output is correct |
21 |
Correct |
3 ms |
716 KB |
Output is correct |
22 |
Execution timed out |
1081 ms |
2456 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |