# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
207060 | gratus907 | Nautilus (BOI19_nautilus) | C++17 | 1048 ms | 1632 KiB |
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("Ofast")
int r, c, m;
char message[5050];
bool dp[2][550][550];
char mp[550][550];
bool bd[550][550];
int32_t main()
{
scanf("%d %d %d\n",&r,&c,&m);
for (int i = 1; i<=r; i++)
scanf(" %s",&mp[i][1]);
scanf(" %s",message+1);
for (int i = 1; i<=r; i++)
for (int j = 1; j<=c; j++)
bd[i][j] = (mp[i][j]=='#'?0:1);
memcpy(dp[0],bd,sizeof(dp[0]));
for (int id = 1; id<=m; id++)
{
int t = id%2, b = 1-t;
memcpy(dp[t],bd,sizeof(dp[t]));
if (message[id] == 'E')
{
for (int i = 1; i<=r; i++)
for (int j = 1; j<=c; j++)
dp[t][i][j] &= dp[b][i][j-1];
}
else if (message[id] == 'W')
{
for (int i = 1; i<=r; i++)
for (int j = 1; j<=c; j++)
dp[t][i][j] &= dp[b][i][j+1];
}
else if (message[id] == 'N')
{
for (int i = 1; i<=r; i++)
for (int j = 1; j<=c; j++)
dp[t][i][j] &= dp[b][i+1][j];
}
else if (message[id] == 'S')
{
for (int i = 1; i<=r; i++)
for (int j = 1; j<=c; j++)
dp[t][i][j] &= dp[b][i-1][j];
}
else if (message[id] == '?')
{
for (int i = 1; i<=r; i++)
for (int j = 1; j<=c; j++)
dp[t][i][j] &= dp[b][i+1][j] || dp[b][i-1][j] || dp[b][i][j+1] || dp[b][i][j-1];
}
}
int ans = 0;
for (int i = 1; i<=r; i++)
for (int j = 1; j<=c; j++)
ans += (dp[m%2][i][j]?1:0);
printf("%d\n",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |