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;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define piii pair<int, pair<int, int>
#define v(int) vector<int>
#define si size()
#define foe(i,a,b) for(int i=a;i<=b;++i)
#define fol(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define Bit(mask,i) (1<<i)&mask
#define offBit(mask,i) (1<<i)^mask
#define onBit(mask,i) (1<<i)mask
#define CNT(x) __builtin_popcountll(x)
const ll int mod = 1e9+7;
const ll int base = 2309;
const ll int inf = 1e18;
const int N = 505;
const int LG = 20;
// ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄▄ ▄ ▄▄▄▄
// █▄▄█ █ █ █ █ █▄▄█ █ █ ██ █ █ ▄▄
// █ █ █▄▄█ █▄▄█ █ █ █▄▄█ █ ██ █▄▄█
ll n, m, k;
char a[N][N];
string s;
bitset<N> dp[N];
bitset<N> lst[N];
bitset<N> b[N];
ll ans = 0;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
foe(i,1,n)
{
foe(j,1,m)
{
cin >> a[i][j];
if (a[i][j] == '.')
{
b[i][j] = true;
dp[i][j] = true;
}
}
}
cin >> s;
fol(c,0,s.si)
{
foe(i,1,n)
{
lst[i] = dp[i];
dp[i] = 0;
}
foe(i,1,n)
{
if (s[c] == 'N' || s[c] == '?')
{
dp[i - 1] |= (lst[i] & b[i - 1]);
}
if (s[c] == 'E' || s[c] == '?')
{
dp[i] |= ((lst[i] << 1) & b[i]);
}
if (s[c] == 'S' || s[c] == '?')
{
dp[i + 1] |= (lst[i] & b[i + 1]);
}
if (s[c] == 'W' || s[c] == '?')
{
dp[i] |= ((lst[i] >> 1) & b[i]);
}
}
}
foe(i,1,n)
{
foe(j,1,m)
{
ans += dp[i][j];
}
}
cout << ans << endl;
}
Compilation message (stderr)
nautilus.cpp: In function 'int main()':
nautilus.cpp:13:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | #define fol(i,a,b) for(int i=a;i<b;++i)
| ^
nautilus.cpp:54:2: note: in expansion of macro 'fol'
54 | fol(c,0,s.si)
| ^~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |