# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
55391 |
2018-07-07T06:40:13 Z |
김세빈(#1545) |
Sandwich (JOI16_sandwich) |
C++11 |
|
2540 ms |
15056 KB |
#include <bits/stdc++.h>
using namespace std;
char str[444][444];
bool chk[444][444][2], res[444][444][2];
int K[444];
int n, m, k;
void run(int i, int j, int d)
{
if(chk[i][j][!d]) k = 1e9;
else if(chk[i][j][d]){
if(!res[i][j][d]) k = 1e9;
return;
}
if(k >= 1e9) return;
chk[i][j][d] = 1;
k += 2;
if(str[i][j] == 'N'){
if(d == 0){
if(j) run(i, j-1, 0);
if(i+1 < n) run(i+1, j, str[i+1][j] == 'Z');
}
else{
if(j+1 < m) run(i, j+1, 1);
if(i) run(i-1, j, str[i-1][j] == 'N');
}
}
else{
if(d == 0){
if(j) run(i, j-1, 0);
if(i) run(i-1, j, str[i-1][j] == 'N');
}
else{
if(j+1 < m) run(i, j+1, 1);
if(i+1 < n) run(i+1, j, str[i+1][j] == 'Z');
}
}
res[i][j][d] = 1;
}
int main()
{
int i, j;
scanf("%d%d", &n, &m);
for(i=0;i<n;i++){
scanf("%s", str[i]);
}
for(i=0;i<n;i++){
for(j=k=0;j<n*m;j++){
chk[j/m][j%m][0] = chk[j/m][j%m][1] = 0;
res[j/m][j%m][0] = res[j/m][j%m][1] = 0;
}
for(j=0;j<m;j++){
if(k < 1e9 && !chk[i][j][0]) run(i, j, 0);
K[j] = k;
}
for(j=k=0;j<n*m;j++){
chk[j/m][j%m][0] = chk[j/m][j%m][1] = 0;
res[j/m][j%m][0] = res[j/m][j%m][1] = 0;
}
for(j=m-1;j>=0;j--){
if(k < 1e9 && !chk[i][j][1]) run(i, j, 1);
K[j] = min(k, K[j]);
}
for(j=0;j<m;j++){
printf("%d ", K[j] < 1e9? K[j] : -1);
}
printf("\n");
}
return 0;
}
Compilation message
sandwich.cpp: In function 'int main()':
sandwich.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
sandwich.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", str[i]);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
564 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
3 ms |
572 KB |
Output is correct |
6 |
Correct |
4 ms |
572 KB |
Output is correct |
7 |
Correct |
5 ms |
624 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
5 ms |
732 KB |
Output is correct |
10 |
Correct |
5 ms |
792 KB |
Output is correct |
11 |
Correct |
6 ms |
792 KB |
Output is correct |
12 |
Correct |
5 ms |
792 KB |
Output is correct |
13 |
Correct |
7 ms |
828 KB |
Output is correct |
14 |
Correct |
7 ms |
828 KB |
Output is correct |
15 |
Correct |
7 ms |
828 KB |
Output is correct |
16 |
Correct |
6 ms |
828 KB |
Output is correct |
17 |
Correct |
5 ms |
828 KB |
Output is correct |
18 |
Correct |
6 ms |
828 KB |
Output is correct |
19 |
Correct |
6 ms |
828 KB |
Output is correct |
20 |
Correct |
6 ms |
828 KB |
Output is correct |
21 |
Correct |
6 ms |
828 KB |
Output is correct |
22 |
Correct |
7 ms |
828 KB |
Output is correct |
23 |
Correct |
7 ms |
864 KB |
Output is correct |
24 |
Correct |
8 ms |
900 KB |
Output is correct |
25 |
Correct |
9 ms |
904 KB |
Output is correct |
26 |
Correct |
7 ms |
1028 KB |
Output is correct |
27 |
Correct |
7 ms |
1028 KB |
Output is correct |
28 |
Correct |
6 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
564 KB |
Output is correct |
4 |
Correct |
2 ms |
572 KB |
Output is correct |
5 |
Correct |
3 ms |
572 KB |
Output is correct |
6 |
Correct |
4 ms |
572 KB |
Output is correct |
7 |
Correct |
5 ms |
624 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
5 ms |
732 KB |
Output is correct |
10 |
Correct |
5 ms |
792 KB |
Output is correct |
11 |
Correct |
6 ms |
792 KB |
Output is correct |
12 |
Correct |
5 ms |
792 KB |
Output is correct |
13 |
Correct |
7 ms |
828 KB |
Output is correct |
14 |
Correct |
7 ms |
828 KB |
Output is correct |
15 |
Correct |
7 ms |
828 KB |
Output is correct |
16 |
Correct |
6 ms |
828 KB |
Output is correct |
17 |
Correct |
5 ms |
828 KB |
Output is correct |
18 |
Correct |
6 ms |
828 KB |
Output is correct |
19 |
Correct |
6 ms |
828 KB |
Output is correct |
20 |
Correct |
6 ms |
828 KB |
Output is correct |
21 |
Correct |
6 ms |
828 KB |
Output is correct |
22 |
Correct |
7 ms |
828 KB |
Output is correct |
23 |
Correct |
7 ms |
864 KB |
Output is correct |
24 |
Correct |
8 ms |
900 KB |
Output is correct |
25 |
Correct |
9 ms |
904 KB |
Output is correct |
26 |
Correct |
7 ms |
1028 KB |
Output is correct |
27 |
Correct |
7 ms |
1028 KB |
Output is correct |
28 |
Correct |
6 ms |
1028 KB |
Output is correct |
29 |
Correct |
3 ms |
1028 KB |
Output is correct |
30 |
Correct |
8 ms |
1724 KB |
Output is correct |
31 |
Correct |
871 ms |
2624 KB |
Output is correct |
32 |
Correct |
780 ms |
2808 KB |
Output is correct |
33 |
Correct |
236 ms |
2808 KB |
Output is correct |
34 |
Correct |
2204 ms |
3320 KB |
Output is correct |
35 |
Correct |
1218 ms |
3320 KB |
Output is correct |
36 |
Correct |
36 ms |
3320 KB |
Output is correct |
37 |
Correct |
2058 ms |
3584 KB |
Output is correct |
38 |
Correct |
1515 ms |
3740 KB |
Output is correct |
39 |
Correct |
2007 ms |
3740 KB |
Output is correct |
40 |
Correct |
2540 ms |
4256 KB |
Output is correct |
41 |
Correct |
888 ms |
4256 KB |
Output is correct |
42 |
Correct |
2182 ms |
4536 KB |
Output is correct |
43 |
Correct |
2376 ms |
4740 KB |
Output is correct |
44 |
Correct |
2184 ms |
4884 KB |
Output is correct |
45 |
Correct |
2293 ms |
4884 KB |
Output is correct |
46 |
Correct |
1534 ms |
5036 KB |
Output is correct |
47 |
Correct |
1576 ms |
5036 KB |
Output is correct |
48 |
Correct |
1082 ms |
5036 KB |
Output is correct |
49 |
Correct |
1478 ms |
5316 KB |
Output is correct |
50 |
Correct |
1620 ms |
5468 KB |
Output is correct |
51 |
Correct |
1376 ms |
5648 KB |
Output is correct |
52 |
Correct |
1621 ms |
5808 KB |
Output is correct |
53 |
Correct |
1625 ms |
5912 KB |
Output is correct |
54 |
Correct |
1555 ms |
6060 KB |
Output is correct |
55 |
Correct |
1537 ms |
6424 KB |
Output is correct |
56 |
Correct |
1490 ms |
6520 KB |
Output is correct |
57 |
Correct |
1282 ms |
6520 KB |
Output is correct |
58 |
Correct |
2324 ms |
7128 KB |
Output is correct |
59 |
Correct |
2300 ms |
7128 KB |
Output is correct |
60 |
Correct |
1426 ms |
7128 KB |
Output is correct |
61 |
Correct |
2215 ms |
7344 KB |
Output is correct |
62 |
Correct |
2068 ms |
14808 KB |
Output is correct |
63 |
Correct |
2097 ms |
15056 KB |
Output is correct |