# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53477 |
2018-06-30T05:43:56 Z |
시제연(#2016) |
Mecho (IOI09_mecho) |
C++11 |
|
279 ms |
6564 KB |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define X first
#define Y second
const int N = 805, INF = int(1e9), dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int n, s, d[N][N], e[N][N], sx, sy, ex, ey;
queue<pii> q;
char b[N][N];
int f(int x){
q.push({sx, sy});
for(int i = 1; i <= n; i++) fill(e[i] + 1, e[i] + n + 1, INF);
e[sx][sy] = 0;
while(!q.empty()){
pii c = q.front();
q.pop();
for(int i = 0; i < 4; i++){
pii nx = {c.X + dx[i], c.Y + dy[i]};
if(nx.X < 1 || nx.X > n || nx.Y < 1 || nx.Y > n) continue;
if(b[nx.X][nx.Y] != 'G' && b[nx.X][nx.Y] != 'D') continue;
if(e[nx.X][nx.Y] <= e[c.X][c.Y] + 1) continue;
if((e[c.X][c.Y] + 1) / s >= d[nx.X][nx.Y] - x) continue;
e[nx.X][nx.Y] = e[c.X][c.Y] + 1;
q.push(nx);
}
}
return (e[ex][ey] != INF);
}
int main(){
scanf("%d%d", &n, &s);
for(int i = 1; i <= n; i++) scanf("%s", b[i] + 1);
for(int i = 1; i <= n; i++) fill(d[i] + 1, d[i] + n + 1, INF);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(b[i][j] == 'H'){ q.push({i, j}); d[i][j] = 0; }
else if(b[i][j] == 'M'){ sx = i; sy = j; }
else if(b[i][j] == 'D'){ ex = i; ey = j; }
}
}
while(!q.empty()){
pii c = q.front();
q.pop();
for(int i = 0; i < 4; i++){
pii nx = {c.X + dx[i], c.Y + dy[i]};
if(nx.X < 1 || nx.X > n || nx.Y < 1 || nx.Y > n) continue;
if(b[nx.X][nx.Y] != 'G' && b[nx.X][nx.Y] != 'M'&& b[nx.X][nx.Y] != 'D') continue;
if(d[nx.X][nx.Y] <= d[c.X][c.Y] + 1) continue;
d[nx.X][nx.Y] = d[c.X][c.Y] + 1;
q.push(nx);
}
}
int l = 0, r = n * n;
while(l <= r){
int m = (l + r) / 2;
if(f(m)) l = m + 1;
else r = m - 1;
}
printf("%d\n", r);
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &s);
~~~~~^~~~~~~~~~~~~~~~
mecho.cpp:36:38: 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", b[i] + 1);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
396 KB |
Output isn't correct |
3 |
Correct |
2 ms |
472 KB |
Output is correct |
4 |
Incorrect |
3 ms |
472 KB |
Output isn't correct |
5 |
Correct |
2 ms |
640 KB |
Output is correct |
6 |
Incorrect |
5 ms |
708 KB |
Output isn't correct |
7 |
Incorrect |
126 ms |
6264 KB |
Output isn't correct |
8 |
Correct |
2 ms |
6264 KB |
Output is correct |
9 |
Correct |
2 ms |
6264 KB |
Output is correct |
10 |
Correct |
3 ms |
6264 KB |
Output is correct |
11 |
Correct |
3 ms |
6264 KB |
Output is correct |
12 |
Incorrect |
3 ms |
6264 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
6264 KB |
Output isn't correct |
14 |
Correct |
4 ms |
6264 KB |
Output is correct |
15 |
Correct |
2 ms |
6264 KB |
Output is correct |
16 |
Correct |
2 ms |
6264 KB |
Output is correct |
17 |
Correct |
2 ms |
6264 KB |
Output is correct |
18 |
Correct |
3 ms |
6264 KB |
Output is correct |
19 |
Correct |
2 ms |
6264 KB |
Output is correct |
20 |
Correct |
2 ms |
6264 KB |
Output is correct |
21 |
Correct |
2 ms |
6264 KB |
Output is correct |
22 |
Correct |
4 ms |
6264 KB |
Output is correct |
23 |
Correct |
2 ms |
6264 KB |
Output is correct |
24 |
Correct |
3 ms |
6264 KB |
Output is correct |
25 |
Correct |
3 ms |
6264 KB |
Output is correct |
26 |
Correct |
3 ms |
6264 KB |
Output is correct |
27 |
Correct |
3 ms |
6264 KB |
Output is correct |
28 |
Correct |
3 ms |
6264 KB |
Output is correct |
29 |
Correct |
3 ms |
6264 KB |
Output is correct |
30 |
Correct |
3 ms |
6264 KB |
Output is correct |
31 |
Correct |
3 ms |
6264 KB |
Output is correct |
32 |
Correct |
3 ms |
6264 KB |
Output is correct |
33 |
Correct |
8 ms |
6264 KB |
Output is correct |
34 |
Correct |
9 ms |
6264 KB |
Output is correct |
35 |
Correct |
34 ms |
6264 KB |
Output is correct |
36 |
Correct |
10 ms |
6264 KB |
Output is correct |
37 |
Correct |
11 ms |
6264 KB |
Output is correct |
38 |
Correct |
44 ms |
6264 KB |
Output is correct |
39 |
Correct |
15 ms |
6264 KB |
Output is correct |
40 |
Correct |
12 ms |
6264 KB |
Output is correct |
41 |
Correct |
64 ms |
6264 KB |
Output is correct |
42 |
Correct |
15 ms |
6264 KB |
Output is correct |
43 |
Correct |
14 ms |
6264 KB |
Output is correct |
44 |
Correct |
66 ms |
6264 KB |
Output is correct |
45 |
Correct |
15 ms |
6264 KB |
Output is correct |
46 |
Correct |
18 ms |
6264 KB |
Output is correct |
47 |
Correct |
88 ms |
6264 KB |
Output is correct |
48 |
Correct |
19 ms |
6264 KB |
Output is correct |
49 |
Correct |
20 ms |
6264 KB |
Output is correct |
50 |
Correct |
105 ms |
6264 KB |
Output is correct |
51 |
Correct |
20 ms |
6264 KB |
Output is correct |
52 |
Correct |
20 ms |
6264 KB |
Output is correct |
53 |
Correct |
129 ms |
6264 KB |
Output is correct |
54 |
Correct |
23 ms |
6264 KB |
Output is correct |
55 |
Correct |
30 ms |
6264 KB |
Output is correct |
56 |
Correct |
151 ms |
6264 KB |
Output is correct |
57 |
Correct |
29 ms |
6264 KB |
Output is correct |
58 |
Correct |
32 ms |
6264 KB |
Output is correct |
59 |
Correct |
151 ms |
6264 KB |
Output is correct |
60 |
Correct |
28 ms |
6268 KB |
Output is correct |
61 |
Correct |
29 ms |
6268 KB |
Output is correct |
62 |
Correct |
170 ms |
6268 KB |
Output is correct |
63 |
Correct |
129 ms |
6268 KB |
Output is correct |
64 |
Correct |
279 ms |
6312 KB |
Output is correct |
65 |
Correct |
195 ms |
6312 KB |
Output is correct |
66 |
Correct |
158 ms |
6312 KB |
Output is correct |
67 |
Correct |
154 ms |
6312 KB |
Output is correct |
68 |
Correct |
60 ms |
6312 KB |
Output is correct |
69 |
Correct |
59 ms |
6312 KB |
Output is correct |
70 |
Correct |
50 ms |
6312 KB |
Output is correct |
71 |
Correct |
52 ms |
6312 KB |
Output is correct |
72 |
Incorrect |
38 ms |
6312 KB |
Output isn't correct |
73 |
Incorrect |
54 ms |
6524 KB |
Output isn't correct |
74 |
Correct |
68 ms |
6528 KB |
Output is correct |
75 |
Correct |
85 ms |
6528 KB |
Output is correct |
76 |
Correct |
78 ms |
6528 KB |
Output is correct |
77 |
Correct |
72 ms |
6528 KB |
Output is correct |
78 |
Correct |
120 ms |
6532 KB |
Output is correct |
79 |
Correct |
92 ms |
6532 KB |
Output is correct |
80 |
Correct |
89 ms |
6532 KB |
Output is correct |
81 |
Correct |
84 ms |
6532 KB |
Output is correct |
82 |
Correct |
71 ms |
6532 KB |
Output is correct |
83 |
Correct |
141 ms |
6532 KB |
Output is correct |
84 |
Correct |
118 ms |
6532 KB |
Output is correct |
85 |
Correct |
134 ms |
6564 KB |
Output is correct |
86 |
Correct |
125 ms |
6564 KB |
Output is correct |
87 |
Correct |
114 ms |
6564 KB |
Output is correct |
88 |
Correct |
115 ms |
6564 KB |
Output is correct |
89 |
Correct |
111 ms |
6564 KB |
Output is correct |
90 |
Correct |
126 ms |
6564 KB |
Output is correct |
91 |
Correct |
114 ms |
6564 KB |
Output is correct |
92 |
Correct |
123 ms |
6564 KB |
Output is correct |