#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
int dfx[4] = {1,-1,0,0}; int dfy[4] = {0,0,1,-1};
int main()
{
fast_cin();
#ifndef ONLINE_JUDGE
#ifdef _WIN32
freopen("input.in", "r", stdin);
freopen("input.out", "w", stdout);
#endif
#endif
int n,s; cin>>n>>s;
char arr[n][n];
int bees[n][n];
fill(bees[0],bees[0]+n*n,INT_MAX);
queue<p32> hq;
p32 start;
for (size_t i = 0; i < n; i++)
{
for (size_t j = 0; j < n; j++)
{
cin>>arr[i][j];
if(arr[i][j]=='H'){
bees[i][j] = 1;
hq.emplace(i,j);
}
if(arr[i][j]=='D') start = p32(i,j);
}
}
while(!hq.empty()){
for (size_t i = 0; i < 4; i++)
{
int x = hq.front().fi+dfx[i];
int y = hq.front().se+dfy[i];
if(x>=0&&x<n&&y>=0&&y<n&&bees[x][y]==INT_MAX&&arr[x][y]!='T'&&arr[x][y]!='M'){
bees[x][y] = bees[hq.front().fi][hq.front().se] + 1;
hq.emplace(x,y);
}
}
hq.pop();
}
int l = -1;
int r = 1000;
while(r-l>1){
int mid = (l+r)/2;
queue<p32> q;
q.push(start);
int depth[n][n];
memset(depth,0,sizeof depth);
depth[start.fi][start.se] = 1;
while(!q.empty()){
for (size_t i = 0; i < 4; i++)
{
int x = q.front().fi+dfx[i];
int y = q.front().se+dfy[i];
int d = depth[q.front().fi][q.front().se];
if(x>=0&&x<n&&y>=0&&y<n&&!depth[x][y]&&arr[x][y]!='T'&&(d+1)/s+mid<bees[x][y]){
if(arr[x][y]=='M'){
l = mid;
goto next;
}
depth[x][y] = d+1;
q.emplace(x,y);
}
}
q.pop();
}
r = mid;
next:
continue;
}
cout<<l<<'\n';
return 0;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:31:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
31 | for (size_t i = 0; i < n; i++)
| ~~^~~
mecho.cpp:33:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
33 | for (size_t j = 0; j < n; j++)
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
452 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
34 ms |
6164 KB |
Output isn't correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
456 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Correct |
0 ms |
456 KB |
Output is correct |
20 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
24 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
29 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
1372 KB |
Output isn't correct |
34 |
Incorrect |
3 ms |
1628 KB |
Output isn't correct |
35 |
Incorrect |
6 ms |
1372 KB |
Output isn't correct |
36 |
Incorrect |
4 ms |
1884 KB |
Output isn't correct |
37 |
Incorrect |
4 ms |
1884 KB |
Output isn't correct |
38 |
Incorrect |
9 ms |
1944 KB |
Output isn't correct |
39 |
Incorrect |
5 ms |
2140 KB |
Output isn't correct |
40 |
Incorrect |
5 ms |
2280 KB |
Output isn't correct |
41 |
Incorrect |
10 ms |
2396 KB |
Output isn't correct |
42 |
Incorrect |
6 ms |
2652 KB |
Output isn't correct |
43 |
Incorrect |
6 ms |
2652 KB |
Output isn't correct |
44 |
Incorrect |
12 ms |
2652 KB |
Output isn't correct |
45 |
Incorrect |
8 ms |
3164 KB |
Output isn't correct |
46 |
Incorrect |
7 ms |
3164 KB |
Output isn't correct |
47 |
Incorrect |
14 ms |
3296 KB |
Output isn't correct |
48 |
Incorrect |
8 ms |
3672 KB |
Output isn't correct |
49 |
Incorrect |
9 ms |
3676 KB |
Output isn't correct |
50 |
Incorrect |
17 ms |
3688 KB |
Output isn't correct |
51 |
Incorrect |
10 ms |
4440 KB |
Output isn't correct |
52 |
Incorrect |
10 ms |
4344 KB |
Output isn't correct |
53 |
Incorrect |
21 ms |
4444 KB |
Output isn't correct |
54 |
Incorrect |
11 ms |
4944 KB |
Output isn't correct |
55 |
Incorrect |
11 ms |
4956 KB |
Output isn't correct |
56 |
Incorrect |
23 ms |
4956 KB |
Output isn't correct |
57 |
Incorrect |
13 ms |
5456 KB |
Output isn't correct |
58 |
Incorrect |
13 ms |
5724 KB |
Output isn't correct |
59 |
Incorrect |
27 ms |
5724 KB |
Output isn't correct |
60 |
Incorrect |
15 ms |
6480 KB |
Output isn't correct |
61 |
Incorrect |
15 ms |
6228 KB |
Output isn't correct |
62 |
Incorrect |
30 ms |
6492 KB |
Output isn't correct |
63 |
Incorrect |
85 ms |
6276 KB |
Output isn't correct |
64 |
Incorrect |
113 ms |
6252 KB |
Output isn't correct |
65 |
Incorrect |
119 ms |
6692 KB |
Output isn't correct |
66 |
Incorrect |
105 ms |
6240 KB |
Output isn't correct |
67 |
Incorrect |
80 ms |
6484 KB |
Output isn't correct |
68 |
Incorrect |
42 ms |
6484 KB |
Output isn't correct |
69 |
Incorrect |
50 ms |
6480 KB |
Output isn't correct |
70 |
Incorrect |
43 ms |
6736 KB |
Output isn't correct |
71 |
Incorrect |
38 ms |
6328 KB |
Output isn't correct |
72 |
Incorrect |
27 ms |
6484 KB |
Output isn't correct |
73 |
Incorrect |
33 ms |
6768 KB |
Output isn't correct |
74 |
Incorrect |
35 ms |
6748 KB |
Output isn't correct |
75 |
Incorrect |
33 ms |
6624 KB |
Output isn't correct |
76 |
Incorrect |
40 ms |
6780 KB |
Output isn't correct |
77 |
Incorrect |
34 ms |
6736 KB |
Output isn't correct |
78 |
Incorrect |
35 ms |
6536 KB |
Output isn't correct |
79 |
Incorrect |
32 ms |
6764 KB |
Output isn't correct |
80 |
Incorrect |
53 ms |
6492 KB |
Output isn't correct |
81 |
Incorrect |
29 ms |
6492 KB |
Output isn't correct |
82 |
Incorrect |
32 ms |
6480 KB |
Output isn't correct |
83 |
Incorrect |
33 ms |
6484 KB |
Output isn't correct |
84 |
Incorrect |
33 ms |
6532 KB |
Output isn't correct |
85 |
Incorrect |
52 ms |
6492 KB |
Output isn't correct |
86 |
Incorrect |
33 ms |
6744 KB |
Output isn't correct |
87 |
Incorrect |
36 ms |
6748 KB |
Output isn't correct |
88 |
Incorrect |
35 ms |
6492 KB |
Output isn't correct |
89 |
Incorrect |
36 ms |
6492 KB |
Output isn't correct |
90 |
Incorrect |
36 ms |
6480 KB |
Output isn't correct |
91 |
Incorrect |
36 ms |
6492 KB |
Output isn't correct |
92 |
Incorrect |
35 ms |
6480 KB |
Output isn't correct |