#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pii pair<int,pi>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) (int) a.size()
#define endl '\n'
#define data "Nautilus"
using namespace std;
const ll linf = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7, N = 5e3;
void add(int &a, int b)
{
a += b;
if(a>=MOD)
a-=MOD;
if(a<0)
a += MOD;
}
int modulo(int x)
{
if(x<=1)
return 1;
return (MOD - MOD/x) * modulo(MOD/x) % MOD;
}
int mul(int a, int b)
{
return (1ll *a%MOD * b%MOD) % MOD;
}
/// N E S W
int dx[] = {+1, 0, -1, 0};
int dy[] = {0, -1, 0, +1};
int row, col, m;
char a[N+3][N+3];
bitset<503> dp[503][N+3];
string s;
void inp(void)
{
cin >> row >> col >> m;
FOR(i, 1, row)
{
FOR(j, 1, col) cin >> a[i][j];
}
cin >> s;
s = ' ' + s;
}
void solve(void)
{
FOR(i, 1, row)
{
FOR(j, 1, col) dp[i][0][j] = (a[i][j] == '.');
}
FOR(t, 1, m)
{
FOR(i, 1, row)
{
if(s[t] == 'N')
dp[i][t] = (dp[i+1][t-1] & dp[i][0]);
else if(s[t] == 'E')
dp[i][t] = (dp[i][t-1] << 1) & (dp[i][0]);
else if(s[t] == 'S')
dp[i][t] = (dp[i-1][t-1] & dp[i][0]);
else if(s[t] == 'W')
dp[i][t] = (dp[i][t-1] >> 1) & (dp[i][0]);
else
{
dp[i][t] |= (dp[i+1][t-1] & dp[i][0]);
dp[i][t] |= (dp[i][t-1] << 1) & (dp[i][0]);
dp[i][t] |= (dp[i-1][t-1] & dp[i][0]);
dp[i][t] |= (dp[i][t-1] >> 1) & (dp[i][0]);
}
}
}
int ans = 0;
FOR(i, 1, row)
{
ans += dp[i][m].count();
}
cout << ans;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(data".inp", "r"))
{
freopen(data".inp","r",stdin);
freopen(data".out","w",stdout);
}
inp();
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
nautilus.cpp: In function 'int main()':
nautilus.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen(data".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | freopen(data".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |