#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fi first
#define pb push_back
#define se second
#define TASK TASK
#define ii pair<int,int>
#define int long long
const int Nmax = 501;
const int MOD = 1000000007;
const int YeuQua = 30058;
const int MASK = (25 >> 1) + 5;
const int SQRT = sqrt(Nmax);
int n , m , z;
char x;
bitset <Nmax * Nmax> dp , water;
/*
5 9 7
...#.#...
..#.##...
..#...##.
.#.#.#...
....#....
WS?EE??
*/
/*
R , C <= 500 , M <= 1000
Ta sẽ trải mảng 2 chiều ra thành 1 dãy bit với phần tử thứ i bằng 1 nếu ô đó có thể có
submarine ở thao tác này, ngược lại là 0.
-> Đi W: dp << 1
-> Đi E: dp >> 1
-> Đi N: dp << n
-> Đi S: dp >> n
00110
W
01100
*/
main()
{
cin >> n >> m >> z;
for (int i = 0 ; i < n ; i++)
for (int j = 0 ; j < m ; j++)
{
cin >> x;
if(x == '.') water[i * n + j] = 1;
}
string s;
dp = water;
cin >> s;
for (int i = 0 ; i < s.size() ; i++)
{
if(s[i] == '?') dp = (dp << 1) | (dp >> 1) | (dp << n) | (dp >> n);
if(s[i] == 'W') dp = (dp << 1);
if(s[i] == 'E') dp = (dp >> 1);
if(s[i] == 'N') dp = (dp << n);
if(s[i] == 'S') dp = (dp >> n);
dp &= water;
}
cout << dp.count();
}
Compilation message (stderr)
nautilus.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |