#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
const int mod = 1e9 + 7;
ll lgp(ll a,ll b){
ll res = 1LL, pop = a;
for(int i=0;(1LL << i)<=b;i++){
if(b & (1LL << i)){
res = (res * pop) % mod;
}
pop = (pop * pop) % mod;
}
return res;
}
ll inv(ll a){
return lgp(a, mod - 2LL);
}
const int mmax = 505;
int n,m,k;
char c[mmax][mmax];
string s;
bitset<mmax>pr[mmax],curr[mmax],obstacole[mmax];
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
srand(chrono::steady_clock::now().time_since_epoch().count());
// freopen("input.in","r",stdin);
cin >> n >> m >> k;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >> c[i][j];
curr[i][j] = (c[i][j] == '.' ? 1 : 0);
obstacole[i][j] = (c[i][j] == '.' ? 1 : 0);
}
}
cin >> s;
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++){
swap(curr[j],pr[j]);
}
for(int j=1;j<=n;j++){
curr[j].reset();
}
if(s[i - 1] == 'N' || s[i - 1] == '?'){
for(int j=1;j<=n;j++){
if(j <= n - 1){
curr[j] |= pr[j + 1];
}
}
}
if(s[i - 1] == 'S' || s[i - 1] == '?'){
for(int j=1;j<=n;j++){
if(j >= 2){
curr[j] |= pr[j - 1];
}
}
}
if(s[i - 1] == 'E' || s[i - 1] == '?'){
for(int j=1;j<=n;j++){
curr[j] |= (pr[j] << 1);
}
}
if(s[i - 1] == 'W' || s[i - 1] == '?'){
for(int j=1;j<=n;j++){
curr[j] |= (pr[j] >> 1);
}
}
for(int j=1;j<=n;j++){
curr[j] &= obstacole[j];
}
}
int ans = 0;
for(int i=1;i<=n;i++){
ans += curr[i].count();
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
63 ms |
896 KB |
Output is correct |
23 |
Correct |
73 ms |
896 KB |
Output is correct |
24 |
Correct |
65 ms |
992 KB |
Output is correct |
25 |
Correct |
62 ms |
896 KB |
Output is correct |
26 |
Correct |
76 ms |
896 KB |
Output is correct |
27 |
Correct |
94 ms |
896 KB |
Output is correct |
28 |
Correct |
86 ms |
896 KB |
Output is correct |
29 |
Correct |
88 ms |
896 KB |
Output is correct |
30 |
Correct |
90 ms |
996 KB |
Output is correct |
31 |
Correct |
110 ms |
896 KB |
Output is correct |
32 |
Correct |
133 ms |
896 KB |
Output is correct |
33 |
Correct |
141 ms |
896 KB |
Output is correct |
34 |
Correct |
102 ms |
996 KB |
Output is correct |
35 |
Correct |
115 ms |
1176 KB |
Output is correct |
36 |
Correct |
102 ms |
992 KB |
Output is correct |