# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
198705 |
2020-01-27T12:35:44 Z |
SamAnd |
Mecho (IOI09_mecho) |
C++17 |
|
388 ms |
8420 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 802;
const int xx[4] = {0, 1, 0, -1};
const int yy[4] = {1, 0, -1, 0};
struct ban
{
int x, y;
ban(){}
ban(int x, int y)
{
this->x = x;
this->y = y;
}
};
int n, s;
int mx, my;
vector<ban> hh;
char a[N][N];
bool ch[N][N];
int dh[N][N];
bool cm[N][N];
int dm[N][N];
bool stg(int x)
{
memset(ch, false, sizeof ch);
memset(cm, false, sizeof cm);
queue<ban> qh;
queue<ban> qm;
for (int i = 0; i < hh.size(); ++i)
{
ch[hh[i].x][hh[i].y] = true;
qh.push(hh[i]);
}
while (!qh.empty())
{
ban t = qh.front();
if (dh[t.x][t.y] == x)
break;
qh.pop();
for (int i = 0; i < 4; ++i)
{
ban h = t;
h.x += xx[i];
h.y += yy[i];
if (h.x >= 0 && h.x < n && h.y >= 0 && h.y < n)
{
if (a[h.x][h.y] == 'G' && !ch[h.x][h.y])
{
ch[h.x][h.y] = true;
dh[h.x][h.y] = dh[t.x][t.y] + 1;
qh.push(h);
}
}
}
}
qm.push(ban(mx, my));
cm[mx][my] = true;
for (int ii = 0; ; ++ii)
{
if (qm.empty())
return false;
while (!qm.empty())
{
ban t = qm.front();
if (dm[t.x][t.y] == (ii + 1) * s)
break;
qm.pop();
if (ch[t.x][t.y])
continue;
if (a[t.x][t.y] == 'D')
return true;
for (int i = 0; i < 4; ++i)
{
ban h = t;
h.x += xx[i];
h.y += yy[i];
if (h.x >= 0 && h.x < n && h.y >= 0 && h.y < n)
{
if ((a[h.x][h.y] == 'G' || a[h.x][h.y] == 'D') && !cm[h.x][h.y] && !ch[h.x][h.y])
{
cm[h.x][h.y] = true;
dm[h.x][h.y] = dm[t.x][t.y] + 1;
qm.push(h);
}
}
}
}
while (!qh.empty())
{
ban t = qh.front();
if (dh[t.x][t.y] == x + ii + 1)
break;
qh.pop();
for (int i = 0; i < 4; ++i)
{
ban h = t;
h.x += xx[i];
h.y += yy[i];
if (h.x >= 0 && h.x < n && h.y >= 0 && h.y < n)
{
if (a[h.x][h.y] == 'G' && !ch[h.x][h.y])
{
ch[h.x][h.y] = true;
dh[h.x][h.y] = dh[t.x][t.y] + 1;
qh.push(h);
}
}
}
}
}
}
int main()
{
//freopen("input.txt", "r", stdin);
scanf("%d%d", &n, &s);
for (int i = 0; i < n; ++i)
{
scanf(" %s", a[i]);
for (int j = 0; j < n; ++j)
{
if (a[i][j] == 'M')
{
mx = i;
my = j;
a[i][j] = 'G';
}
if (a[i][j] == 'H')
{
hh.push_back(ban(i, j));
a[i][j] = 'G';
}
}
}
int l = 0, r = n * n;
int ans = -1;
while (l <= r)
{
int m = (l + r) / 2;
if (stg(m))
{
ans = m;
l = m + 1;
}
else
r = m - 1;
}
printf("%d\n", ans);
return 0;
}
Compilation message
mecho.cpp: In function 'bool stg(int)':
mecho.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < hh.size(); ++i)
~~^~~~~~~~~~~
mecho.cpp: In function 'int main()':
mecho.cpp:120: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:123:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %s", a[i]);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1656 KB |
Output is correct |
2 |
Correct |
6 ms |
1656 KB |
Output is correct |
3 |
Correct |
7 ms |
1656 KB |
Output is correct |
4 |
Correct |
6 ms |
1656 KB |
Output is correct |
5 |
Correct |
6 ms |
1656 KB |
Output is correct |
6 |
Correct |
6 ms |
1656 KB |
Output is correct |
7 |
Correct |
316 ms |
7032 KB |
Output is correct |
8 |
Correct |
6 ms |
1656 KB |
Output is correct |
9 |
Correct |
6 ms |
1656 KB |
Output is correct |
10 |
Correct |
7 ms |
1656 KB |
Output is correct |
11 |
Correct |
6 ms |
1660 KB |
Output is correct |
12 |
Correct |
7 ms |
1784 KB |
Output is correct |
13 |
Correct |
9 ms |
1784 KB |
Output is correct |
14 |
Correct |
8 ms |
1912 KB |
Output is correct |
15 |
Correct |
6 ms |
1656 KB |
Output is correct |
16 |
Correct |
7 ms |
1656 KB |
Output is correct |
17 |
Correct |
7 ms |
1656 KB |
Output is correct |
18 |
Correct |
7 ms |
1784 KB |
Output is correct |
19 |
Correct |
7 ms |
1784 KB |
Output is correct |
20 |
Correct |
6 ms |
1784 KB |
Output is correct |
21 |
Correct |
7 ms |
1784 KB |
Output is correct |
22 |
Correct |
7 ms |
1784 KB |
Output is correct |
23 |
Correct |
7 ms |
1784 KB |
Output is correct |
24 |
Correct |
7 ms |
1788 KB |
Output is correct |
25 |
Correct |
7 ms |
1784 KB |
Output is correct |
26 |
Correct |
7 ms |
1784 KB |
Output is correct |
27 |
Correct |
7 ms |
1888 KB |
Output is correct |
28 |
Correct |
8 ms |
1912 KB |
Output is correct |
29 |
Correct |
7 ms |
1916 KB |
Output is correct |
30 |
Correct |
7 ms |
1912 KB |
Output is correct |
31 |
Correct |
8 ms |
1912 KB |
Output is correct |
32 |
Correct |
8 ms |
1912 KB |
Output is correct |
33 |
Correct |
32 ms |
3064 KB |
Output is correct |
34 |
Correct |
29 ms |
3064 KB |
Output is correct |
35 |
Correct |
40 ms |
4216 KB |
Output is correct |
36 |
Correct |
36 ms |
3320 KB |
Output is correct |
37 |
Correct |
36 ms |
3320 KB |
Output is correct |
38 |
Correct |
51 ms |
4600 KB |
Output is correct |
39 |
Correct |
56 ms |
3576 KB |
Output is correct |
40 |
Correct |
42 ms |
3576 KB |
Output is correct |
41 |
Correct |
69 ms |
4984 KB |
Output is correct |
42 |
Correct |
54 ms |
3832 KB |
Output is correct |
43 |
Correct |
50 ms |
3832 KB |
Output is correct |
44 |
Correct |
88 ms |
5368 KB |
Output is correct |
45 |
Correct |
67 ms |
4216 KB |
Output is correct |
46 |
Correct |
56 ms |
4088 KB |
Output is correct |
47 |
Correct |
91 ms |
5752 KB |
Output is correct |
48 |
Correct |
72 ms |
4344 KB |
Output is correct |
49 |
Correct |
68 ms |
4376 KB |
Output is correct |
50 |
Correct |
124 ms |
6264 KB |
Output is correct |
51 |
Correct |
95 ms |
4728 KB |
Output is correct |
52 |
Correct |
83 ms |
4600 KB |
Output is correct |
53 |
Correct |
137 ms |
6648 KB |
Output is correct |
54 |
Correct |
106 ms |
4856 KB |
Output is correct |
55 |
Correct |
99 ms |
4856 KB |
Output is correct |
56 |
Correct |
182 ms |
7032 KB |
Output is correct |
57 |
Correct |
116 ms |
5112 KB |
Output is correct |
58 |
Correct |
108 ms |
5184 KB |
Output is correct |
59 |
Correct |
205 ms |
7544 KB |
Output is correct |
60 |
Correct |
142 ms |
5368 KB |
Output is correct |
61 |
Correct |
121 ms |
5368 KB |
Output is correct |
62 |
Correct |
230 ms |
8056 KB |
Output is correct |
63 |
Correct |
336 ms |
7928 KB |
Output is correct |
64 |
Correct |
341 ms |
7928 KB |
Output is correct |
65 |
Correct |
307 ms |
7928 KB |
Output is correct |
66 |
Correct |
346 ms |
7928 KB |
Output is correct |
67 |
Correct |
333 ms |
7928 KB |
Output is correct |
68 |
Correct |
341 ms |
7928 KB |
Output is correct |
69 |
Correct |
303 ms |
8056 KB |
Output is correct |
70 |
Correct |
317 ms |
8004 KB |
Output is correct |
71 |
Correct |
375 ms |
8060 KB |
Output is correct |
72 |
Correct |
388 ms |
6008 KB |
Output is correct |
73 |
Correct |
271 ms |
8212 KB |
Output is correct |
74 |
Correct |
347 ms |
8128 KB |
Output is correct |
75 |
Correct |
380 ms |
8336 KB |
Output is correct |
76 |
Correct |
360 ms |
8200 KB |
Output is correct |
77 |
Correct |
370 ms |
8420 KB |
Output is correct |
78 |
Correct |
326 ms |
7004 KB |
Output is correct |
79 |
Correct |
322 ms |
6792 KB |
Output is correct |
80 |
Correct |
338 ms |
6624 KB |
Output is correct |
81 |
Correct |
330 ms |
6732 KB |
Output is correct |
82 |
Correct |
326 ms |
6732 KB |
Output is correct |
83 |
Correct |
333 ms |
7132 KB |
Output is correct |
84 |
Correct |
333 ms |
6984 KB |
Output is correct |
85 |
Correct |
345 ms |
6836 KB |
Output is correct |
86 |
Correct |
345 ms |
6992 KB |
Output is correct |
87 |
Correct |
331 ms |
7048 KB |
Output is correct |
88 |
Correct |
320 ms |
7064 KB |
Output is correct |
89 |
Correct |
315 ms |
6940 KB |
Output is correct |
90 |
Correct |
323 ms |
7068 KB |
Output is correct |
91 |
Correct |
327 ms |
6988 KB |
Output is correct |
92 |
Correct |
336 ms |
6968 KB |
Output is correct |