/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
//#define int long long
#define pii pair < int, int >
using namespace std;
typedef long long ll;
const int N = 2e5;
int r, C, m;
char c[505][505];
string s;
main() {
/*ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);*/
//file("pieaters");
cin >> r >> C >> m;
bitset < 501 > b[505], bad[505], zer, last[505];
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= C; j++) {
cin >> c[i][j];
bad[i][j] = (c[i][j] == '.');
b[i][j] = (c[i][j] == '.');
}
}
cin >> s;
for(int k = 0; k < s.size(); k++) {
if(s[k] == 'W') {
for(int i = 1; i <= r; i++) {
b[i] >>= 1;
b[i] &= bad[i];
}
}
if(s[k] == 'E') {
for(int i = 1; i <= r; i++) {
b[i] <<= 1;
b[i] &= bad[i];
}
}
if(s[k] == 'N') {
for(int i = 1; i < r; i++) {
b[i] = b[i + 1] & bad[i];
}
b[r] = zer;
}
if(s[k] == 'S') {
for(int i = r; i > 1; i--) {
b[i] = b[i - 1] & bad[i];
}
b[1] = zer;
}
if(s[k] == '?') {
for (int i = 1; i <= r; i++) {
last[i] = b[i];
}
for(int i = 1; i <= r; i++) {
b[i] = ((b[i] << 1) | (b[i] >> 1) | last[i + 1] | last[i - 1]);
b[i] &= bad[i];
}
}
}
int ans = 0;
for(int i = 1; i <= r; i++) {
ans += b[i].count();
}
cout << ans;
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
*/
Compilation message
nautilus.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main() {
| ^~~~
nautilus.cpp: In function 'int main()':
nautilus.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int k = 0; k < s.size(); k++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
404 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
404 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
86 ms |
628 KB |
Output is correct |
23 |
Correct |
99 ms |
628 KB |
Output is correct |
24 |
Correct |
83 ms |
628 KB |
Output is correct |
25 |
Correct |
81 ms |
624 KB |
Output is correct |
26 |
Correct |
82 ms |
644 KB |
Output is correct |
27 |
Correct |
130 ms |
632 KB |
Output is correct |
28 |
Correct |
134 ms |
628 KB |
Output is correct |
29 |
Correct |
130 ms |
624 KB |
Output is correct |
30 |
Correct |
130 ms |
628 KB |
Output is correct |
31 |
Correct |
129 ms |
636 KB |
Output is correct |
32 |
Correct |
168 ms |
628 KB |
Output is correct |
33 |
Correct |
169 ms |
628 KB |
Output is correct |
34 |
Correct |
175 ms |
612 KB |
Output is correct |
35 |
Correct |
166 ms |
588 KB |
Output is correct |
36 |
Correct |
174 ms |
644 KB |
Output is correct |