//GOAL : BECOME A MASTER
//cf : Mali
//Toktarbek Muhammedali 10B
//Esyk BIL
// #include <bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
#define fast() ios_base::sync_with_stdio(0),cin.tie(0)
#define int long long
#define F first
#define S second
// const int N = 1e6 + 10;
// const long long INF = 1e18 + 1;
// const int mod = 1e9 + 7;
using namespace std;
bitset<600>a[600] , b[600] , E[600] , W[600] , S[600] , N[600] , nw[600];
void goat(){
char x;
string s;
int n , m , k;
cin >> n >> m >> k;
for (int i = 1 ; i <= n ; i ++){
for (int j = 1 ; j <= m ; j ++){
cin >> x;
if (x == '.'){
a[i][j] = 1;
b[i][j] = 1;
}
}
}
cin >> s;
s = '.' + s;
for (int i = 1 ; i <= k ; i ++){
if (s[i] == 'E'){
for (int j = 1 ; j <= n ; j ++)a[j] = (a[j] << 1);
for (int j = 1 ; j <= n ; j ++)a[j] &= b[j];
}
else if (s[i] == 'W'){
for (int j = 1 ; j <= n ; j ++)a[j] = (a[j] >> 1);
for (int j = 1 ; j <= n ; j ++)a[j] &= b[j];
}
else if (s[i] == 'S'){
for (int j = n ; j >= 1 ; j --)a[j] = a[j-1];
for (int j = 1 ; j <= n ; j ++)a[j] &= b[j];
}
else if (s[i] == 'N'){
for (int j = 1 ; j <= n ; j ++)a[j] = a[j+1];
for (int j = 1 ; j <= n ; j ++)a[j] &= b[j];
}
else {
for (int i = 1 ; i <= n ; i ++){
N[i] = a[i];
W[i] = a[i];
S[i] = a[i];
E[i] = a[i];
}
//
for (int j = 1 ; j <= n ; j ++)N[j] = N[j+1];
for (int j = 1 ; j <= n ; j ++)N[j] &= b[j];
//
for (int j = n ; j >= 1 ; j --)S[j] = S[j-1];
for (int j = 1 ; j <= n ; j ++)S[j] &= b[j];
//
for (int j = 1 ; j <= n ; j ++)W[j] = (W[j] >> 1);
for (int j = 1 ; j <= n ; j ++)W[j] &= b[j];
//
for (int j = 1 ; j <= n ; j ++)E[j] = (E[j] << 1);
for (int j = 1 ; j <= n ; j ++)E[j] &= b[j];
//
for (int i = 1 ; i <= n ; i ++){
nw[i] = (N[i] | W[i] | E[i] | S[i]);
a[i] = nw[i];
}
}
}
int ans = 0;
for (int i = 1 ; i <= n ; i ++){
for (int j = 1 ; j <= m ; j ++){
if (a[i][j] == 1)ans++;
}
}
cout << ans << endl;
}
signed main () {
fast();
///S
//E W
///N
// freopen("B.in", "r", stdin);
// freopen("B.out", "w", stdout);
// int T;
// cin >> T;
// for (int i = 1 ; i <= T ; i ++){
goat();
// }
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
472 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
560 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
472 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
560 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
82 ms |
1004 KB |
Output is correct |
23 |
Correct |
83 ms |
1012 KB |
Output is correct |
24 |
Correct |
81 ms |
856 KB |
Output is correct |
25 |
Correct |
82 ms |
1008 KB |
Output is correct |
26 |
Correct |
79 ms |
856 KB |
Output is correct |
27 |
Correct |
149 ms |
1008 KB |
Output is correct |
28 |
Correct |
157 ms |
1104 KB |
Output is correct |
29 |
Correct |
151 ms |
860 KB |
Output is correct |
30 |
Correct |
155 ms |
1012 KB |
Output is correct |
31 |
Correct |
149 ms |
860 KB |
Output is correct |
32 |
Correct |
208 ms |
856 KB |
Output is correct |
33 |
Correct |
214 ms |
1008 KB |
Output is correct |
34 |
Correct |
208 ms |
856 KB |
Output is correct |
35 |
Correct |
213 ms |
1012 KB |
Output is correct |
36 |
Correct |
208 ms |
856 KB |
Output is correct |