# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53467 |
2018-06-30T05:31:50 Z |
김세빈(#1419) |
Mecho (IOI09_mecho) |
C++11 |
|
251 ms |
9468 KB |
#include <bits/stdc++.h>
using namespace std;
char str[808][808];
int D[808][808], P[808][808], Q[1010101];
bool chk[808][808];
int n,k,x,y,z,w,f,r;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main()
{
int i,j,p,q,a,b,s,e;
scanf("%d%d", &n, &k);
for(i=0;i<n;i++){
scanf("%s", str[i]);
for(j=0;j<n;j++){
D[i][j] = 1e9;
if(str[i][j] == 'H'){
D[i][j] = 0;
chk[i][j] = 1;
Q[++f] = i*n+j;
}
else if(str[i][j] == 'M') x = i, y = j;
else if(str[i][j] == 'D') z = i, w = j;
}
}
for(;r<f;){
p = Q[++r] / n, q = Q[r] % n;
for(i=0;i<4;i++){
a = p + dx[i], b = q + dy[i];
if(0 <= a && a < n && 0 <= b && b < n && !chk[a][b] && (str[a][b] == 'G' || str[a][b] == 'M')){
chk[a][b] = 1;
D[a][b] = D[p][q] + k;
Q[++f] = a*n+b;
}
}
}
for(s=0,e=n*n;s<=e;){
for(i=0;i<n;i++){
for(j=0;j<n;j++){
chk[i][j] = 0;
}
}
f = r = 0;
P[x][y] = (s+e>>1) * k;
if(D[x][y] > P[x][y]){
chk[x][y] = 1;
Q[++f] = x*n+y;
}
for(;r<f;){
p = Q[++r] / n, q = Q[r] % n;
for(i=0;i<4;i++){
a = p + dx[i], b = q + dy[i];
if(0 <= a && a < n && 0 <= b && b < n && D[a][b] > P[p][q] + 1 && !chk[a][b] && (str[a][b] == 'G' || str[a][b] == 'D')){
chk[a][b] = 1;
P[a][b] = P[p][q] + 1;
Q[++f] = a*n+b;
}
}
}
if(chk[z][w]) s = (s+e>>1) + 1;
else e = (s+e>>1) - 1;
}
printf("%d\n", s-1);
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:53:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
P[x][y] = (s+e>>1) * k;
~^~
mecho.cpp:72:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(chk[z][w]) s = (s+e>>1) + 1;
~^~
mecho.cpp:73:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else e = (s+e>>1) - 1;
~^~
mecho.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~
mecho.cpp:18: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 |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
544 KB |
Output is correct |
5 |
Correct |
2 ms |
708 KB |
Output is correct |
6 |
Correct |
2 ms |
708 KB |
Output is correct |
7 |
Correct |
108 ms |
8392 KB |
Output is correct |
8 |
Correct |
2 ms |
8392 KB |
Output is correct |
9 |
Correct |
2 ms |
8392 KB |
Output is correct |
10 |
Correct |
2 ms |
8392 KB |
Output is correct |
11 |
Correct |
2 ms |
8392 KB |
Output is correct |
12 |
Correct |
3 ms |
8392 KB |
Output is correct |
13 |
Correct |
3 ms |
8392 KB |
Output is correct |
14 |
Correct |
3 ms |
8392 KB |
Output is correct |
15 |
Correct |
3 ms |
8392 KB |
Output is correct |
16 |
Correct |
2 ms |
8392 KB |
Output is correct |
17 |
Correct |
2 ms |
8392 KB |
Output is correct |
18 |
Correct |
2 ms |
8392 KB |
Output is correct |
19 |
Correct |
3 ms |
8392 KB |
Output is correct |
20 |
Correct |
2 ms |
8392 KB |
Output is correct |
21 |
Correct |
3 ms |
8392 KB |
Output is correct |
22 |
Correct |
3 ms |
8392 KB |
Output is correct |
23 |
Correct |
3 ms |
8392 KB |
Output is correct |
24 |
Correct |
3 ms |
8392 KB |
Output is correct |
25 |
Correct |
3 ms |
8392 KB |
Output is correct |
26 |
Correct |
2 ms |
8392 KB |
Output is correct |
27 |
Correct |
3 ms |
8392 KB |
Output is correct |
28 |
Correct |
3 ms |
8392 KB |
Output is correct |
29 |
Correct |
3 ms |
8392 KB |
Output is correct |
30 |
Correct |
3 ms |
8392 KB |
Output is correct |
31 |
Correct |
2 ms |
8392 KB |
Output is correct |
32 |
Correct |
3 ms |
8392 KB |
Output is correct |
33 |
Correct |
8 ms |
8392 KB |
Output is correct |
34 |
Correct |
10 ms |
8392 KB |
Output is correct |
35 |
Correct |
34 ms |
8392 KB |
Output is correct |
36 |
Correct |
11 ms |
8392 KB |
Output is correct |
37 |
Correct |
11 ms |
8392 KB |
Output is correct |
38 |
Correct |
64 ms |
8392 KB |
Output is correct |
39 |
Correct |
11 ms |
8392 KB |
Output is correct |
40 |
Correct |
14 ms |
8392 KB |
Output is correct |
41 |
Correct |
53 ms |
8392 KB |
Output is correct |
42 |
Correct |
15 ms |
8392 KB |
Output is correct |
43 |
Correct |
15 ms |
8392 KB |
Output is correct |
44 |
Correct |
68 ms |
8392 KB |
Output is correct |
45 |
Correct |
16 ms |
8392 KB |
Output is correct |
46 |
Correct |
19 ms |
8392 KB |
Output is correct |
47 |
Correct |
85 ms |
8392 KB |
Output is correct |
48 |
Correct |
19 ms |
8392 KB |
Output is correct |
49 |
Correct |
21 ms |
8392 KB |
Output is correct |
50 |
Correct |
129 ms |
8392 KB |
Output is correct |
51 |
Correct |
20 ms |
8392 KB |
Output is correct |
52 |
Correct |
27 ms |
8392 KB |
Output is correct |
53 |
Correct |
143 ms |
8392 KB |
Output is correct |
54 |
Correct |
23 ms |
8392 KB |
Output is correct |
55 |
Correct |
26 ms |
8392 KB |
Output is correct |
56 |
Correct |
147 ms |
8392 KB |
Output is correct |
57 |
Correct |
29 ms |
8392 KB |
Output is correct |
58 |
Correct |
30 ms |
8392 KB |
Output is correct |
59 |
Correct |
169 ms |
8392 KB |
Output is correct |
60 |
Correct |
29 ms |
8392 KB |
Output is correct |
61 |
Correct |
39 ms |
8392 KB |
Output is correct |
62 |
Correct |
219 ms |
8912 KB |
Output is correct |
63 |
Correct |
138 ms |
8912 KB |
Output is correct |
64 |
Correct |
251 ms |
8912 KB |
Output is correct |
65 |
Correct |
204 ms |
8912 KB |
Output is correct |
66 |
Correct |
159 ms |
8912 KB |
Output is correct |
67 |
Correct |
147 ms |
8912 KB |
Output is correct |
68 |
Correct |
65 ms |
8912 KB |
Output is correct |
69 |
Correct |
66 ms |
8912 KB |
Output is correct |
70 |
Correct |
50 ms |
8912 KB |
Output is correct |
71 |
Correct |
55 ms |
8912 KB |
Output is correct |
72 |
Correct |
41 ms |
8912 KB |
Output is correct |
73 |
Correct |
46 ms |
9400 KB |
Output is correct |
74 |
Correct |
74 ms |
9424 KB |
Output is correct |
75 |
Correct |
118 ms |
9440 KB |
Output is correct |
76 |
Correct |
79 ms |
9440 KB |
Output is correct |
77 |
Correct |
84 ms |
9468 KB |
Output is correct |
78 |
Correct |
105 ms |
9468 KB |
Output is correct |
79 |
Correct |
65 ms |
9468 KB |
Output is correct |
80 |
Correct |
78 ms |
9468 KB |
Output is correct |
81 |
Correct |
97 ms |
9468 KB |
Output is correct |
82 |
Correct |
93 ms |
9468 KB |
Output is correct |
83 |
Correct |
116 ms |
9468 KB |
Output is correct |
84 |
Correct |
102 ms |
9468 KB |
Output is correct |
85 |
Correct |
108 ms |
9468 KB |
Output is correct |
86 |
Correct |
112 ms |
9468 KB |
Output is correct |
87 |
Correct |
141 ms |
9468 KB |
Output is correct |
88 |
Correct |
111 ms |
9468 KB |
Output is correct |
89 |
Correct |
126 ms |
9468 KB |
Output is correct |
90 |
Correct |
146 ms |
9468 KB |
Output is correct |
91 |
Correct |
118 ms |
9468 KB |
Output is correct |
92 |
Correct |
139 ms |
9468 KB |
Output is correct |