This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
namespace
{
} // namespace
using BS = bitset<250'000>;
void solve()
{
int r, c, m;
cin >> r >> c >> m;
vector<string> grid(r);
for (string &row : grid)
cin >> row;
string s;
cin >> s;
auto idx = [&](int i, int j) -> int
{ return c * i + j; };
BS base;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
if (grid[i][j] == '.')
{
int k = idx(i, j);
base[k] = 1;
}
}
}
BS lft = base, rgt = base;
for (int i = 0; i < r; i++)
lft[i * c] = 0;
for (int i = 0; i < r; i++)
rgt[i * c + c - 1] = 0;
BS can = base;
for (char x : s)
{
if (x == 'N')
can = (can << r) & base;
else if (x == 'E')
can = ((can & lft) << 1) & base;
else if (x == 'W')
can = ((can & rgt) >> 1) & base;
else if (x == 'S')
can = (can >> r) & base;
else
can = ((can << r) | ((can & lft) << 1) | ((can & rgt) >> 1) | (can >> r)) & base;
}
cout << can.count() << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
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... |