# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
53456 |
2018-06-30T05:12:22 Z |
강태규(#1417) |
Mecho (IOI09_mecho) |
C++11 |
|
457 ms |
8916 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 = 1e7;
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] <= bdst[x][y] / sd) 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;
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 (grid[nx][ny] == 'D') 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]);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
524 KB |
Output is correct |
7 |
Correct |
141 ms |
8892 KB |
Output is correct |
8 |
Correct |
3 ms |
8892 KB |
Output is correct |
9 |
Correct |
2 ms |
8892 KB |
Output is correct |
10 |
Correct |
2 ms |
8892 KB |
Output is correct |
11 |
Correct |
2 ms |
8892 KB |
Output is correct |
12 |
Correct |
2 ms |
8892 KB |
Output is correct |
13 |
Correct |
2 ms |
8892 KB |
Output is correct |
14 |
Correct |
3 ms |
8892 KB |
Output is correct |
15 |
Correct |
2 ms |
8892 KB |
Output is correct |
16 |
Correct |
2 ms |
8892 KB |
Output is correct |
17 |
Correct |
3 ms |
8892 KB |
Output is correct |
18 |
Correct |
3 ms |
8892 KB |
Output is correct |
19 |
Correct |
2 ms |
8892 KB |
Output is correct |
20 |
Correct |
2 ms |
8892 KB |
Output is correct |
21 |
Correct |
3 ms |
8892 KB |
Output is correct |
22 |
Correct |
2 ms |
8892 KB |
Output is correct |
23 |
Correct |
2 ms |
8892 KB |
Output is correct |
24 |
Correct |
3 ms |
8892 KB |
Output is correct |
25 |
Correct |
2 ms |
8892 KB |
Output is correct |
26 |
Correct |
2 ms |
8892 KB |
Output is correct |
27 |
Correct |
2 ms |
8892 KB |
Output is correct |
28 |
Correct |
3 ms |
8892 KB |
Output is correct |
29 |
Correct |
3 ms |
8892 KB |
Output is correct |
30 |
Correct |
2 ms |
8892 KB |
Output is correct |
31 |
Correct |
2 ms |
8892 KB |
Output is correct |
32 |
Correct |
2 ms |
8892 KB |
Output is correct |
33 |
Correct |
7 ms |
8892 KB |
Output is correct |
34 |
Correct |
7 ms |
8892 KB |
Output is correct |
35 |
Correct |
26 ms |
8892 KB |
Output is correct |
36 |
Correct |
8 ms |
8892 KB |
Output is correct |
37 |
Correct |
8 ms |
8892 KB |
Output is correct |
38 |
Correct |
33 ms |
8892 KB |
Output is correct |
39 |
Correct |
9 ms |
8892 KB |
Output is correct |
40 |
Incorrect |
256 ms |
8892 KB |
Output isn't correct |
41 |
Correct |
44 ms |
8892 KB |
Output is correct |
42 |
Correct |
11 ms |
8892 KB |
Output is correct |
43 |
Incorrect |
387 ms |
8892 KB |
Output isn't correct |
44 |
Correct |
80 ms |
8892 KB |
Output is correct |
45 |
Correct |
15 ms |
8892 KB |
Output is correct |
46 |
Incorrect |
118 ms |
8892 KB |
Output isn't correct |
47 |
Correct |
91 ms |
8892 KB |
Output is correct |
48 |
Correct |
16 ms |
8892 KB |
Output is correct |
49 |
Incorrect |
329 ms |
8892 KB |
Output isn't correct |
50 |
Correct |
92 ms |
8892 KB |
Output is correct |
51 |
Correct |
20 ms |
8892 KB |
Output is correct |
52 |
Incorrect |
341 ms |
8892 KB |
Output isn't correct |
53 |
Correct |
106 ms |
8892 KB |
Output is correct |
54 |
Correct |
18 ms |
8892 KB |
Output is correct |
55 |
Incorrect |
292 ms |
8892 KB |
Output isn't correct |
56 |
Correct |
136 ms |
8892 KB |
Output is correct |
57 |
Correct |
21 ms |
8892 KB |
Output is correct |
58 |
Incorrect |
399 ms |
8892 KB |
Output isn't correct |
59 |
Correct |
179 ms |
8892 KB |
Output is correct |
60 |
Correct |
30 ms |
8892 KB |
Output is correct |
61 |
Incorrect |
457 ms |
8892 KB |
Output isn't correct |
62 |
Correct |
200 ms |
8892 KB |
Output is correct |
63 |
Correct |
138 ms |
8892 KB |
Output is correct |
64 |
Correct |
248 ms |
8892 KB |
Output is correct |
65 |
Correct |
244 ms |
8892 KB |
Output is correct |
66 |
Correct |
173 ms |
8892 KB |
Output is correct |
67 |
Correct |
157 ms |
8892 KB |
Output is correct |
68 |
Correct |
65 ms |
8892 KB |
Output is correct |
69 |
Correct |
58 ms |
8892 KB |
Output is correct |
70 |
Correct |
49 ms |
8892 KB |
Output is correct |
71 |
Correct |
45 ms |
8892 KB |
Output is correct |
72 |
Correct |
39 ms |
8892 KB |
Output is correct |
73 |
Correct |
39 ms |
8892 KB |
Output is correct |
74 |
Correct |
85 ms |
8892 KB |
Output is correct |
75 |
Correct |
78 ms |
8892 KB |
Output is correct |
76 |
Correct |
107 ms |
8892 KB |
Output is correct |
77 |
Correct |
105 ms |
8892 KB |
Output is correct |
78 |
Correct |
94 ms |
8892 KB |
Output is correct |
79 |
Correct |
75 ms |
8892 KB |
Output is correct |
80 |
Correct |
119 ms |
8892 KB |
Output is correct |
81 |
Correct |
109 ms |
8892 KB |
Output is correct |
82 |
Correct |
135 ms |
8892 KB |
Output is correct |
83 |
Correct |
136 ms |
8892 KB |
Output is correct |
84 |
Correct |
92 ms |
8892 KB |
Output is correct |
85 |
Correct |
88 ms |
8892 KB |
Output is correct |
86 |
Correct |
103 ms |
8892 KB |
Output is correct |
87 |
Correct |
136 ms |
8892 KB |
Output is correct |
88 |
Correct |
120 ms |
8892 KB |
Output is correct |
89 |
Correct |
128 ms |
8892 KB |
Output is correct |
90 |
Correct |
119 ms |
8916 KB |
Output is correct |
91 |
Correct |
121 ms |
8916 KB |
Output is correct |
92 |
Correct |
138 ms |
8916 KB |
Output is correct |