//bit chass 1
#include <bits/stdc++.h>
#define x first
#define y second
#define el "\n"
#define ll long long
#define pb push_back
#define pll pair <ll, ll>
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define lcm(x,y) x * y / __gcd(x, y)
#define ibase ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
const int N = 3e5 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300;
const ll MI = 2e18;
const double P = 3.14;
string s[505];
void solve() {
int r, c, m, x = 0, y = 0;
cin >> r >> c >> m;
for (int i = 0; i < r; i++)
cin >> s[i];
int ans= 0;
string a;
cin >> a;
for (int i = 0; i < m; i++) {
if (a[i] == 'N')
x--;
if (a[i] == 'S')
x++;
if (a[i] == 'W')
y--;
if (a[i] == 'E')
y++;
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (0 <= i + x && i + x < r && 0 <= j + y && j + y < c && s[i][j] == '.' && s[i + x][j + y] == '.') {
bool ok = 0;
int q = i, w = j;
for (int k = 0; k < m; k++) {
if (a[k] == 'N') {
if (q == 0 || s[q - 1][w] == '#')
break;
q--;
}
if (a[k] == 'S') {
q++;
if (q == r || s[q][w] == '#')
break;
}
if (a[k] == 'W') {
if (w == 0 || s[q][w - 1] == '#')
break;
w--;
}
if (a[k] == 'E') {
w++;
if (w == c || s[q][w] == '#')
break;
}
if (k == m - 1)
ok = 1;
}
if (ok)
ans++;
}
}
}
cout << ans;
}
int main() {
ibase;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
// cout << "Case " << i << ": ";
solve();
cout << el;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Incorrect |
3 ms |
352 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Incorrect |
3 ms |
352 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |