# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
# define pb push_back
# define pf push_front
# define For(i, a, b) for( int i = a; i < b; i++ )
# define in insert
# define all(a) a.begin(),a.end()
# define pi pair < int, int >
# define DEBUG
# define readfile(file) freopen ( (file + ".in").c_str(), "r", stdin)
# define writefile(file) freopen ( (file + ".out").c_str(), "w", stdout)
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
# define LARGE 1000
# define SET(file) readfile(file);writefile(file);
using namespace std;
int ax[4] = { 1, -1, 0, 0 };
int ay[4] = { 0, 0, 1, -1 };
char mainMap[LARGE][LARGE];
bool visited[LARGE][LARGE];
int beeDistance[LARGE][LARGE];
int n, s;
int dx, dy;
int mx, my;
bool valid( int i, int j )
{
if ( i >= 0 && i < n && j >= 0 && j < n && mainMap[i][j] != 'T' )
return 1;
return 0;
}
bool test( int delay )
{
if ( delay * s >= beeDistance[mx][my] )
return false;
memset(visited, 0, sizeof(visited));
queue < pair < int, pi > > q;
q.push({delay * s, {mx, my}});
visited[mx][my] = 1;
while (!q.empty())
{
int distance = q.front().fi;
int x = q.front().se.fi;
int y = q.front().se.se;
q.pop();
if ( mainMap[x][y] == 'D' )
return true;
For ( i, 0, 4)
{
int nx = x + ax[i];
int ny = y + ay[i];
if ( !valid(nx, ny) || visited[nx][ny] || (distance + 1) >= beeDistance[nx][ny] )
continue;
q.push({distance + 1, {nx, ny}});
visited[nx][ny] = 1;
}
}
return false;
}
int main()
{
/// Author: _Dilshod_
speed;
cin >> n >> s;
queue < pi > bq;
memset(beeDistance, -1, sizeof(beeDistance));
For ( i, 0, n )
{
For ( j, 0, n )
{
cin >> mainMap[i][j];
if ( mainMap[i][j] == 'D' )
{
dx = i;
dy = j;
} else if ( mainMap[i][j] == 'H' )
{
bq.push({i, j});
beeDistance[i][j] = 1;
} else if ( mainMap[i][j] == 'M' )
{
mx = i;
my = j;
mainMap[i][j] = 'G';
}
}
}
while( !bq.empty() )
{
int x = bq.front().fi;
int y = bq.front().se;
bq.pop();
For ( i, 0, 4 )
{
int nx = x + ax[i];
int ny = y + ay[i];
if ( !valid(nx, ny) || mainMap[nx][ny] != 'G' || beeDistance[nx][ny] != -1 )
continue;
beeDistance[nx][ny] = beeDistance[x][y] + s;
bq.push({nx, ny});
}
}
beeDistance[dx][dy] = n * n * s;
int l = -1, r = 2 * n * n, m;
while (r - l > 1 )
{
m = (l + r) >> 1;
if ( test(m) ) l = m;
else r = m;
}
cout << l;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
5 |
Correct |
6 ms |
5240 KB |
Output is correct |
6 |
Correct |
6 ms |
5240 KB |
Output is correct |
7 |
Correct |
114 ms |
6756 KB |
Output is correct |
8 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
9 |
Correct |
6 ms |
5240 KB |
Output is correct |
10 |
Correct |
6 ms |
5240 KB |
Output is correct |
11 |
Correct |
6 ms |
5240 KB |
Output is correct |
12 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
13 |
Incorrect |
6 ms |
5284 KB |
Output isn't correct |
14 |
Correct |
7 ms |
5368 KB |
Output is correct |
15 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
16 |
Correct |
6 ms |
5244 KB |
Output is correct |
17 |
Incorrect |
7 ms |
5284 KB |
Output isn't correct |
18 |
Correct |
6 ms |
5288 KB |
Output is correct |
19 |
Incorrect |
6 ms |
5260 KB |
Output isn't correct |
20 |
Correct |
6 ms |
5240 KB |
Output is correct |
21 |
Incorrect |
7 ms |
5240 KB |
Output isn't correct |
22 |
Correct |
7 ms |
5240 KB |
Output is correct |
23 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
24 |
Correct |
6 ms |
5368 KB |
Output is correct |
25 |
Incorrect |
6 ms |
5240 KB |
Output isn't correct |
26 |
Correct |
7 ms |
5240 KB |
Output is correct |
27 |
Incorrect |
7 ms |
5240 KB |
Output isn't correct |
28 |
Correct |
7 ms |
5368 KB |
Output is correct |
29 |
Incorrect |
7 ms |
5240 KB |
Output isn't correct |
30 |
Correct |
8 ms |
5368 KB |
Output is correct |
31 |
Incorrect |
7 ms |
5368 KB |
Output isn't correct |
32 |
Correct |
7 ms |
5372 KB |
Output is correct |
33 |
Incorrect |
12 ms |
5752 KB |
Output isn't correct |
34 |
Correct |
10 ms |
5624 KB |
Output is correct |
35 |
Correct |
28 ms |
5624 KB |
Output is correct |
36 |
Incorrect |
11 ms |
5752 KB |
Output isn't correct |
37 |
Correct |
12 ms |
5724 KB |
Output is correct |
38 |
Correct |
37 ms |
5752 KB |
Output is correct |
39 |
Incorrect |
13 ms |
5876 KB |
Output isn't correct |
40 |
Correct |
13 ms |
5880 KB |
Output is correct |
41 |
Correct |
48 ms |
5880 KB |
Output is correct |
42 |
Incorrect |
14 ms |
6008 KB |
Output isn't correct |
43 |
Correct |
15 ms |
6052 KB |
Output is correct |
44 |
Correct |
60 ms |
6016 KB |
Output is correct |
45 |
Incorrect |
16 ms |
6008 KB |
Output isn't correct |
46 |
Correct |
16 ms |
6008 KB |
Output is correct |
47 |
Correct |
66 ms |
6028 KB |
Output is correct |
48 |
Incorrect |
17 ms |
6136 KB |
Output isn't correct |
49 |
Correct |
17 ms |
6096 KB |
Output is correct |
50 |
Correct |
85 ms |
6136 KB |
Output is correct |
51 |
Incorrect |
22 ms |
6264 KB |
Output isn't correct |
52 |
Correct |
21 ms |
6320 KB |
Output is correct |
53 |
Correct |
102 ms |
6264 KB |
Output is correct |
54 |
Incorrect |
21 ms |
6392 KB |
Output isn't correct |
55 |
Correct |
22 ms |
6392 KB |
Output is correct |
56 |
Correct |
125 ms |
6392 KB |
Output is correct |
57 |
Incorrect |
24 ms |
6520 KB |
Output isn't correct |
58 |
Correct |
24 ms |
6520 KB |
Output is correct |
59 |
Correct |
153 ms |
6664 KB |
Output is correct |
60 |
Incorrect |
25 ms |
6776 KB |
Output isn't correct |
61 |
Correct |
25 ms |
6648 KB |
Output is correct |
62 |
Correct |
157 ms |
6692 KB |
Output is correct |
63 |
Correct |
127 ms |
6696 KB |
Output is correct |
64 |
Correct |
244 ms |
6688 KB |
Output is correct |
65 |
Correct |
183 ms |
6728 KB |
Output is correct |
66 |
Incorrect |
163 ms |
6776 KB |
Output isn't correct |
67 |
Correct |
141 ms |
6656 KB |
Output is correct |
68 |
Correct |
60 ms |
6648 KB |
Output is correct |
69 |
Correct |
59 ms |
6648 KB |
Output is correct |
70 |
Correct |
46 ms |
6648 KB |
Output is correct |
71 |
Correct |
53 ms |
6648 KB |
Output is correct |
72 |
Incorrect |
45 ms |
6648 KB |
Output isn't correct |
73 |
Incorrect |
56 ms |
6904 KB |
Output isn't correct |
74 |
Correct |
72 ms |
6904 KB |
Output is correct |
75 |
Correct |
90 ms |
6904 KB |
Output is correct |
76 |
Correct |
81 ms |
6916 KB |
Output is correct |
77 |
Correct |
78 ms |
7032 KB |
Output is correct |
78 |
Correct |
100 ms |
6904 KB |
Output is correct |
79 |
Correct |
61 ms |
6904 KB |
Output is correct |
80 |
Correct |
77 ms |
6908 KB |
Output is correct |
81 |
Correct |
86 ms |
6904 KB |
Output is correct |
82 |
Correct |
76 ms |
6904 KB |
Output is correct |
83 |
Correct |
100 ms |
6904 KB |
Output is correct |
84 |
Correct |
92 ms |
6900 KB |
Output is correct |
85 |
Correct |
102 ms |
6904 KB |
Output is correct |
86 |
Correct |
103 ms |
7004 KB |
Output is correct |
87 |
Correct |
95 ms |
6812 KB |
Output is correct |
88 |
Correct |
107 ms |
6776 KB |
Output is correct |
89 |
Correct |
110 ms |
6776 KB |
Output is correct |
90 |
Correct |
114 ms |
6908 KB |
Output is correct |
91 |
Correct |
111 ms |
6776 KB |
Output is correct |
92 |
Correct |
117 ms |
6776 KB |
Output is correct |