# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
53461 |
2018-06-30T05:26:31 Z |
강태규(#1417) |
Mecho (IOI09_mecho) |
C++11 |
|
226 ms |
8928 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 (dist[x][y] * sd <= bdst[x][y]) continue;
if (grid[x][y] == 'D') return 1;
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 |
Incorrect |
2 ms |
548 KB |
Output isn't correct |
3 |
Correct |
2 ms |
548 KB |
Output is correct |
4 |
Incorrect |
2 ms |
548 KB |
Output isn't correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Incorrect |
2 ms |
548 KB |
Output isn't correct |
7 |
Incorrect |
102 ms |
8576 KB |
Output isn't correct |
8 |
Correct |
2 ms |
8576 KB |
Output is correct |
9 |
Correct |
2 ms |
8576 KB |
Output is correct |
10 |
Correct |
2 ms |
8576 KB |
Output is correct |
11 |
Correct |
2 ms |
8576 KB |
Output is correct |
12 |
Incorrect |
2 ms |
8576 KB |
Output isn't correct |
13 |
Correct |
2 ms |
8576 KB |
Output is correct |
14 |
Correct |
3 ms |
8576 KB |
Output is correct |
15 |
Correct |
2 ms |
8576 KB |
Output is correct |
16 |
Correct |
2 ms |
8576 KB |
Output is correct |
17 |
Correct |
2 ms |
8576 KB |
Output is correct |
18 |
Correct |
2 ms |
8576 KB |
Output is correct |
19 |
Correct |
2 ms |
8576 KB |
Output is correct |
20 |
Correct |
2 ms |
8576 KB |
Output is correct |
21 |
Correct |
2 ms |
8576 KB |
Output is correct |
22 |
Correct |
2 ms |
8576 KB |
Output is correct |
23 |
Correct |
3 ms |
8576 KB |
Output is correct |
24 |
Correct |
2 ms |
8576 KB |
Output is correct |
25 |
Correct |
2 ms |
8576 KB |
Output is correct |
26 |
Correct |
3 ms |
8576 KB |
Output is correct |
27 |
Correct |
2 ms |
8576 KB |
Output is correct |
28 |
Correct |
3 ms |
8576 KB |
Output is correct |
29 |
Correct |
2 ms |
8576 KB |
Output is correct |
30 |
Correct |
2 ms |
8576 KB |
Output is correct |
31 |
Correct |
2 ms |
8576 KB |
Output is correct |
32 |
Correct |
2 ms |
8576 KB |
Output is correct |
33 |
Correct |
7 ms |
8576 KB |
Output is correct |
34 |
Correct |
10 ms |
8576 KB |
Output is correct |
35 |
Correct |
25 ms |
8576 KB |
Output is correct |
36 |
Correct |
8 ms |
8576 KB |
Output is correct |
37 |
Correct |
9 ms |
8576 KB |
Output is correct |
38 |
Correct |
33 ms |
8576 KB |
Output is correct |
39 |
Correct |
10 ms |
8576 KB |
Output is correct |
40 |
Correct |
13 ms |
8576 KB |
Output is correct |
41 |
Correct |
44 ms |
8576 KB |
Output is correct |
42 |
Correct |
11 ms |
8576 KB |
Output is correct |
43 |
Correct |
12 ms |
8576 KB |
Output is correct |
44 |
Correct |
68 ms |
8576 KB |
Output is correct |
45 |
Correct |
14 ms |
8576 KB |
Output is correct |
46 |
Correct |
14 ms |
8576 KB |
Output is correct |
47 |
Correct |
67 ms |
8576 KB |
Output is correct |
48 |
Correct |
14 ms |
8576 KB |
Output is correct |
49 |
Correct |
14 ms |
8576 KB |
Output is correct |
50 |
Correct |
81 ms |
8576 KB |
Output is correct |
51 |
Correct |
17 ms |
8576 KB |
Output is correct |
52 |
Correct |
17 ms |
8576 KB |
Output is correct |
53 |
Correct |
122 ms |
8576 KB |
Output is correct |
54 |
Correct |
19 ms |
8576 KB |
Output is correct |
55 |
Correct |
23 ms |
8576 KB |
Output is correct |
56 |
Correct |
128 ms |
8576 KB |
Output is correct |
57 |
Correct |
26 ms |
8576 KB |
Output is correct |
58 |
Correct |
21 ms |
8576 KB |
Output is correct |
59 |
Correct |
133 ms |
8576 KB |
Output is correct |
60 |
Correct |
24 ms |
8576 KB |
Output is correct |
61 |
Correct |
23 ms |
8576 KB |
Output is correct |
62 |
Correct |
168 ms |
8576 KB |
Output is correct |
63 |
Correct |
148 ms |
8576 KB |
Output is correct |
64 |
Correct |
226 ms |
8576 KB |
Output is correct |
65 |
Correct |
217 ms |
8576 KB |
Output is correct |
66 |
Correct |
160 ms |
8576 KB |
Output is correct |
67 |
Correct |
144 ms |
8576 KB |
Output is correct |
68 |
Correct |
60 ms |
8576 KB |
Output is correct |
69 |
Correct |
60 ms |
8576 KB |
Output is correct |
70 |
Correct |
54 ms |
8576 KB |
Output is correct |
71 |
Correct |
51 ms |
8576 KB |
Output is correct |
72 |
Correct |
45 ms |
8576 KB |
Output is correct |
73 |
Correct |
58 ms |
8704 KB |
Output is correct |
74 |
Correct |
78 ms |
8736 KB |
Output is correct |
75 |
Correct |
76 ms |
8736 KB |
Output is correct |
76 |
Correct |
82 ms |
8828 KB |
Output is correct |
77 |
Correct |
81 ms |
8828 KB |
Output is correct |
78 |
Correct |
95 ms |
8828 KB |
Output is correct |
79 |
Correct |
85 ms |
8828 KB |
Output is correct |
80 |
Correct |
100 ms |
8828 KB |
Output is correct |
81 |
Correct |
88 ms |
8828 KB |
Output is correct |
82 |
Correct |
75 ms |
8828 KB |
Output is correct |
83 |
Correct |
159 ms |
8828 KB |
Output is correct |
84 |
Correct |
92 ms |
8828 KB |
Output is correct |
85 |
Correct |
99 ms |
8828 KB |
Output is correct |
86 |
Correct |
110 ms |
8828 KB |
Output is correct |
87 |
Correct |
98 ms |
8928 KB |
Output is correct |
88 |
Correct |
106 ms |
8928 KB |
Output is correct |
89 |
Correct |
132 ms |
8928 KB |
Output is correct |
90 |
Correct |
114 ms |
8928 KB |
Output is correct |
91 |
Correct |
132 ms |
8928 KB |
Output is correct |
92 |
Correct |
112 ms |
8928 KB |
Output is correct |