#include <bits/stdc++.h>
//code
#define fl(i,x,y,z) for(int i=x;i<=y;i=i+z)
#define fn(i,x,y,z) for(int i=x;i>=y;i=i-z)
#define rep(i,x,y) for(int i=x;i<y;i=i+1)
#define all(v) v.begin(),v.end()
#define pb emplace_back
#define tle cout<<"tle"<<endl
#define edl cout<<"\n"
#define el "\n"
#define getbit(x,i) ((x>>i)&1)
#define bitcnt __builtin_popcount
//ham
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
//#define int long long
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
const int maxn=505;
int m,n,p;
string s;
bitset <maxn> dp[maxn],et[maxn],f[maxn],a[maxn];
void inp()
{
cin>>m>>n>>p;
fl(i,1,m,1)
fl(j,1,n,1)
{
char x; cin>>x;
if (x=='.') a[i][j]=1;
else a[i][j]=0;
dp[i][j]=a[i][j];
}
}
void change(char t,int x)
{
if (t=='?') f[x]=(dp[x-1]|dp[x+1]|(dp[x]>>1)|(dp[x]<<1))&a[x];
else if (t=='N') f[x]=dp[x+1]&a[x];
else if (t=='E') f[x]=(dp[x]<<1)&a[x];
else if (t=='S') f[x]=dp[x-1]&a[x];
else if (t=='W') f[x]=(dp[x]>>1)&a[x];
}
void sol()
{
while (p--)
{
char type; cin>>type;
fl(i,1,m,1) change(type,i);
fl(i,1,m,1) dp[i]=f[i];
}
int cnt=0;
fl(i,1,m,1)
cnt+= dp[i].count();
cout<<cnt;
}
signed main()
{
#define name "seaw"
if (fopen(name".inp", "r"))
{
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
inp();
sol();
return 0;
}
/* /\_/\
( ._. )
/ >V< \
*/
Compilation message
nautilus.cpp: In function 'int main()':
nautilus.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen(name".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
2 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
88 ms |
336 KB |
Output is correct |
23 |
Correct |
83 ms |
336 KB |
Output is correct |
24 |
Correct |
81 ms |
560 KB |
Output is correct |
25 |
Correct |
80 ms |
552 KB |
Output is correct |
26 |
Correct |
80 ms |
796 KB |
Output is correct |
27 |
Correct |
135 ms |
592 KB |
Output is correct |
28 |
Correct |
138 ms |
760 KB |
Output is correct |
29 |
Correct |
139 ms |
792 KB |
Output is correct |
30 |
Correct |
143 ms |
944 KB |
Output is correct |
31 |
Correct |
136 ms |
592 KB |
Output is correct |
32 |
Correct |
184 ms |
760 KB |
Output is correct |
33 |
Correct |
181 ms |
592 KB |
Output is correct |
34 |
Correct |
184 ms |
592 KB |
Output is correct |
35 |
Correct |
181 ms |
592 KB |
Output is correct |
36 |
Correct |
181 ms |
592 KB |
Output is correct |