이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |