# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
956827 |
2024-04-02T14:11:46 Z |
wood |
Mecho (IOI09_mecho) |
C++17 |
|
148 ms |
6484 KB |
#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]=='M') 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]!='D'){
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+s-1)/s+mid<bees[x][y]){
if(arr[x][y]=='D'&&mid<bees[start.fi][start.se]){
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++)
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
66 ms |
5980 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
396 KB |
Output isn't correct |
33 |
Incorrect |
3 ms |
1368 KB |
Output isn't correct |
34 |
Incorrect |
3 ms |
1368 KB |
Output isn't correct |
35 |
Correct |
15 ms |
1532 KB |
Output is correct |
36 |
Incorrect |
4 ms |
1628 KB |
Output isn't correct |
37 |
Incorrect |
4 ms |
1628 KB |
Output isn't correct |
38 |
Correct |
19 ms |
1628 KB |
Output is correct |
39 |
Incorrect |
6 ms |
2136 KB |
Output isn't correct |
40 |
Incorrect |
5 ms |
2336 KB |
Output isn't correct |
41 |
Correct |
24 ms |
2140 KB |
Output is correct |
42 |
Incorrect |
6 ms |
2600 KB |
Output isn't correct |
43 |
Incorrect |
6 ms |
2652 KB |
Output isn't correct |
44 |
Correct |
30 ms |
2648 KB |
Output is correct |
45 |
Incorrect |
7 ms |
2908 KB |
Output isn't correct |
46 |
Incorrect |
7 ms |
2908 KB |
Output isn't correct |
47 |
Correct |
39 ms |
2904 KB |
Output is correct |
48 |
Incorrect |
8 ms |
3416 KB |
Output isn't correct |
49 |
Incorrect |
11 ms |
3676 KB |
Output isn't correct |
50 |
Correct |
49 ms |
3492 KB |
Output is correct |
51 |
Incorrect |
10 ms |
3932 KB |
Output isn't correct |
52 |
Incorrect |
10 ms |
4060 KB |
Output isn't correct |
53 |
Correct |
55 ms |
3928 KB |
Output is correct |
54 |
Incorrect |
11 ms |
4700 KB |
Output isn't correct |
55 |
Incorrect |
11 ms |
4700 KB |
Output isn't correct |
56 |
Correct |
64 ms |
4752 KB |
Output is correct |
57 |
Incorrect |
13 ms |
5212 KB |
Output isn't correct |
58 |
Incorrect |
13 ms |
5212 KB |
Output isn't correct |
59 |
Correct |
75 ms |
5392 KB |
Output is correct |
60 |
Incorrect |
14 ms |
5976 KB |
Output isn't correct |
61 |
Incorrect |
15 ms |
5980 KB |
Output isn't correct |
62 |
Correct |
87 ms |
5980 KB |
Output is correct |
63 |
Correct |
86 ms |
5864 KB |
Output is correct |
64 |
Correct |
148 ms |
6136 KB |
Output is correct |
65 |
Correct |
131 ms |
6072 KB |
Output is correct |
66 |
Incorrect |
109 ms |
6064 KB |
Output isn't correct |
67 |
Correct |
84 ms |
5972 KB |
Output is correct |
68 |
Correct |
47 ms |
5980 KB |
Output is correct |
69 |
Correct |
35 ms |
5976 KB |
Output is correct |
70 |
Correct |
35 ms |
5980 KB |
Output is correct |
71 |
Correct |
30 ms |
5980 KB |
Output is correct |
72 |
Incorrect |
25 ms |
5968 KB |
Output isn't correct |
73 |
Incorrect |
26 ms |
6232 KB |
Output isn't correct |
74 |
Correct |
43 ms |
6348 KB |
Output is correct |
75 |
Correct |
48 ms |
6236 KB |
Output is correct |
76 |
Correct |
44 ms |
6232 KB |
Output is correct |
77 |
Correct |
43 ms |
6340 KB |
Output is correct |
78 |
Correct |
51 ms |
6236 KB |
Output is correct |
79 |
Correct |
50 ms |
6224 KB |
Output is correct |
80 |
Correct |
46 ms |
6236 KB |
Output is correct |
81 |
Correct |
52 ms |
6236 KB |
Output is correct |
82 |
Correct |
48 ms |
6236 KB |
Output is correct |
83 |
Correct |
59 ms |
6284 KB |
Output is correct |
84 |
Correct |
53 ms |
6236 KB |
Output is correct |
85 |
Correct |
52 ms |
6236 KB |
Output is correct |
86 |
Correct |
57 ms |
6228 KB |
Output is correct |
87 |
Correct |
59 ms |
6484 KB |
Output is correct |
88 |
Correct |
59 ms |
6224 KB |
Output is correct |
89 |
Correct |
59 ms |
6228 KB |
Output is correct |
90 |
Correct |
63 ms |
6480 KB |
Output is correct |
91 |
Correct |
59 ms |
5976 KB |
Output is correct |
92 |
Correct |
64 ms |
6232 KB |
Output is correct |