#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define TASKNAME "NAME"
void init()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen(TASKNAME".INP","r",stdin); freopen(TASKNAME".OUT","w",stdout);
}
const int SZ = 5e2+5;
const ll INF = INT_MAX / 2, MOD = 1e9+7, INFLL = 2e18;
const double epsilon = 1e-3;
int r,c,m;
#define bs bitset<500>
bs a[SZ], dp[SZ][2];
string s;
int res = 0;
int main()
{
init();
cin >> r >> c >> m;
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
char p;
cin >> p;
if(p == '.')
{
a[i][j] = 1;
dp[i][0][j] = 1;
}
}
}
cin >> s;
s = " " + s;
for(int k = 1; k <= m; k++)
{
int j = k % 2;
for(int i = 0; i < r; i++)
{
dp[i][j] = 0;
if(i > 0 && ( s[k] == 'S' || s[k] == '?' )) dp[i][j] |= ( a[i] & dp[i - 1][j ^ 1] );
if(i < r - 1 && ( s[k] == 'N' || s[k] == '?' )) dp[i][j] |= ( a[i] & dp[i + 1][j ^ 1] );
if( s[k] == 'E' || s[k] == '?' ) dp[i][j] |= ( a[i] & (dp[i][j ^ 1] << 1) );
if( s[k] == 'W' || s[k] == '?' ) dp[i][j] |= ( a[i] & (dp[i][j ^ 1] >> 1) );
}
}
for(int i = 0; i < r; i++)
{
res += dp[i][ m % 2 ].count();
//cout << dp[i][m % 2].count() << '\n';
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
460 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 |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
460 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 |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
110 ms |
604 KB |
Output is correct |
23 |
Correct |
115 ms |
792 KB |
Output is correct |
24 |
Correct |
114 ms |
604 KB |
Output is correct |
25 |
Correct |
112 ms |
604 KB |
Output is correct |
26 |
Correct |
112 ms |
772 KB |
Output is correct |
27 |
Correct |
150 ms |
604 KB |
Output is correct |
28 |
Correct |
150 ms |
800 KB |
Output is correct |
29 |
Correct |
156 ms |
800 KB |
Output is correct |
30 |
Correct |
155 ms |
804 KB |
Output is correct |
31 |
Correct |
154 ms |
776 KB |
Output is correct |
32 |
Correct |
178 ms |
796 KB |
Output is correct |
33 |
Correct |
185 ms |
600 KB |
Output is correct |
34 |
Correct |
186 ms |
796 KB |
Output is correct |
35 |
Correct |
179 ms |
604 KB |
Output is correct |
36 |
Correct |
183 ms |
604 KB |
Output is correct |