# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057786 |
2024-08-14T06:05:15 Z |
12345678 |
Mecho (IOI09_mecho) |
C++17 |
|
86 ms |
6436 KB |
#include <bits/stdc++.h>
using namespace std;
const int nx=805;
int n, s, mn[nx][nx], dx[4]={1, 0, 0, -1}, dy[4]={0, 1, -1, 0}, dp[nx][nx], f;
char mp[nx][nx];
pair<int, int> st, tg;
queue<pair<int, int>> q;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>s;
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) cin>>mp[i][j], mn[i][j]=1e9;
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) if (mp[i][j]=='M') st={i, j};
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) if (mp[i][j]=='H') q.push({i, j}), mn[i][j]=0;
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) if (mp[i][j]=='D') tg={i, j};
while (!q.empty())
{
auto [x, y]=q.front();
q.pop();
for (int i=0; i<4; i++)
{
int cx=x+dx[i], cy=y+dy[i];
if (cx<1||cx>n||cy<1||cy>n||mp[cx][cy]=='T'||mp[cx][cy]=='D') continue;
if (mn[cx][cy]>mn[x][y]+1) mn[cx][cy]=mn[x][y]+1, q.push({cx, cy});
}
}
int l=0, r=2*n;
while (l<r||r==0)
{
int md=(l+r+1)/2;
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j]=1e9;
if (mn[st.first][st.second]<=md)
{
r=md-1;
continue;
}
dp[st.first][st.second]=0;
q.push({st.first, st.second});
while (!q.empty())
{
auto [x, y]=q.front();
q.pop();
for (int i=0; i<4; i++)
{
int cx=x+dx[i], cy=y+dy[i];
if (cx<1||cx>n||cy<1||cy>n||mp[cx][cy]=='T'||mp[cx][cy]=='H') continue;
if (dp[cx][cy]>dp[x][y]+1&&(md+(dp[x][y]+1)/s)<mn[cx][cy]) dp[cx][cy]=dp[x][y]+1, q.push({cx, cy});
}
}
if (r==0)
{
if (dp[tg.first][tg.second]!=1e9) f=0;
else f=1;
break;
}
else
{
if (dp[tg.first][tg.second]!=1e9) l=md;
else r=md-1;
}
}
if (f) cout<<-1;
else cout<<l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
0 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
41 ms |
6268 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
0 ms |
4444 KB |
Output is correct |
10 |
Correct |
0 ms |
4444 KB |
Output is correct |
11 |
Correct |
0 ms |
4444 KB |
Output is correct |
12 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
13 |
Correct |
0 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
17 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
20 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
21 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
22 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
24 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
33 |
Incorrect |
7 ms |
4700 KB |
Output isn't correct |
34 |
Incorrect |
13 ms |
4740 KB |
Output isn't correct |
35 |
Correct |
11 ms |
4700 KB |
Output is correct |
36 |
Incorrect |
9 ms |
4696 KB |
Output isn't correct |
37 |
Incorrect |
13 ms |
4700 KB |
Output isn't correct |
38 |
Correct |
15 ms |
4700 KB |
Output is correct |
39 |
Incorrect |
11 ms |
5044 KB |
Output isn't correct |
40 |
Incorrect |
15 ms |
4956 KB |
Output isn't correct |
41 |
Correct |
20 ms |
4956 KB |
Output is correct |
42 |
Incorrect |
15 ms |
5212 KB |
Output isn't correct |
43 |
Incorrect |
19 ms |
4956 KB |
Output isn't correct |
44 |
Correct |
22 ms |
5208 KB |
Output is correct |
45 |
Incorrect |
17 ms |
5208 KB |
Output isn't correct |
46 |
Incorrect |
23 ms |
5368 KB |
Output isn't correct |
47 |
Correct |
27 ms |
5212 KB |
Output is correct |
48 |
Incorrect |
22 ms |
5468 KB |
Output isn't correct |
49 |
Incorrect |
28 ms |
5468 KB |
Output isn't correct |
50 |
Correct |
33 ms |
5468 KB |
Output is correct |
51 |
Incorrect |
29 ms |
5468 KB |
Output isn't correct |
52 |
Incorrect |
34 ms |
5464 KB |
Output isn't correct |
53 |
Correct |
41 ms |
5468 KB |
Output is correct |
54 |
Incorrect |
28 ms |
5832 KB |
Output isn't correct |
55 |
Incorrect |
41 ms |
5812 KB |
Output isn't correct |
56 |
Correct |
47 ms |
5720 KB |
Output is correct |
57 |
Incorrect |
33 ms |
5976 KB |
Output isn't correct |
58 |
Incorrect |
43 ms |
6228 KB |
Output isn't correct |
59 |
Correct |
55 ms |
5980 KB |
Output is correct |
60 |
Incorrect |
36 ms |
5976 KB |
Output isn't correct |
61 |
Incorrect |
50 ms |
6128 KB |
Output isn't correct |
62 |
Correct |
64 ms |
5976 KB |
Output is correct |
63 |
Correct |
60 ms |
5980 KB |
Output is correct |
64 |
Correct |
86 ms |
5980 KB |
Output is correct |
65 |
Correct |
83 ms |
5980 KB |
Output is correct |
66 |
Correct |
72 ms |
5976 KB |
Output is correct |
67 |
Correct |
68 ms |
5976 KB |
Output is correct |
68 |
Correct |
29 ms |
5976 KB |
Output is correct |
69 |
Correct |
24 ms |
5976 KB |
Output is correct |
70 |
Correct |
24 ms |
5980 KB |
Output is correct |
71 |
Correct |
22 ms |
5976 KB |
Output is correct |
72 |
Correct |
19 ms |
6168 KB |
Output is correct |
73 |
Correct |
21 ms |
6436 KB |
Output is correct |
74 |
Correct |
31 ms |
6232 KB |
Output is correct |
75 |
Correct |
37 ms |
6236 KB |
Output is correct |
76 |
Correct |
32 ms |
6236 KB |
Output is correct |
77 |
Correct |
36 ms |
6236 KB |
Output is correct |
78 |
Correct |
41 ms |
6236 KB |
Output is correct |
79 |
Correct |
31 ms |
6236 KB |
Output is correct |
80 |
Correct |
33 ms |
6236 KB |
Output is correct |
81 |
Correct |
39 ms |
6236 KB |
Output is correct |
82 |
Correct |
33 ms |
6412 KB |
Output is correct |
83 |
Correct |
42 ms |
6236 KB |
Output is correct |
84 |
Correct |
39 ms |
6236 KB |
Output is correct |
85 |
Correct |
40 ms |
6232 KB |
Output is correct |
86 |
Correct |
42 ms |
6232 KB |
Output is correct |
87 |
Correct |
37 ms |
6236 KB |
Output is correct |
88 |
Correct |
42 ms |
6236 KB |
Output is correct |
89 |
Correct |
43 ms |
6316 KB |
Output is correct |
90 |
Correct |
44 ms |
6300 KB |
Output is correct |
91 |
Correct |
45 ms |
6232 KB |
Output is correct |
92 |
Correct |
44 ms |
6236 KB |
Output is correct |