This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("-Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#define int int64_t
using namespace std;
signed main()
{
int r, c, m;
cin >> r >> c >> m;
vector<bitset<500>> tab;
vector<bitset<500>> st(r, bitset<500>());
vector<bitset<500>> old(r, bitset<500>());
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
char ch;
cin >> ch;
st[i][j] = (ch == '.');
}
}
tab = st;
string seq;
cin >> seq;
for (int t = 0; t < m; t++)
{
swap(old, tab);
for (int i = 0; i < r; i++)
{
tab[i] = 0;
if ((seq[t] == 'S' || seq[t] == '?') && i > 0) tab[i] = tab[i] | old[i - 1];
if (seq[t] == 'W' || seq[t] == '?') tab[i] = tab[i] | (old[i] >> 1);
if ((seq[t] == 'N' || seq[t] == '?') && i + 1 < r) tab[i] = tab[i] | old[i + 1];
if (seq[t] == 'E' || seq[t] == '?') tab[i] = tab[i] | (old[i] << 1);
tab[i] &= st[i];
}
/*
for (auto v : tab)
{
for (int i = 0; i < 10; i++)
{
cout << v[i];
}
cout << "\n";
}
cout << "\n";
*/
}
int res = 0;
for (auto v : tab) res = res + v.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... |