# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
109011 |
2019-05-04T01:53:50 Z |
PeppaPig |
Mecho (IOI09_mecho) |
C++14 |
|
272 ms |
6940 KB |
#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 805;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int n, s;
int sx, sy, bee[N][N], d[N][N];
char A[N][N];
void gen_bee() {
queue<pii> Q;
for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) {
if(A[i][j] == 'M') sx = i, sy = j;
if(A[i][j] == 'H') {
bee[i][j] = 0;
Q.emplace(i, j);
}
}
while(!Q.empty()) {
pii u = Q.front(); Q.pop();
for(int i = 0; i < 4; i++) {
int nr = u.x + dx[i], nc = u.y + dy[i];
if(nr < 1 || nr > n || nc < 1 || nc > n) continue;
if(A[nr][nc] != 'G' && A[nr][nc] != 'M') continue;
if(bee[u.x][u.y] + 1 < bee[nr][nc]) {
bee[nr][nc] = bee[u.x][u.y] + 1;
Q.emplace(nr, nc);
}
}
}
}
bool chk(int mid) {
if(1ll * mid >= bee[sx][sy]) return false;
fill_n(d[0], N*N, 1e9+1);
queue<pii> Q;
d[sx][sy] = 0;
Q.emplace(sx, sy);
while(!Q.empty()) {
pii u = Q.front(); Q.pop();
if(A[u.x][u.y] == 'D') return true;
for(int i = 0; i < 4; i++) {
int nr = u.x + dx[i], nc = u.y + dy[i];
if(nr < 1 || nr > n || nc < 1 || nc > n) continue;
if(A[nr][nc] != 'M' && A[nr][nc] != 'G' && A[nr][nc] != 'D') continue;
if(d[u.x][u.y] + 1 < d[nr][nc] && 1ll * d[u.x][u.y] + 1 < 1ll * s * (bee[nr][nc] - mid)) {
d[nr][nc] = d[u.x][u.y] + 1;
Q.emplace(nr, nc);
}
}
}
return false;
}
int main() {
fill_n(bee[0], N*N, 1e9+1);
scanf("%d %d", &n, &s);
for(int i = 1; i <= n; i++) scanf(" %s", A[i] + 1);
gen_bee();
int l = 0, r = n * n;
while(l < r) {
int mid = (l + r + 1) >> 1;
if(chk(mid)) l = mid;
else r = mid-1;
}
if(chk(l)) printf("%d\n", l);
else printf("-1\n");
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:64: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:65: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", A[i] + 1);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5376 KB |
Output is correct |
2 |
Correct |
8 ms |
5376 KB |
Output is correct |
3 |
Correct |
8 ms |
5376 KB |
Output is correct |
4 |
Correct |
7 ms |
5372 KB |
Output is correct |
5 |
Correct |
6 ms |
5376 KB |
Output is correct |
6 |
Correct |
8 ms |
5376 KB |
Output is correct |
7 |
Correct |
129 ms |
6784 KB |
Output is correct |
8 |
Correct |
8 ms |
5376 KB |
Output is correct |
9 |
Correct |
9 ms |
5376 KB |
Output is correct |
10 |
Correct |
10 ms |
5376 KB |
Output is correct |
11 |
Correct |
9 ms |
5504 KB |
Output is correct |
12 |
Correct |
9 ms |
5504 KB |
Output is correct |
13 |
Correct |
8 ms |
5376 KB |
Output is correct |
14 |
Correct |
10 ms |
5504 KB |
Output is correct |
15 |
Correct |
11 ms |
5376 KB |
Output is correct |
16 |
Correct |
9 ms |
5376 KB |
Output is correct |
17 |
Correct |
12 ms |
5504 KB |
Output is correct |
18 |
Correct |
9 ms |
5348 KB |
Output is correct |
19 |
Correct |
11 ms |
5376 KB |
Output is correct |
20 |
Correct |
10 ms |
5376 KB |
Output is correct |
21 |
Correct |
10 ms |
5504 KB |
Output is correct |
22 |
Correct |
11 ms |
5504 KB |
Output is correct |
23 |
Correct |
9 ms |
5504 KB |
Output is correct |
24 |
Correct |
8 ms |
5504 KB |
Output is correct |
25 |
Correct |
9 ms |
5504 KB |
Output is correct |
26 |
Correct |
9 ms |
5376 KB |
Output is correct |
27 |
Correct |
9 ms |
5504 KB |
Output is correct |
28 |
Correct |
11 ms |
5504 KB |
Output is correct |
29 |
Correct |
13 ms |
5504 KB |
Output is correct |
30 |
Correct |
10 ms |
5504 KB |
Output is correct |
31 |
Correct |
11 ms |
5504 KB |
Output is correct |
32 |
Correct |
11 ms |
5496 KB |
Output is correct |
33 |
Correct |
16 ms |
5716 KB |
Output is correct |
34 |
Correct |
13 ms |
5760 KB |
Output is correct |
35 |
Correct |
33 ms |
5760 KB |
Output is correct |
36 |
Correct |
12 ms |
5860 KB |
Output is correct |
37 |
Correct |
15 ms |
5888 KB |
Output is correct |
38 |
Correct |
45 ms |
5888 KB |
Output is correct |
39 |
Correct |
14 ms |
6016 KB |
Output is correct |
40 |
Correct |
17 ms |
6008 KB |
Output is correct |
41 |
Correct |
74 ms |
6016 KB |
Output is correct |
42 |
Correct |
20 ms |
6144 KB |
Output is correct |
43 |
Correct |
18 ms |
6144 KB |
Output is correct |
44 |
Correct |
75 ms |
6016 KB |
Output is correct |
45 |
Correct |
23 ms |
6144 KB |
Output is correct |
46 |
Correct |
22 ms |
6192 KB |
Output is correct |
47 |
Correct |
102 ms |
6144 KB |
Output is correct |
48 |
Correct |
19 ms |
6272 KB |
Output is correct |
49 |
Correct |
26 ms |
6272 KB |
Output is correct |
50 |
Correct |
110 ms |
6244 KB |
Output is correct |
51 |
Correct |
22 ms |
6312 KB |
Output is correct |
52 |
Correct |
20 ms |
6400 KB |
Output is correct |
53 |
Correct |
118 ms |
6392 KB |
Output is correct |
54 |
Correct |
19 ms |
6400 KB |
Output is correct |
55 |
Correct |
19 ms |
6528 KB |
Output is correct |
56 |
Correct |
156 ms |
6596 KB |
Output is correct |
57 |
Correct |
23 ms |
6524 KB |
Output is correct |
58 |
Correct |
26 ms |
6528 KB |
Output is correct |
59 |
Correct |
167 ms |
6524 KB |
Output is correct |
60 |
Correct |
28 ms |
6648 KB |
Output is correct |
61 |
Correct |
28 ms |
6656 KB |
Output is correct |
62 |
Correct |
202 ms |
6656 KB |
Output is correct |
63 |
Correct |
160 ms |
6780 KB |
Output is correct |
64 |
Correct |
272 ms |
6776 KB |
Output is correct |
65 |
Correct |
211 ms |
6776 KB |
Output is correct |
66 |
Correct |
173 ms |
6780 KB |
Output is correct |
67 |
Correct |
160 ms |
6648 KB |
Output is correct |
68 |
Correct |
86 ms |
6648 KB |
Output is correct |
69 |
Correct |
66 ms |
6776 KB |
Output is correct |
70 |
Correct |
72 ms |
6776 KB |
Output is correct |
71 |
Correct |
57 ms |
6776 KB |
Output is correct |
72 |
Correct |
38 ms |
6648 KB |
Output is correct |
73 |
Correct |
66 ms |
6756 KB |
Output is correct |
74 |
Correct |
98 ms |
6752 KB |
Output is correct |
75 |
Correct |
111 ms |
6784 KB |
Output is correct |
76 |
Correct |
115 ms |
6836 KB |
Output is correct |
77 |
Correct |
116 ms |
6736 KB |
Output is correct |
78 |
Correct |
122 ms |
6836 KB |
Output is correct |
79 |
Correct |
75 ms |
6836 KB |
Output is correct |
80 |
Correct |
110 ms |
6776 KB |
Output is correct |
81 |
Correct |
89 ms |
6848 KB |
Output is correct |
82 |
Correct |
81 ms |
6836 KB |
Output is correct |
83 |
Correct |
120 ms |
6940 KB |
Output is correct |
84 |
Correct |
120 ms |
6836 KB |
Output is correct |
85 |
Correct |
138 ms |
6832 KB |
Output is correct |
86 |
Correct |
133 ms |
6836 KB |
Output is correct |
87 |
Correct |
117 ms |
6844 KB |
Output is correct |
88 |
Correct |
123 ms |
6832 KB |
Output is correct |
89 |
Correct |
143 ms |
6868 KB |
Output is correct |
90 |
Correct |
167 ms |
6840 KB |
Output is correct |
91 |
Correct |
141 ms |
6844 KB |
Output is correct |
92 |
Correct |
135 ms |
6740 KB |
Output is correct |