# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53463 |
2018-06-30T05:27:33 Z |
강태규(#1417) |
Mecho (IOI09_mecho) |
C++11 |
|
250 ms |
8828 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
const int inf = 1e8;
int n, sd, sx, sy;
char grid[800][801];
int dist[800][800];
int bdst[800][800];
int que[800 * 800];
const int gox[4] = { 1, 0, -1, 0 };
const int goy[4] = { 0, 1, 0, -1 };
int check(int t) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
bdst[i][j] = inf;
}
}
int tp = 0, bt = 0;
bdst[sx][sy] = sd * t;
que[tp++] = sx * n + sy;
while (bt < tp) {
int xy = que[bt++];
int x = xy / n;
int y = xy % n;
if (grid[x][y] == 'D') return 1;
if (dist[x][y] * sd <= bdst[x][y]) continue;
for (int i = 0; i < 4; ++i) {
int nx = x + gox[i];
int ny = y + goy[i];
if (nx < 0 || n <= nx || ny < 0 || n <= ny) continue;
if (grid[nx][ny] == 'T') continue;
if (bdst[nx][ny] < inf) continue;
bdst[nx][ny] = bdst[x][y] + 1;
que[tp++] = nx * n + ny;
}
}
return 0;
}
int main() {
scanf("%d%d", &n, &sd);
int tp = 0, bt = 0;
for (int i = 0; i < n; ++i) {
scanf("%s", grid[i]);
for (int j = 0; j < n; ++j) {
dist[i][j] = inf;
if (grid[i][j] == 'M') sx = i, sy = j;
else if (grid[i][j] == 'H') dist[i][j] = 0, que[tp++] = i * n + j;
}
}
while (bt < tp) {
int xy = que[bt++];
int x = xy / n;
int y = xy % n;
if (grid[x][y] == 'D') continue;
for (int i = 0; i < 4; ++i) {
int nx = x + gox[i];
int ny = y + goy[i];
if (nx < 0 || n <= nx || ny < 0 || n <= ny) continue;
if (grid[nx][ny] == 'T') continue;
if (dist[nx][ny] < inf) continue;
dist[nx][ny] = dist[x][y] + 1;
que[tp++] = nx * n + ny;
}
}
int s = -1, e = dist[sx][sy];
while (s < e) {
int m = (s + e + 1) / 2;
if (check(m)) s = m;
else e = m - 1;
}
printf("%d\n", s);
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &sd);
~~~~~^~~~~~~~~~~~~~~~~
mecho.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", grid[i]);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
109 ms |
8716 KB |
Output is correct |
8 |
Correct |
2 ms |
8716 KB |
Output is correct |
9 |
Correct |
2 ms |
8716 KB |
Output is correct |
10 |
Correct |
3 ms |
8716 KB |
Output is correct |
11 |
Correct |
2 ms |
8716 KB |
Output is correct |
12 |
Correct |
2 ms |
8716 KB |
Output is correct |
13 |
Correct |
2 ms |
8716 KB |
Output is correct |
14 |
Correct |
2 ms |
8716 KB |
Output is correct |
15 |
Correct |
2 ms |
8716 KB |
Output is correct |
16 |
Correct |
2 ms |
8716 KB |
Output is correct |
17 |
Correct |
2 ms |
8716 KB |
Output is correct |
18 |
Correct |
2 ms |
8716 KB |
Output is correct |
19 |
Correct |
2 ms |
8716 KB |
Output is correct |
20 |
Correct |
2 ms |
8716 KB |
Output is correct |
21 |
Correct |
2 ms |
8716 KB |
Output is correct |
22 |
Correct |
2 ms |
8716 KB |
Output is correct |
23 |
Correct |
3 ms |
8716 KB |
Output is correct |
24 |
Correct |
3 ms |
8716 KB |
Output is correct |
25 |
Correct |
3 ms |
8716 KB |
Output is correct |
26 |
Correct |
4 ms |
8716 KB |
Output is correct |
27 |
Correct |
3 ms |
8716 KB |
Output is correct |
28 |
Correct |
2 ms |
8716 KB |
Output is correct |
29 |
Correct |
5 ms |
8716 KB |
Output is correct |
30 |
Correct |
2 ms |
8716 KB |
Output is correct |
31 |
Correct |
2 ms |
8716 KB |
Output is correct |
32 |
Correct |
2 ms |
8716 KB |
Output is correct |
33 |
Correct |
7 ms |
8716 KB |
Output is correct |
34 |
Correct |
7 ms |
8716 KB |
Output is correct |
35 |
Correct |
24 ms |
8716 KB |
Output is correct |
36 |
Correct |
9 ms |
8716 KB |
Output is correct |
37 |
Correct |
8 ms |
8716 KB |
Output is correct |
38 |
Correct |
33 ms |
8716 KB |
Output is correct |
39 |
Correct |
10 ms |
8716 KB |
Output is correct |
40 |
Correct |
10 ms |
8716 KB |
Output is correct |
41 |
Correct |
50 ms |
8716 KB |
Output is correct |
42 |
Correct |
11 ms |
8716 KB |
Output is correct |
43 |
Correct |
11 ms |
8716 KB |
Output is correct |
44 |
Correct |
61 ms |
8716 KB |
Output is correct |
45 |
Correct |
14 ms |
8716 KB |
Output is correct |
46 |
Correct |
13 ms |
8716 KB |
Output is correct |
47 |
Correct |
64 ms |
8716 KB |
Output is correct |
48 |
Correct |
15 ms |
8716 KB |
Output is correct |
49 |
Correct |
15 ms |
8716 KB |
Output is correct |
50 |
Correct |
81 ms |
8716 KB |
Output is correct |
51 |
Correct |
17 ms |
8716 KB |
Output is correct |
52 |
Correct |
17 ms |
8716 KB |
Output is correct |
53 |
Correct |
94 ms |
8716 KB |
Output is correct |
54 |
Correct |
19 ms |
8716 KB |
Output is correct |
55 |
Correct |
27 ms |
8716 KB |
Output is correct |
56 |
Correct |
123 ms |
8716 KB |
Output is correct |
57 |
Correct |
22 ms |
8716 KB |
Output is correct |
58 |
Correct |
22 ms |
8716 KB |
Output is correct |
59 |
Correct |
129 ms |
8716 KB |
Output is correct |
60 |
Correct |
23 ms |
8716 KB |
Output is correct |
61 |
Correct |
23 ms |
8716 KB |
Output is correct |
62 |
Correct |
155 ms |
8716 KB |
Output is correct |
63 |
Correct |
140 ms |
8716 KB |
Output is correct |
64 |
Correct |
250 ms |
8716 KB |
Output is correct |
65 |
Correct |
233 ms |
8716 KB |
Output is correct |
66 |
Correct |
190 ms |
8716 KB |
Output is correct |
67 |
Correct |
154 ms |
8716 KB |
Output is correct |
68 |
Correct |
69 ms |
8716 KB |
Output is correct |
69 |
Correct |
55 ms |
8716 KB |
Output is correct |
70 |
Correct |
51 ms |
8716 KB |
Output is correct |
71 |
Correct |
42 ms |
8716 KB |
Output is correct |
72 |
Correct |
41 ms |
8716 KB |
Output is correct |
73 |
Correct |
39 ms |
8716 KB |
Output is correct |
74 |
Correct |
82 ms |
8716 KB |
Output is correct |
75 |
Correct |
83 ms |
8828 KB |
Output is correct |
76 |
Correct |
83 ms |
8828 KB |
Output is correct |
77 |
Correct |
83 ms |
8828 KB |
Output is correct |
78 |
Correct |
97 ms |
8828 KB |
Output is correct |
79 |
Correct |
76 ms |
8828 KB |
Output is correct |
80 |
Correct |
82 ms |
8828 KB |
Output is correct |
81 |
Correct |
85 ms |
8828 KB |
Output is correct |
82 |
Correct |
84 ms |
8828 KB |
Output is correct |
83 |
Correct |
118 ms |
8828 KB |
Output is correct |
84 |
Correct |
96 ms |
8828 KB |
Output is correct |
85 |
Correct |
90 ms |
8828 KB |
Output is correct |
86 |
Correct |
108 ms |
8828 KB |
Output is correct |
87 |
Correct |
98 ms |
8828 KB |
Output is correct |
88 |
Correct |
113 ms |
8828 KB |
Output is correct |
89 |
Correct |
108 ms |
8828 KB |
Output is correct |
90 |
Correct |
148 ms |
8828 KB |
Output is correct |
91 |
Correct |
133 ms |
8828 KB |
Output is correct |
92 |
Correct |
141 ms |
8828 KB |
Output is correct |