# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
139819 | ae04071 | Nautilus (BOI19_nautilus) | C++11 | 176 ms | 1016 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;
int n,m,l;
bitset<500> dp[2][500];
char arr[501][501],str[5010];
bitset<500> ta[501];
int main() {
scanf("%d%d%d",&n,&m,&l);
for(int i=0;i<n;i++) {
scanf("%s",arr[i]);
for(int j=0;j<m;j++) ta[i][j] = arr[i][j]=='.';
}
scanf("%s",str);
for(int k=0;k<l;k++) {
if(str[k]=='?') str[k] = 15;
else if(str[k]=='S') str[k]=1;
else if(str[k]=='N') str[k]=2;
else if(str[k]=='W') str[k]=4;
else str[k]=8;
}
for(int i=0;i<n;i++) dp[0][i] = ta[i];
int cur=1,pr=0;
for(int k=0;k<l;k++) {
for(int i=0;i<n;i++) dp[cur][i].reset();
for(int i=0;i<n;i++) {
if(i && (str[k]&1)) dp[cur][i] |= dp[pr][i-1];
if(i<n-1 && (str[k]>>1&1)) dp[cur][i] |= dp[pr][i+1];
if(str[k]>>2&1) dp[cur][i] |= (dp[pr][i]>>1);
if(str[k]>>3&1) dp[cur][i] |= (dp[pr][i]<<1);
dp[cur][i] &= ta[i];
}
swap(cur,pr);
}
int ans=0;
for(int i=0;i<n;i++)for(int j=0;j<m;j++) if(dp[pr][i][j]) ans++;
printf("%d\n",ans);
return 0;
}
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... |