# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
611689 |
2022-07-29T06:37:52 Z |
Belgutei |
Mecho (IOI09_mecho) |
C++17 |
|
153 ms |
8924 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,m;
int b[805][806];
queue<pair<int,int> > q;
int stx, sty;
int cnt[805][805];
int tmp[805][805];
bool check = 0;
char ch[805][805];
int main() {
IOS
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= n; j ++) {
cin >> ch[i][j];
if(ch[i][j] == 'H') {
b[i][j] = 1;
q.push({i,j});
}
if(ch[i][j] == 'M') {
stx = i;
sty = j;
}
}
}
while(q.size() > 0) {
int x = q.front().ff;
int y = q.front().ss;
q.pop();
if(x > 1 && b[x - 1][y] == 0 && ch[x - 1][y] != 'T' && ch[x - 1][y] != 'D') {
q.push({x - 1, y});
b[x - 1][y] = b[x][y] + 1;
}
if(x < n && b[x + 1][y] == 0 && ch[x + 1][y] != 'T' && ch[x + 1][y] != 'D') {
q.push({x + 1, y});
b[x + 1][y] = b[x][y] + 1;
}
if(y > 1 && b[x][y - 1] == 0 && ch[x][y - 1] != 'T' && ch[x][y - 1] != 'D') {
q.push({x, y - 1});
b[x][y - 1] = b[x][y] + 1;
}
if(y < n && b[x][y + 1] == 0 && ch[x][y + 1] != 'T' && ch[x][y + 1] != 'D') {
q.push({x, y + 1});
b[x][y + 1] = b[x][y] + 1;
}
}
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= n; j ++) {
if(b[i][j] == 0) b[i][j] = 1e9;
}
}
int l = 0;
int r = n * n;
while(l < r) {
int mid = (l + r + 1) / 2;
memset(cnt, -1, sizeof(cnt));
while(q.size() > 0) q.pop();
q.push({stx,sty});
cnt[stx][sty] = mid;
tmp[stx][sty] = m;
bool ok = 0;
while(q.size() > 0) {
int x = q.front().ff;
int y = q.front().ss;
q.pop();
int num = cnt[x][y];
int move = tmp[x][y];
if(tmp[x][y] == m) {
num ++;
move = 0;
}
move ++;
//
if(x > 1 && cnt[x - 1][y] == -1 && num < b[x - 1][y] && ch[x - 1][y] != 'T') {
if(ch[x - 1][y] == 'D') { // home location
ok = 1; break;
}
cnt[x - 1][y] = num;
tmp[x - 1][y] = move;
q.push({x - 1, y});
}
//
if(x < n && cnt[x + 1][y] == -1 && num < b[x + 1][y] && ch[x + 1][y] != 'T') {
if(ch[x + 1][y] == 'D') { // home location
ok = 1; break;
}
cnt[x + 1][y] = num;
tmp[x + 1][y] = move;
q.push({x + 1, y});
}
//
if(y > 1 && cnt[x][y - 1] == -1 && num < b[x][y - 1] && ch[x][y - 1] != 'T') {
if(ch[x][y - 1] == 'D') { // home location
ok = 1; break;
}
cnt[x][y - 1] = num;
tmp[x][y - 1] = move;
q.push({x, y - 1});
}
//
if(y < n && cnt[x][y + 1] == -1 && num < b[x][y + 1] && ch[x][y + 1] != 'T') {
if(ch[x][y + 1] == 'D') { // home location
ok = 1; break;
}
cnt[x][y + 1] = num;
tmp[x][y + 1] = move;
q.push({x, y + 1});
}
}
if(ok == 1) {
check = 1;
l = mid;
}
else r = mid - 1;
}
if(check == 1){
cout << l - 1;
}
else cout << -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2900 KB |
Output is correct |
2 |
Correct |
1 ms |
2900 KB |
Output is correct |
3 |
Correct |
2 ms |
2900 KB |
Output is correct |
4 |
Correct |
2 ms |
2900 KB |
Output is correct |
5 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
7 |
Incorrect |
72 ms |
7500 KB |
Output isn't correct |
8 |
Correct |
2 ms |
2900 KB |
Output is correct |
9 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
13 |
Correct |
2 ms |
3156 KB |
Output is correct |
14 |
Correct |
2 ms |
3200 KB |
Output is correct |
15 |
Correct |
2 ms |
2900 KB |
Output is correct |
16 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
17 |
Correct |
2 ms |
2900 KB |
Output is correct |
18 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
19 |
Correct |
2 ms |
2900 KB |
Output is correct |
20 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
21 |
Correct |
3 ms |
3028 KB |
Output is correct |
22 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
23 |
Correct |
2 ms |
3028 KB |
Output is correct |
24 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
25 |
Correct |
2 ms |
3036 KB |
Output is correct |
26 |
Incorrect |
3 ms |
3028 KB |
Output isn't correct |
27 |
Correct |
3 ms |
3028 KB |
Output is correct |
28 |
Incorrect |
3 ms |
3160 KB |
Output isn't correct |
29 |
Correct |
3 ms |
3156 KB |
Output is correct |
30 |
Incorrect |
3 ms |
3156 KB |
Output isn't correct |
31 |
Correct |
3 ms |
3156 KB |
Output is correct |
32 |
Incorrect |
3 ms |
3156 KB |
Output isn't correct |
33 |
Correct |
8 ms |
4156 KB |
Output is correct |
34 |
Incorrect |
6 ms |
4180 KB |
Output isn't correct |
35 |
Incorrect |
16 ms |
5332 KB |
Output isn't correct |
36 |
Correct |
7 ms |
4464 KB |
Output is correct |
37 |
Incorrect |
7 ms |
4436 KB |
Output isn't correct |
38 |
Incorrect |
21 ms |
5708 KB |
Output isn't correct |
39 |
Correct |
8 ms |
4564 KB |
Output is correct |
40 |
Incorrect |
8 ms |
4564 KB |
Output isn't correct |
41 |
Incorrect |
28 ms |
5972 KB |
Output isn't correct |
42 |
Correct |
8 ms |
4820 KB |
Output is correct |
43 |
Incorrect |
8 ms |
4820 KB |
Output isn't correct |
44 |
Incorrect |
38 ms |
6356 KB |
Output isn't correct |
45 |
Correct |
12 ms |
4948 KB |
Output is correct |
46 |
Incorrect |
11 ms |
5080 KB |
Output isn't correct |
47 |
Incorrect |
48 ms |
6756 KB |
Output isn't correct |
48 |
Correct |
12 ms |
5204 KB |
Output is correct |
49 |
Incorrect |
10 ms |
5204 KB |
Output isn't correct |
50 |
Incorrect |
47 ms |
7124 KB |
Output isn't correct |
51 |
Correct |
14 ms |
5352 KB |
Output is correct |
52 |
Incorrect |
12 ms |
5460 KB |
Output isn't correct |
53 |
Incorrect |
64 ms |
7464 KB |
Output isn't correct |
54 |
Correct |
15 ms |
5588 KB |
Output is correct |
55 |
Incorrect |
15 ms |
5576 KB |
Output isn't correct |
56 |
Incorrect |
70 ms |
7928 KB |
Output isn't correct |
57 |
Correct |
16 ms |
5768 KB |
Output is correct |
58 |
Incorrect |
14 ms |
5764 KB |
Output isn't correct |
59 |
Incorrect |
89 ms |
8180 KB |
Output isn't correct |
60 |
Correct |
17 ms |
5952 KB |
Output is correct |
61 |
Incorrect |
17 ms |
6080 KB |
Output isn't correct |
62 |
Incorrect |
112 ms |
8540 KB |
Output isn't correct |
63 |
Incorrect |
91 ms |
8528 KB |
Output isn't correct |
64 |
Incorrect |
153 ms |
8540 KB |
Output isn't correct |
65 |
Incorrect |
132 ms |
8536 KB |
Output isn't correct |
66 |
Correct |
111 ms |
8528 KB |
Output is correct |
67 |
Correct |
108 ms |
8532 KB |
Output is correct |
68 |
Incorrect |
43 ms |
8260 KB |
Output isn't correct |
69 |
Incorrect |
48 ms |
8504 KB |
Output isn't correct |
70 |
Incorrect |
42 ms |
8472 KB |
Output isn't correct |
71 |
Incorrect |
38 ms |
8532 KB |
Output isn't correct |
72 |
Correct |
30 ms |
6652 KB |
Output is correct |
73 |
Correct |
27 ms |
8704 KB |
Output is correct |
74 |
Incorrect |
47 ms |
8924 KB |
Output isn't correct |
75 |
Incorrect |
49 ms |
8752 KB |
Output isn't correct |
76 |
Incorrect |
51 ms |
8788 KB |
Output isn't correct |
77 |
Incorrect |
52 ms |
8720 KB |
Output isn't correct |
78 |
Correct |
54 ms |
7492 KB |
Output is correct |
79 |
Incorrect |
43 ms |
7236 KB |
Output isn't correct |
80 |
Incorrect |
50 ms |
7128 KB |
Output isn't correct |
81 |
Incorrect |
62 ms |
7308 KB |
Output isn't correct |
82 |
Incorrect |
45 ms |
7236 KB |
Output isn't correct |
83 |
Incorrect |
58 ms |
7376 KB |
Output isn't correct |
84 |
Incorrect |
55 ms |
7296 KB |
Output isn't correct |
85 |
Incorrect |
56 ms |
7388 KB |
Output isn't correct |
86 |
Incorrect |
79 ms |
7396 KB |
Output isn't correct |
87 |
Incorrect |
70 ms |
7356 KB |
Output isn't correct |
88 |
Incorrect |
83 ms |
7548 KB |
Output isn't correct |
89 |
Incorrect |
80 ms |
7432 KB |
Output isn't correct |
90 |
Incorrect |
74 ms |
7380 KB |
Output isn't correct |
91 |
Incorrect |
66 ms |
7524 KB |
Output isn't correct |
92 |
Incorrect |
65 ms |
7544 KB |
Output isn't correct |