//Bismillahir-Rahmanir-Rahim
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)
using namespace std;
const int N = 1e2 + 7;
const int M = 1e3 + 7;
const int maxA = 2e6 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 1e9 + 7;
const ld eps = 1e-9;
pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long
bool a[N][N];
int n, m, k, dp[N][N][N];
bool border(int i, int j) {
return i >= 1 && i <= n && j >= 1 && j <= m;
}
int id[255];
char s[N];
void solve() {
cin >> n >> m >> k;
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
char c;
cin >> c;
a[i][j] = (c == '.' ? 1 : 0);
}
}
for (int i = 1;i <= k;i++)cin >> s[i];
id['W'] = 0, id['N'] = 1, id['E'] = 2, id['S'] = 3;
int ans = 0;
for (int step = 0;step <= k;step++) {
//cout << step << ":\n";
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= m;j++) {
if (!a[i][j]) {
//cout << 0 << ' ';
skip;
}
if (step == 0) {
dp[i][j][0] = 1;
//cout << 1 << ' ';
skip;
}
if (s[step] == '?') {
for (auto p : dir) {
int x = i + p.x, y = j + p.y;
if (border(x, y) && a[x][y])dp[i][j][step] |= dp[x][y][step - 1];
}
}
else {
int x = i + dir[id[s[step]]].x, y = j + dir[id[s[step]]].y;
if (border(x, y) && a[x][y])dp[i][j][step] |= dp[x][y][step - 1];
}
if (step == k)ans += dp[i][j][step];
//cout << dp[i][j][step] << ' ';
}
//cout << '\n';
}
}
cout << ans;
}
signed main() {
//srand(time(NULL));
ios_base::sync_with_stdio(0);
cout.tie(0);
//freopen("tests.in", "r", stdin);
//freopen("milkorder.out", "w", stdout);
int test = 1;
//cin >> test;
for (int t = 1;t <= test;t++) {
//cout << "Case " << t << ": ";
solve();
}
return 0;
}
Compilation message
nautilus.cpp: In function 'void solve()':
nautilus.cpp:76:46: warning: array subscript has type 'char' [-Wchar-subscripts]
76 | int x = i + dir[id[s[step]]].x, y = j + dir[id[s[step]]].y;
| ~~~~~~^
nautilus.cpp:76:74: warning: array subscript has type 'char' [-Wchar-subscripts]
76 | int x = i + dir[id[s[step]]].x, y = j + dir[id[s[step]]].y;
| ~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9308 KB |
Output is correct |
2 |
Correct |
7 ms |
9308 KB |
Output is correct |
3 |
Correct |
10 ms |
9304 KB |
Output is correct |
4 |
Correct |
8 ms |
9356 KB |
Output is correct |
5 |
Correct |
5 ms |
9184 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9308 KB |
Output is correct |
2 |
Correct |
7 ms |
9308 KB |
Output is correct |
3 |
Correct |
10 ms |
9304 KB |
Output is correct |
4 |
Correct |
8 ms |
9356 KB |
Output is correct |
5 |
Correct |
5 ms |
9184 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
9 ms |
9308 KB |
Output is correct |
8 |
Correct |
12 ms |
9392 KB |
Output is correct |
9 |
Correct |
10 ms |
9308 KB |
Output is correct |
10 |
Correct |
5 ms |
9052 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
14 ms |
9308 KB |
Output is correct |
13 |
Correct |
14 ms |
9308 KB |
Output is correct |
14 |
Correct |
15 ms |
9308 KB |
Output is correct |
15 |
Correct |
7 ms |
9304 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
20 ms |
9308 KB |
Output is correct |
18 |
Correct |
19 ms |
9404 KB |
Output is correct |
19 |
Correct |
15 ms |
9336 KB |
Output is correct |
20 |
Correct |
6 ms |
9052 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9308 KB |
Output is correct |
2 |
Correct |
7 ms |
9308 KB |
Output is correct |
3 |
Correct |
10 ms |
9304 KB |
Output is correct |
4 |
Correct |
8 ms |
9356 KB |
Output is correct |
5 |
Correct |
5 ms |
9184 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
9 ms |
9308 KB |
Output is correct |
8 |
Correct |
12 ms |
9392 KB |
Output is correct |
9 |
Correct |
10 ms |
9308 KB |
Output is correct |
10 |
Correct |
5 ms |
9052 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
14 ms |
9308 KB |
Output is correct |
13 |
Correct |
14 ms |
9308 KB |
Output is correct |
14 |
Correct |
15 ms |
9308 KB |
Output is correct |
15 |
Correct |
7 ms |
9304 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
20 ms |
9308 KB |
Output is correct |
18 |
Correct |
19 ms |
9404 KB |
Output is correct |
19 |
Correct |
15 ms |
9336 KB |
Output is correct |
20 |
Correct |
6 ms |
9052 KB |
Output is correct |
21 |
Correct |
1 ms |
4696 KB |
Output is correct |
22 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |