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>
#define int int64_t
using namespace std;
signed main()
{
int r, c, m;
cin >> r >> c >> m;
vector<vector<bool>> tab;
vector<vector<bool>> st(r, vector<bool>(c));
vector<vector<bool>> old(r, vector<bool>(c));
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;
// reverse(seq.begin(), seq.end());
for (int i = 0; i < m; i++)
{
if (seq[i] == 'N') seq[i] = 'S';
else if (seq[i] == 'S') seq[i] = 'N';
else if (seq[i] == 'E') seq[i] = 'W';
else if (seq[i] == 'W') seq[i] = 'E';
}
for (int t = 0; t < m; t++)
{
swap(old, tab);
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
tab[i][j] = false;
if (seq[t] == 'N' || seq[t] == '?') tab[i][j] = tab[i][j] || ((i - 1 >= 0) ? old[i - 1][j] : false);
if (seq[t] == 'W' || seq[t] == '?') tab[i][j] = tab[i][j] || ((j - 1 >= 0) ? old[i][j - 1] : false);
if (seq[t] == 'S' || seq[t] == '?') tab[i][j] = tab[i][j] || ((i + 1 < r) ? old[i + 1][j] : false);
if (seq[t] == 'E' || seq[t] == '?') tab[i][j] = tab[i][j] || ((j + 1 < c) ? old[i][j + 1] : false);
tab[i][j] = tab[i][j] && st[i][j];
}
}
/*
for (auto v : tab)
{
for (auto j : v)
{
cout << j << " ";
}
cout << "\n";
}
cout << "\n";
*/
}
int res = 0;
for (auto v : tab) for (auto j : v) res += j;
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... |