이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 500 + 1;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int r , c , m;
cin >> r >> c >> m;
vector<vector<char>> g(r , vector<char> (c));
for (int i = 0 ; i < r ; i++) {
for (int j = 0 ; j < c ; j++) {
cin >> g[i][j];
}
}
string s;
cin >> s;
vector<bitset<Maxn>> cur(r) , forbidden(r);
bitset<Maxn> Fixer;
for (int i = 0 ; i < c ; i++) {
Fixer[i] = 1;
}
auto Move_Up = [&]() {
vector<bitset<Maxn>> res(r);
for (int i = 0 ; i < r - 1 ; i++) {
res[i] |= cur[i + 1];
}
vector<bitset<Maxn>> t = res;
for (int i = 0 ; i < r ; i++) {
t[i] ^= forbidden[i];
}
for (int i = 0 ; i < r ; i++) {
res[i] &= t[i];
}
return res;
};
auto Move_Down = [&]() {
vector<bitset<Maxn>> res(r);
for (int i = 1 ; i < r ; i++) {
res[i] |= cur[i - 1];
}
vector<bitset<Maxn>> t = res;
for (int i = 0 ; i < r ; i++) {
t[i] ^= forbidden[i];
}
for (int i = 0 ; i < r ; i++) {
res[i] &= t[i];
}
return res;
};
auto Move_Left = [&]() {
vector<bitset<Maxn>> res(r);
for (int i = 0 ; i < r ; i++) {
res[i] = (cur[i] >> 1);
}
vector<bitset<Maxn>> t = res;
for (int i = 0 ; i < r ; i++) {
t[i] ^= forbidden[i];
}
for (int i = 0 ; i < r ; i++) {
res[i] &= t[i];
}
return res;
};
auto Move_Right = [&]() {
vector<bitset<Maxn>> res(r);
for (int i = 0 ; i < r ; i++) {
res[i] = (cur[i] << 1);
}
vector<bitset<Maxn>> t = res;
for (int i = 0 ; i < r ; i++) {
t[i] ^= forbidden[i];
}
for (int i = 0 ; i < r ; i++) {
res[i] &= t[i];
}
return res;
};
auto Fix = [&]() {
for (int i = 0 ; i < r ; i++) {
cur[i] &= Fixer;
}
return ;
};
for (int i = 0 ; i < r ; i++) {
for (int j = 0 ; j < c ; j++) {
if (g[i][j] != '#') cur[i][j] = true;
else forbidden[i][j] = true;
}
}
for (int idx = 0 ; idx < m ; idx++) {
vector<bitset<Maxn>> res(r);
if (s[idx] == 'N') {
res = Move_Up();
}
else if (s[idx] == 'S') {
res = Move_Down();
}
else if (s[idx] == 'E') {
res = Move_Right();
}
else if (s[idx] == 'W') {
res = Move_Left();
}
else {
vector<bitset<Maxn>> A = Move_Down();
vector<bitset<Maxn>> B = Move_Left();
vector<bitset<Maxn>> C = Move_Right();
vector<bitset<Maxn>> D = Move_Up();
for (int i = 0 ; i < r ; i++) {
res[i] |= A[i];
res[i] |= B[i];
res[i] |= C[i];
res[i] |= D[i];
}
}
swap(cur , res);
Fix();
}
int ans = 0;
for (int i = 0 ; i < r ; i++) {
for (int j = 0 ; j < c ; j++) {
if (cur[i][j]) {
assert(g[i][j] != '#');
ans += 1;
}
}
}
cout << ans << '\n';
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... |