이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ll inf = 1e9;
const ld eps = 1e-8;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, m, q;
cin >> n >> m >> q;
vector<vector<char>> w(n, vector<char>(m));
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
cin >> w[i][j];
}
}
vector<bitset<502>> a(n), newa, bad(n);
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < m; j++) {
if (w[i][j] == '.') {
a[i][j + 1] = 1;
} else {
bad[i][j + 1] = 1;
}
}
bad[i][0] = 1;
bad[i][m + 1] = 1;
}
for (ll qw = 0; qw < q; qw++) {
char t;
cin >> t;
if (t == 'E') {
for (ll i = 0; i < n; i++) {
a[i] <<= 1;
a[i] &= ~bad[i];
}
} else if (t == 'W') {
for (ll i = 0; i < n; i++) {
a[i] >>= 1;
a[i] &= ~bad[i];
}
} else if (t == 'N') {
for (ll i = 0; i < n - 1; i++) {
a[i] = a[i + 1];
a[i] &= ~bad[i];
}
a[n - 1] = 0;
} else if (t == 'S') {
for (ll i = n - 1; i > 0; i--) {
a[i] = a[i - 1];
a[i] &= ~bad[i];
}
a[0] = 0;
} else {
newa = a;
for (ll i = 0; i < n; i++) {
newa[i] = (a[i] >> 1);
newa[i] |= (a[i] << 1);
if (i > 0) {
newa[i] |= a[i - 1];
}
if (i < n - 1) {
newa[i] |= a[i + 1];
}
newa[i] &= ~bad[i];
}
a = newa;
}
/*for(ll i = 0; i < n; i++) {
for(ll j = 1; j < m + 1; j++) {
cout << a[i][j];
}
cout << endl;
}
cout << endl << endl;*/
}
ll res = 0;
for (ll i = 0; i < n; i++) {
res += a[i].count();
}
cout << res << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |