# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1007492 |
2024-06-25T04:18:57 Z |
huutuan |
Mecho (IOI09_mecho) |
C++14 |
|
116 ms |
12120 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=810, dx[]={1, -1, 0, 0}, dy[]={0, 0, 1, -1};
int n, s;
char a[N][N];
int d[N][N], f[N][N];
int xm, ym, xd, yd;
bool check(int t){
queue<pair<int, int>> q;
memset(f, 0x3f, sizeof f);
q.emplace(xm, ym); f[xm][ym]=t*s;
if ((f[xm][ym]+s-1)/s>d[xm][ym]) return 0;
while (q.size()){
int x=q.front().first, y=q.front().second; q.pop();
if (x==xd && y==yd) return 1;
for (int i=0; i<4; ++i){
int u=x+dx[i], v=y+dy[i];
if (u<1 || v<1 || u>n || v>n || f[u][v]<1e18 || (f[x][y]+s)/s>d[u][v] || a[u][v]=='T') continue;
f[u][v]=f[x][y]+1;
q.emplace(u, v);
}
}
return 0;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> s;
queue<pair<int, int>> q;
memset(d, 0x3f, sizeof d);
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j){
cin >> a[i][j];
if (a[i][j]=='M') xm=i, ym=j;
if (a[i][j]=='D') xd=i, yd=j;
if (a[i][j]=='H'){
d[i][j]=0;
q.emplace(i, j);
}
}
while (q.size()){
int x=q.front().first, y=q.front().second; q.pop();
for (int i=0; i<4; ++i){
int u=x+dx[i], v=y+dy[i];
if (u<1 || v<1 || u>n || v>n || d[u][v]<1e18 || a[u][v]=='T' || a[u][v]=='D') continue;
d[u][v]=d[x][y]+1;
q.emplace(u, v);
}
}
int l=1, r=1e9;
while (l<=r){
int mid=(l+r)>>1;
if (check(mid)) l=mid+1;
else r=mid-1;
}
if (r==(int)1e9) r=-1;
cout << r << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
2 |
Incorrect |
4 ms |
10708 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
5 |
Correct |
4 ms |
10900 KB |
Output is correct |
6 |
Correct |
3 ms |
10844 KB |
Output is correct |
7 |
Correct |
49 ms |
11400 KB |
Output is correct |
8 |
Incorrect |
5 ms |
10844 KB |
Output isn't correct |
9 |
Correct |
4 ms |
10844 KB |
Output is correct |
10 |
Correct |
4 ms |
10844 KB |
Output is correct |
11 |
Correct |
4 ms |
10844 KB |
Output is correct |
12 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
10844 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
10844 KB |
Output isn't correct |
15 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
16 |
Correct |
3 ms |
10892 KB |
Output is correct |
17 |
Incorrect |
4 ms |
10896 KB |
Output isn't correct |
18 |
Correct |
4 ms |
10844 KB |
Output is correct |
19 |
Incorrect |
3 ms |
10844 KB |
Output isn't correct |
20 |
Correct |
4 ms |
10840 KB |
Output is correct |
21 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
22 |
Correct |
4 ms |
10892 KB |
Output is correct |
23 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
24 |
Correct |
4 ms |
10844 KB |
Output is correct |
25 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
26 |
Correct |
4 ms |
10840 KB |
Output is correct |
27 |
Incorrect |
4 ms |
10840 KB |
Output isn't correct |
28 |
Correct |
5 ms |
10840 KB |
Output is correct |
29 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
30 |
Correct |
4 ms |
10840 KB |
Output is correct |
31 |
Incorrect |
5 ms |
10840 KB |
Output isn't correct |
32 |
Correct |
5 ms |
10904 KB |
Output is correct |
33 |
Incorrect |
6 ms |
11008 KB |
Output isn't correct |
34 |
Correct |
6 ms |
10844 KB |
Output is correct |
35 |
Correct |
16 ms |
10844 KB |
Output is correct |
36 |
Incorrect |
7 ms |
10844 KB |
Output isn't correct |
37 |
Correct |
9 ms |
10840 KB |
Output is correct |
38 |
Correct |
20 ms |
11060 KB |
Output is correct |
39 |
Incorrect |
7 ms |
10840 KB |
Output isn't correct |
40 |
Correct |
8 ms |
10840 KB |
Output is correct |
41 |
Correct |
24 ms |
11100 KB |
Output is correct |
42 |
Incorrect |
8 ms |
11096 KB |
Output isn't correct |
43 |
Correct |
8 ms |
11100 KB |
Output is correct |
44 |
Correct |
30 ms |
11144 KB |
Output is correct |
45 |
Incorrect |
9 ms |
11100 KB |
Output isn't correct |
46 |
Correct |
9 ms |
11040 KB |
Output is correct |
47 |
Correct |
36 ms |
11096 KB |
Output is correct |
48 |
Incorrect |
10 ms |
11100 KB |
Output isn't correct |
49 |
Correct |
15 ms |
10968 KB |
Output is correct |
50 |
Correct |
42 ms |
11100 KB |
Output is correct |
51 |
Incorrect |
10 ms |
11100 KB |
Output isn't correct |
52 |
Correct |
11 ms |
11064 KB |
Output is correct |
53 |
Correct |
49 ms |
11100 KB |
Output is correct |
54 |
Incorrect |
11 ms |
11100 KB |
Output isn't correct |
55 |
Correct |
12 ms |
11100 KB |
Output is correct |
56 |
Correct |
60 ms |
11292 KB |
Output is correct |
57 |
Incorrect |
12 ms |
11100 KB |
Output isn't correct |
58 |
Correct |
12 ms |
11100 KB |
Output is correct |
59 |
Correct |
66 ms |
11112 KB |
Output is correct |
60 |
Incorrect |
13 ms |
11356 KB |
Output isn't correct |
61 |
Correct |
14 ms |
11356 KB |
Output is correct |
62 |
Correct |
77 ms |
11356 KB |
Output is correct |
63 |
Correct |
66 ms |
11192 KB |
Output is correct |
64 |
Correct |
109 ms |
11352 KB |
Output is correct |
65 |
Correct |
116 ms |
11356 KB |
Output is correct |
66 |
Incorrect |
86 ms |
11352 KB |
Output isn't correct |
67 |
Incorrect |
76 ms |
11356 KB |
Output isn't correct |
68 |
Correct |
33 ms |
11356 KB |
Output is correct |
69 |
Correct |
36 ms |
11352 KB |
Output is correct |
70 |
Correct |
32 ms |
11432 KB |
Output is correct |
71 |
Correct |
25 ms |
11348 KB |
Output is correct |
72 |
Incorrect |
23 ms |
11344 KB |
Output isn't correct |
73 |
Incorrect |
27 ms |
12120 KB |
Output isn't correct |
74 |
Correct |
41 ms |
11896 KB |
Output is correct |
75 |
Correct |
43 ms |
11868 KB |
Output is correct |
76 |
Correct |
38 ms |
11856 KB |
Output is correct |
77 |
Correct |
45 ms |
11856 KB |
Output is correct |
78 |
Incorrect |
45 ms |
11868 KB |
Output isn't correct |
79 |
Correct |
39 ms |
11844 KB |
Output is correct |
80 |
Correct |
42 ms |
11868 KB |
Output is correct |
81 |
Correct |
42 ms |
11860 KB |
Output is correct |
82 |
Correct |
38 ms |
11864 KB |
Output is correct |
83 |
Correct |
50 ms |
11608 KB |
Output is correct |
84 |
Correct |
48 ms |
11612 KB |
Output is correct |
85 |
Correct |
45 ms |
11608 KB |
Output is correct |
86 |
Correct |
51 ms |
11608 KB |
Output is correct |
87 |
Correct |
51 ms |
11608 KB |
Output is correct |
88 |
Correct |
47 ms |
11612 KB |
Output is correct |
89 |
Correct |
52 ms |
11612 KB |
Output is correct |
90 |
Correct |
55 ms |
11512 KB |
Output is correct |
91 |
Correct |
53 ms |
11664 KB |
Output is correct |
92 |
Correct |
45 ms |
11612 KB |
Output is correct |