#include <bits/stdc++.h>
// #define int long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define kill(x) cout << x << endl, exit(0);
#define endl "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)500 + 7;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
int n, m, q, tmp, tmp2, tmp3, tmp4, ans, k, u, v, w, flag;
int arr[MAXN][MAXN], arr2[MAXN][MAXN];
bool bad[MAXN][MAXN];
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
int cnt[][4] = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, {1, 1, 1, 1}};
string s; char ch;
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin >> ch;
arr[i][j] = (ch == '.');
bad[i][j] = (ch == '#');
}
}
cin >> s;
for (int o=1; o<=k; o++) {
// cout << "@" << o-1 << endl;
// for (int i=1; i<=n; i++) {
// for (int j=1; j<=m; j++) cout << arr[i][j] << " ";
// cout << endl;
// }
// cout << endl;
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) arr2[i][j] = arr[i][j];
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) arr[i][j] = 0;
if (s[o-1] == 'N') tmp = 0;
else if (s[o-1] == 'S') tmp = 1;
else if (s[o-1] == 'W') tmp = 2;
else if (s[o-1] == 'E') tmp = 3;
else tmp = 4;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
for (int x=0; x<4; x++) {
int i2 = i+dx[x], j2 = j+dy[x];
if (min(i2, j2) == 0 || i2 > n || j2 > m || !cnt[tmp][x] || bad[i2][j2]) continue;
arr[i2][j2] |= arr2[i][j];
}
}
}
}
ans = 0;
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) ans += arr[i][j];
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2392 KB |
Output is correct |
2 |
Correct |
10 ms |
2396 KB |
Output is correct |
3 |
Correct |
13 ms |
2396 KB |
Output is correct |
4 |
Correct |
13 ms |
2392 KB |
Output is correct |
5 |
Correct |
10 ms |
2392 KB |
Output is correct |
6 |
Correct |
8 ms |
2572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2392 KB |
Output is correct |
2 |
Correct |
10 ms |
2396 KB |
Output is correct |
3 |
Correct |
13 ms |
2396 KB |
Output is correct |
4 |
Correct |
13 ms |
2392 KB |
Output is correct |
5 |
Correct |
10 ms |
2392 KB |
Output is correct |
6 |
Correct |
8 ms |
2572 KB |
Output is correct |
7 |
Correct |
9 ms |
2396 KB |
Output is correct |
8 |
Correct |
16 ms |
2396 KB |
Output is correct |
9 |
Correct |
20 ms |
2576 KB |
Output is correct |
10 |
Correct |
15 ms |
2388 KB |
Output is correct |
11 |
Correct |
9 ms |
2396 KB |
Output is correct |
12 |
Correct |
10 ms |
2576 KB |
Output is correct |
13 |
Correct |
18 ms |
2652 KB |
Output is correct |
14 |
Correct |
22 ms |
2392 KB |
Output is correct |
15 |
Correct |
18 ms |
2392 KB |
Output is correct |
16 |
Correct |
9 ms |
2396 KB |
Output is correct |
17 |
Correct |
11 ms |
2576 KB |
Output is correct |
18 |
Correct |
17 ms |
2396 KB |
Output is correct |
19 |
Correct |
26 ms |
2396 KB |
Output is correct |
20 |
Correct |
17 ms |
2392 KB |
Output is correct |
21 |
Correct |
10 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2392 KB |
Output is correct |
2 |
Correct |
10 ms |
2396 KB |
Output is correct |
3 |
Correct |
13 ms |
2396 KB |
Output is correct |
4 |
Correct |
13 ms |
2392 KB |
Output is correct |
5 |
Correct |
10 ms |
2392 KB |
Output is correct |
6 |
Correct |
8 ms |
2572 KB |
Output is correct |
7 |
Correct |
9 ms |
2396 KB |
Output is correct |
8 |
Correct |
16 ms |
2396 KB |
Output is correct |
9 |
Correct |
20 ms |
2576 KB |
Output is correct |
10 |
Correct |
15 ms |
2388 KB |
Output is correct |
11 |
Correct |
9 ms |
2396 KB |
Output is correct |
12 |
Correct |
10 ms |
2576 KB |
Output is correct |
13 |
Correct |
18 ms |
2652 KB |
Output is correct |
14 |
Correct |
22 ms |
2392 KB |
Output is correct |
15 |
Correct |
18 ms |
2392 KB |
Output is correct |
16 |
Correct |
9 ms |
2396 KB |
Output is correct |
17 |
Correct |
11 ms |
2576 KB |
Output is correct |
18 |
Correct |
17 ms |
2396 KB |
Output is correct |
19 |
Correct |
26 ms |
2396 KB |
Output is correct |
20 |
Correct |
17 ms |
2392 KB |
Output is correct |
21 |
Correct |
10 ms |
2396 KB |
Output is correct |
22 |
Execution timed out |
1081 ms |
2884 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |