답안 #163186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163186 2019-11-11T17:50:19 Z TadijaSebez Sandwich (JOI16_sandwich) C++11
100 / 100
5159 ms 10720 KB
#include <bits/stdc++.h>
using namespace std;
const int N=405;
const int inf=N*N*2;
char mat[N][N];
int mv[4][2]={{0,1},{-1,0},{0,-1},{1,0}};
int was[N][N],sum,ans[N][N];
void DFS(int x, int y, int dir)
{
	if(mat[x][y]!='N' && mat[x][y]!='Z') return;
	if(was[x][y]==2) return;
	if(was[x][y]==1){ sum=inf;return;}
	int xr;sum+=2;
	if(mat[x][y]=='N') xr=1;
	else xr=3;
	was[x][y]=1;
	DFS(x+mv[dir][0],y+mv[dir][1],dir);
	DFS(x+mv[dir^xr][0],y+mv[dir^xr][1],dir^xr);
	was[x][y]=2;
}
void cl(){ for(int i=0;i<N;i++) for(int j=0;j<N;j++) was[i][j]=0;sum=0;}
int main()
{
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",mat[i]+1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			DFS(i,j,2);
			ans[i][j]=sum;
		}
		cl();
		for(int j=m;j>=1;j--)
		{
			DFS(i,j,0);
			ans[i][j]=min(ans[i][j],sum);
		}
		cl();
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
		if(ans[i][j]>=inf) printf("-1 ");
		else printf("%i ",ans[i][j]);
		if(j==m) printf("\n");
	}
	return 0;
}

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
sandwich.cpp:26:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%s",mat[i]+1);
                        ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 11 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 12 ms 1144 KB Output is correct
6 Correct 45 ms 1144 KB Output is correct
7 Correct 14 ms 1016 KB Output is correct
8 Correct 15 ms 1144 KB Output is correct
9 Correct 14 ms 1016 KB Output is correct
10 Correct 18 ms 1144 KB Output is correct
11 Correct 18 ms 1144 KB Output is correct
12 Correct 11 ms 1144 KB Output is correct
13 Correct 17 ms 1144 KB Output is correct
14 Correct 17 ms 1144 KB Output is correct
15 Correct 14 ms 1116 KB Output is correct
16 Correct 13 ms 1080 KB Output is correct
17 Correct 13 ms 1016 KB Output is correct
18 Correct 13 ms 1016 KB Output is correct
19 Correct 13 ms 1016 KB Output is correct
20 Correct 15 ms 1144 KB Output is correct
21 Correct 13 ms 1144 KB Output is correct
22 Correct 13 ms 1272 KB Output is correct
23 Correct 13 ms 1016 KB Output is correct
24 Correct 17 ms 1016 KB Output is correct
25 Correct 17 ms 1016 KB Output is correct
26 Correct 16 ms 1016 KB Output is correct
27 Correct 15 ms 1096 KB Output is correct
28 Correct 16 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 11 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 12 ms 1144 KB Output is correct
6 Correct 45 ms 1144 KB Output is correct
7 Correct 14 ms 1016 KB Output is correct
8 Correct 15 ms 1144 KB Output is correct
9 Correct 14 ms 1016 KB Output is correct
10 Correct 18 ms 1144 KB Output is correct
11 Correct 18 ms 1144 KB Output is correct
12 Correct 11 ms 1144 KB Output is correct
13 Correct 17 ms 1144 KB Output is correct
14 Correct 17 ms 1144 KB Output is correct
15 Correct 14 ms 1116 KB Output is correct
16 Correct 13 ms 1080 KB Output is correct
17 Correct 13 ms 1016 KB Output is correct
18 Correct 13 ms 1016 KB Output is correct
19 Correct 13 ms 1016 KB Output is correct
20 Correct 15 ms 1144 KB Output is correct
21 Correct 13 ms 1144 KB Output is correct
22 Correct 13 ms 1272 KB Output is correct
23 Correct 13 ms 1016 KB Output is correct
24 Correct 17 ms 1016 KB Output is correct
25 Correct 17 ms 1016 KB Output is correct
26 Correct 16 ms 1016 KB Output is correct
27 Correct 15 ms 1096 KB Output is correct
28 Correct 16 ms 1144 KB Output is correct
29 Correct 3 ms 1020 KB Output is correct
30 Correct 77 ms 1784 KB Output is correct
31 Correct 4945 ms 6368 KB Output is correct
32 Correct 5159 ms 6560 KB Output is correct
33 Correct 1154 ms 3044 KB Output is correct
34 Correct 1624 ms 3064 KB Output is correct
35 Correct 1211 ms 2568 KB Output is correct
36 Correct 109 ms 1828 KB Output is correct
37 Correct 1809 ms 3192 KB Output is correct
38 Correct 1661 ms 3064 KB Output is correct
39 Correct 1845 ms 3108 KB Output is correct
40 Correct 3113 ms 10720 KB Output is correct
41 Correct 1123 ms 7024 KB Output is correct
42 Correct 2260 ms 3592 KB Output is correct
43 Correct 2365 ms 3448 KB Output is correct
44 Correct 2396 ms 3440 KB Output is correct
45 Correct 1591 ms 3080 KB Output is correct
46 Correct 1004 ms 3104 KB Output is correct
47 Correct 1442 ms 2956 KB Output is correct
48 Correct 795 ms 2776 KB Output is correct
49 Correct 1091 ms 3064 KB Output is correct
50 Correct 1153 ms 3064 KB Output is correct
51 Correct 1068 ms 2808 KB Output is correct
52 Correct 1048 ms 2936 KB Output is correct
53 Correct 1104 ms 2980 KB Output is correct
54 Correct 1020 ms 3136 KB Output is correct
55 Correct 1126 ms 3064 KB Output is correct
56 Correct 1027 ms 3096 KB Output is correct
57 Correct 840 ms 2724 KB Output is correct
58 Correct 2897 ms 3268 KB Output is correct
59 Correct 3038 ms 3284 KB Output is correct
60 Correct 1987 ms 2944 KB Output is correct
61 Correct 2869 ms 3212 KB Output is correct
62 Correct 1631 ms 3268 KB Output is correct
63 Correct 2430 ms 3280 KB Output is correct