답안 #315251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315251 2020-10-22T06:37:32 Z dCoding Nautilus (BOI19_nautilus) C++17
29 / 100
1000 ms 504 KB
#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

nautilus.cpp: In function 'int main()':
nautilus.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
nautilus.cpp:33:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  for(int i=0;i<n;i++) scanf("%s",grid[i]);
      |                       ~~~~~^~~~~~~~~~~~~~
nautilus.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf("%s",str);
      |  ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Execution timed out 1086 ms 504 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Execution timed out 1086 ms 504 KB Time limit exceeded
8 Halted 0 ms 0 KB -