#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #pragma GCC target ("avx,avx2,fma")
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define SPEED ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define rall(v) (v).rbegin(),(v).rend()
#define all(v) (v).begin(),(v).end()
#define setp fixed<<setprecision
#define OK cerr<<"OK"<<endl<<flush
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define F first
#define S second
#define y0 jahdakdh
#define y1 jahsadakdakdh
#define endl '\n'
const ll MOD=1e9+7;
const ll mod=(1ll<<31)-1;
const ld eps=1e-8;
const ll MAXLONG=9223372036854775807;
const ll MINLONG=-9223372036854775807;
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N=1e5+5;
int n, m, k, ans;
string s;
bitset<505>a[505], dp[5005][505];
int main()
{
SPEED;
cin>>n>>m>>k;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
char x; cin>>x;
if(x=='.') a[i][j]=1, dp[0][i][j]=1;
}
}
cin>>s;
for(int i=1; i<=k; i++)
{
for(int j=0; j<n; j++)
{
if(s[i-1]=='N') dp[i][j]=dp[i-1][j+1]&a[j];
else if(s[i-1]=='S') dp[i][j]=dp[i-1][j-1]&a[j];
else if(s[i-1]=='W') dp[i][j]=(dp[i-1][j]>>1)&a[j];
else if(s[i-1]=='E') dp[i][j]=(dp[i-1][j]<<1)&a[j];
else dp[i][j]=(dp[i-1][j+1]|dp[i-1][j-1]|(dp[i-1][j]>>1)|(dp[i-1][j]<<1))&a[j];
}
}
for(int i=0; i<n; i++)
{
ans+=dp[k][i].count();
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1488 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1364 KB |
Output is correct |
16 |
Correct |
1 ms |
1364 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1408 KB |
Output is correct |
2 |
Correct |
1 ms |
1364 KB |
Output is correct |
3 |
Correct |
1 ms |
1364 KB |
Output is correct |
4 |
Correct |
1 ms |
1364 KB |
Output is correct |
5 |
Correct |
1 ms |
1364 KB |
Output is correct |
6 |
Correct |
1 ms |
1364 KB |
Output is correct |
7 |
Correct |
1 ms |
1364 KB |
Output is correct |
8 |
Correct |
1 ms |
1364 KB |
Output is correct |
9 |
Correct |
1 ms |
1364 KB |
Output is correct |
10 |
Correct |
1 ms |
1488 KB |
Output is correct |
11 |
Correct |
1 ms |
1364 KB |
Output is correct |
12 |
Correct |
1 ms |
1364 KB |
Output is correct |
13 |
Correct |
1 ms |
1364 KB |
Output is correct |
14 |
Correct |
1 ms |
1364 KB |
Output is correct |
15 |
Correct |
1 ms |
1364 KB |
Output is correct |
16 |
Correct |
1 ms |
1364 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1364 KB |
Output is correct |
19 |
Correct |
1 ms |
1364 KB |
Output is correct |
20 |
Correct |
1 ms |
1364 KB |
Output is correct |
21 |
Correct |
1 ms |
1364 KB |
Output is correct |
22 |
Correct |
66 ms |
158412 KB |
Output is correct |
23 |
Correct |
68 ms |
158484 KB |
Output is correct |
24 |
Correct |
75 ms |
158412 KB |
Output is correct |
25 |
Correct |
67 ms |
158412 KB |
Output is correct |
26 |
Correct |
70 ms |
158380 KB |
Output is correct |
27 |
Correct |
73 ms |
158432 KB |
Output is correct |
28 |
Correct |
72 ms |
158412 KB |
Output is correct |
29 |
Correct |
72 ms |
158412 KB |
Output is correct |
30 |
Correct |
71 ms |
158428 KB |
Output is correct |
31 |
Correct |
71 ms |
158412 KB |
Output is correct |
32 |
Correct |
74 ms |
158408 KB |
Output is correct |
33 |
Correct |
74 ms |
158496 KB |
Output is correct |
34 |
Correct |
76 ms |
158412 KB |
Output is correct |
35 |
Correct |
75 ms |
158516 KB |
Output is correct |
36 |
Correct |
73 ms |
158412 KB |
Output is correct |