#include <bits/stdc++.h>
using namespace std;
char A[409][409];
int R, C, chk[409][409], s, ans[409][409];
const int INF = 1e9;
/*
0 - up
1 - down
2 - left
3 - right
*/
void go(int x, int y, int d) {
if(x < 1 || x > R || y < 1 || y > C) return;
if(chk[x][y] == 2) return;
if(chk[x][y] == 1) {
s = INF;
return;
}
chk[x][y] = 1; s += 2;
if(A[x][y] == 'N') {
if(d == 0 || d == 3) {go(x-1, y, 0); go(x, y+1, 3);}
if(d == 1 || d == 2) {go(x+1, y, 1); go(x, y-1, 2);}
}
if(A[x][y] == 'Z') {
if(d == 0 || d == 2) {go(x-1, y, 0); go(x, y-1, 2);}
if(d == 1 || d == 3) {go(x+1, y, 1); go(x, y+1, 3);}
}
chk[x][y] = 2;
}
void cl() {
memset(chk, 0, sizeof(chk));
s = 0;
}
int main() {
scanf("%d%d",&R,&C);
for(int i=1; i<=R; i++) {
for(int j=1; j<=C; j++) {
scanf(" %c",&A[i][j]);
}
}
for(int i=1; i<=C; i++) {
for(int j=1; j<=R; j++) {
go(j, i, 0);
ans[j][i] = s;
}
cl();
for(int j=R; j>=1; j--) {
go(j, i, 1);
ans[j][i] = min(s, ans[j][i]);
}
cl();
}
for(int i=1; i<=R; i++) {
for(int j=1; j<=C; j++) {
if(ans[i][j] >= INF) printf("-1 ");
else printf("%d ", ans[i][j]);
}
puts("");
}
return 0;
}
Compilation message
sandwich.cpp: In function 'int main()':
sandwich.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&R,&C);
~~~~~^~~~~~~~~~~~~~
sandwich.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&A[i][j]);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
5 ms |
1024 KB |
Output is correct |
3 |
Correct |
2 ms |
1024 KB |
Output is correct |
4 |
Correct |
3 ms |
1024 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
7 ms |
1152 KB |
Output is correct |
8 |
Correct |
8 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
1024 KB |
Output is correct |
10 |
Correct |
8 ms |
1024 KB |
Output is correct |
11 |
Correct |
8 ms |
1152 KB |
Output is correct |
12 |
Correct |
6 ms |
1024 KB |
Output is correct |
13 |
Correct |
8 ms |
1152 KB |
Output is correct |
14 |
Correct |
8 ms |
1152 KB |
Output is correct |
15 |
Correct |
6 ms |
1152 KB |
Output is correct |
16 |
Correct |
7 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
1152 KB |
Output is correct |
18 |
Correct |
7 ms |
1152 KB |
Output is correct |
19 |
Correct |
6 ms |
1152 KB |
Output is correct |
20 |
Correct |
7 ms |
1152 KB |
Output is correct |
21 |
Correct |
7 ms |
1152 KB |
Output is correct |
22 |
Correct |
7 ms |
1152 KB |
Output is correct |
23 |
Correct |
7 ms |
1152 KB |
Output is correct |
24 |
Correct |
8 ms |
1144 KB |
Output is correct |
25 |
Correct |
8 ms |
1152 KB |
Output is correct |
26 |
Correct |
8 ms |
1152 KB |
Output is correct |
27 |
Correct |
8 ms |
1024 KB |
Output is correct |
28 |
Correct |
8 ms |
1124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1024 KB |
Output is correct |
2 |
Correct |
5 ms |
1024 KB |
Output is correct |
3 |
Correct |
2 ms |
1024 KB |
Output is correct |
4 |
Correct |
3 ms |
1024 KB |
Output is correct |
5 |
Correct |
3 ms |
1152 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
7 ms |
1152 KB |
Output is correct |
8 |
Correct |
8 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
1024 KB |
Output is correct |
10 |
Correct |
8 ms |
1024 KB |
Output is correct |
11 |
Correct |
8 ms |
1152 KB |
Output is correct |
12 |
Correct |
6 ms |
1024 KB |
Output is correct |
13 |
Correct |
8 ms |
1152 KB |
Output is correct |
14 |
Correct |
8 ms |
1152 KB |
Output is correct |
15 |
Correct |
6 ms |
1152 KB |
Output is correct |
16 |
Correct |
7 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
1152 KB |
Output is correct |
18 |
Correct |
7 ms |
1152 KB |
Output is correct |
19 |
Correct |
6 ms |
1152 KB |
Output is correct |
20 |
Correct |
7 ms |
1152 KB |
Output is correct |
21 |
Correct |
7 ms |
1152 KB |
Output is correct |
22 |
Correct |
7 ms |
1152 KB |
Output is correct |
23 |
Correct |
7 ms |
1152 KB |
Output is correct |
24 |
Correct |
8 ms |
1144 KB |
Output is correct |
25 |
Correct |
8 ms |
1152 KB |
Output is correct |
26 |
Correct |
8 ms |
1152 KB |
Output is correct |
27 |
Correct |
8 ms |
1024 KB |
Output is correct |
28 |
Correct |
8 ms |
1124 KB |
Output is correct |
29 |
Correct |
29 ms |
1024 KB |
Output is correct |
30 |
Correct |
4 ms |
1840 KB |
Output is correct |
31 |
Correct |
3377 ms |
7568 KB |
Output is correct |
32 |
Correct |
3649 ms |
7416 KB |
Output is correct |
33 |
Correct |
256 ms |
3192 KB |
Output is correct |
34 |
Correct |
706 ms |
2936 KB |
Output is correct |
35 |
Correct |
618 ms |
2660 KB |
Output is correct |
36 |
Correct |
6 ms |
1792 KB |
Output is correct |
37 |
Correct |
900 ms |
2908 KB |
Output is correct |
38 |
Correct |
879 ms |
2940 KB |
Output is correct |
39 |
Correct |
874 ms |
2908 KB |
Output is correct |
40 |
Correct |
1264 ms |
3196 KB |
Output is correct |
41 |
Correct |
764 ms |
2296 KB |
Output is correct |
42 |
Correct |
1169 ms |
3576 KB |
Output is correct |
43 |
Correct |
1202 ms |
3448 KB |
Output is correct |
44 |
Correct |
1104 ms |
3576 KB |
Output is correct |
45 |
Correct |
636 ms |
2928 KB |
Output is correct |
46 |
Correct |
488 ms |
2908 KB |
Output is correct |
47 |
Correct |
559 ms |
2808 KB |
Output is correct |
48 |
Correct |
306 ms |
2552 KB |
Output is correct |
49 |
Correct |
444 ms |
2932 KB |
Output is correct |
50 |
Correct |
564 ms |
2812 KB |
Output is correct |
51 |
Correct |
453 ms |
2936 KB |
Output is correct |
52 |
Correct |
522 ms |
2936 KB |
Output is correct |
53 |
Correct |
466 ms |
2936 KB |
Output is correct |
54 |
Correct |
481 ms |
2808 KB |
Output is correct |
55 |
Correct |
490 ms |
2936 KB |
Output is correct |
56 |
Correct |
491 ms |
2936 KB |
Output is correct |
57 |
Correct |
369 ms |
2684 KB |
Output is correct |
58 |
Correct |
1195 ms |
3960 KB |
Output is correct |
59 |
Correct |
1179 ms |
3704 KB |
Output is correct |
60 |
Correct |
842 ms |
3320 KB |
Output is correct |
61 |
Correct |
1456 ms |
8056 KB |
Output is correct |
62 |
Correct |
1285 ms |
2936 KB |
Output is correct |
63 |
Correct |
1281 ms |
3068 KB |
Output is correct |