# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
315251 | dCoding | Nautilus (BOI19_nautilus) | C++17 | 1086 ms | 504 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;
#define ll long long
#define F first
#define S second
const int MAXN=505;
char grid[MAXN][MAXN];
char str[MAXN];
int n,m,k;
bool ok[MAXN][MAXN];
void dfs(int x,int y,int idx) {
if(x<0||y<0||x>=n||y>=m||grid[x][y]=='#') return;
if(idx==k) {
ok[x][y]=true;
return;
}
if(str[idx]=='N') dfs(x-1,y,idx+1);
else if(str[idx]=='S') dfs(x+1,y,idx+1);
else if(str[idx]=='E') dfs(x,y+1,idx+1);
else if(str[idx]=='W') dfs(x,y-1,idx+1);
else {
dfs(x-1,y,idx+1);
dfs(x+1,y,idx+1);
dfs(x,y+1,idx+1);
dfs(x,y-1,idx+1);
}
}
int main() {
scanf("%d%d%d",&n,&m,&k);
for(int i=0;i<n;i++) scanf("%s",grid[i]);
scanf("%s",str);
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
dfs(i,j,0);
}
}
int ans=0;
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
ans+=ok[i][j];
}
}
printf("%d",ans);
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
*/
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... |