# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
53469 |
2018-06-30T05:32:16 Z |
시제연(#2016) |
Mecho (IOI09_mecho) |
C++11 |
|
240 ms |
6528 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] / s >= d[nx.X][nx.Y] - x) continue;
e[nx.X][nx.Y] = e[c.X][c.Y] + 1;
q.push(nx);
}
}
//puts("");
//for(int i=1;i<=n;i++,puts(""))for(int j=1;j<=n;j++)printf("%d ",e[i][j]%INF);
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') 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:37: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:38: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);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
556 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
556 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
556 KB |
Output isn't correct |
5 |
Correct |
3 ms |
556 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
104 ms |
6244 KB |
Output is correct |
8 |
Incorrect |
2 ms |
6244 KB |
Output isn't correct |
9 |
Correct |
2 ms |
6244 KB |
Output is correct |
10 |
Correct |
2 ms |
6244 KB |
Output is correct |
11 |
Correct |
2 ms |
6244 KB |
Output is correct |
12 |
Incorrect |
2 ms |
6244 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
6244 KB |
Output isn't correct |
14 |
Correct |
3 ms |
6244 KB |
Output is correct |
15 |
Incorrect |
2 ms |
6244 KB |
Output isn't correct |
16 |
Correct |
2 ms |
6244 KB |
Output is correct |
17 |
Incorrect |
2 ms |
6244 KB |
Output isn't correct |
18 |
Correct |
2 ms |
6244 KB |
Output is correct |
19 |
Incorrect |
2 ms |
6244 KB |
Output isn't correct |
20 |
Correct |
2 ms |
6244 KB |
Output is correct |
21 |
Incorrect |
2 ms |
6244 KB |
Output isn't correct |
22 |
Correct |
2 ms |
6244 KB |
Output is correct |
23 |
Incorrect |
3 ms |
6244 KB |
Output isn't correct |
24 |
Correct |
3 ms |
6244 KB |
Output is correct |
25 |
Incorrect |
3 ms |
6244 KB |
Output isn't correct |
26 |
Correct |
3 ms |
6244 KB |
Output is correct |
27 |
Incorrect |
3 ms |
6244 KB |
Output isn't correct |
28 |
Correct |
3 ms |
6244 KB |
Output is correct |
29 |
Incorrect |
2 ms |
6244 KB |
Output isn't correct |
30 |
Correct |
2 ms |
6244 KB |
Output is correct |
31 |
Incorrect |
2 ms |
6244 KB |
Output isn't correct |
32 |
Correct |
3 ms |
6244 KB |
Output is correct |
33 |
Incorrect |
9 ms |
6244 KB |
Output isn't correct |
34 |
Correct |
8 ms |
6244 KB |
Output is correct |
35 |
Correct |
25 ms |
6244 KB |
Output is correct |
36 |
Incorrect |
10 ms |
6244 KB |
Output isn't correct |
37 |
Correct |
10 ms |
6244 KB |
Output is correct |
38 |
Correct |
30 ms |
6244 KB |
Output is correct |
39 |
Incorrect |
11 ms |
6244 KB |
Output isn't correct |
40 |
Correct |
12 ms |
6244 KB |
Output is correct |
41 |
Correct |
44 ms |
6244 KB |
Output is correct |
42 |
Incorrect |
13 ms |
6244 KB |
Output isn't correct |
43 |
Correct |
14 ms |
6244 KB |
Output is correct |
44 |
Correct |
70 ms |
6244 KB |
Output is correct |
45 |
Incorrect |
21 ms |
6244 KB |
Output isn't correct |
46 |
Correct |
15 ms |
6244 KB |
Output is correct |
47 |
Correct |
66 ms |
6244 KB |
Output is correct |
48 |
Incorrect |
16 ms |
6244 KB |
Output isn't correct |
49 |
Correct |
23 ms |
6244 KB |
Output is correct |
50 |
Correct |
81 ms |
6244 KB |
Output is correct |
51 |
Incorrect |
19 ms |
6244 KB |
Output isn't correct |
52 |
Correct |
21 ms |
6244 KB |
Output is correct |
53 |
Correct |
113 ms |
6244 KB |
Output is correct |
54 |
Incorrect |
21 ms |
6244 KB |
Output isn't correct |
55 |
Correct |
38 ms |
6244 KB |
Output is correct |
56 |
Correct |
179 ms |
6244 KB |
Output is correct |
57 |
Incorrect |
29 ms |
6244 KB |
Output isn't correct |
58 |
Correct |
33 ms |
6244 KB |
Output is correct |
59 |
Correct |
150 ms |
6244 KB |
Output is correct |
60 |
Incorrect |
29 ms |
6260 KB |
Output isn't correct |
61 |
Correct |
30 ms |
6396 KB |
Output is correct |
62 |
Correct |
177 ms |
6396 KB |
Output is correct |
63 |
Correct |
126 ms |
6396 KB |
Output is correct |
64 |
Correct |
240 ms |
6396 KB |
Output is correct |
65 |
Correct |
191 ms |
6396 KB |
Output is correct |
66 |
Incorrect |
179 ms |
6396 KB |
Output isn't correct |
67 |
Correct |
162 ms |
6396 KB |
Output is correct |
68 |
Correct |
85 ms |
6396 KB |
Output is correct |
69 |
Correct |
69 ms |
6396 KB |
Output is correct |
70 |
Correct |
46 ms |
6396 KB |
Output is correct |
71 |
Correct |
52 ms |
6396 KB |
Output is correct |
72 |
Incorrect |
46 ms |
6396 KB |
Output isn't correct |
73 |
Incorrect |
82 ms |
6508 KB |
Output isn't correct |
74 |
Correct |
96 ms |
6524 KB |
Output is correct |
75 |
Correct |
84 ms |
6524 KB |
Output is correct |
76 |
Correct |
72 ms |
6524 KB |
Output is correct |
77 |
Correct |
80 ms |
6524 KB |
Output is correct |
78 |
Correct |
112 ms |
6524 KB |
Output is correct |
79 |
Correct |
60 ms |
6528 KB |
Output is correct |
80 |
Correct |
74 ms |
6528 KB |
Output is correct |
81 |
Correct |
83 ms |
6528 KB |
Output is correct |
82 |
Correct |
70 ms |
6528 KB |
Output is correct |
83 |
Correct |
99 ms |
6528 KB |
Output is correct |
84 |
Correct |
86 ms |
6528 KB |
Output is correct |
85 |
Correct |
129 ms |
6528 KB |
Output is correct |
86 |
Correct |
95 ms |
6528 KB |
Output is correct |
87 |
Correct |
104 ms |
6528 KB |
Output is correct |
88 |
Correct |
115 ms |
6528 KB |
Output is correct |
89 |
Correct |
104 ms |
6528 KB |
Output is correct |
90 |
Correct |
119 ms |
6528 KB |
Output is correct |
91 |
Correct |
103 ms |
6528 KB |
Output is correct |
92 |
Correct |
114 ms |
6528 KB |
Output is correct |