# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
611674 |
2022-07-29T06:30:43 Z |
Belgutei |
Mecho (IOI09_mecho) |
C++17 |
|
175 ms |
9564 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() {
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, 0, 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] == 0 && 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] == 0 && 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] == 0 && 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] == 0 && 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});
}
}
//
// cout << mid << ' ' << ok << "\n";
if(ok == 1) {
check = 1;
l = mid;
}
else r = mid - 1;
// if(mid == 0) {
// for(int i = 1; i <= n; i ++) {
// for(int j = 1; j <= n; j ++) {
// cout << cnt[i][j] << ' ';
// }
// cout << '\n';
// }
// }
}
if(check == 1){
cout << l;
}
else cout << -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2772 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
2872 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
2876 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
2876 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
2772 KB |
Output isn't correct |
6 |
Correct |
2 ms |
2900 KB |
Output is correct |
7 |
Correct |
99 ms |
8084 KB |
Output is correct |
8 |
Correct |
2 ms |
2900 KB |
Output is correct |
9 |
Correct |
2 ms |
2900 KB |
Output is correct |
10 |
Correct |
2 ms |
2900 KB |
Output is correct |
11 |
Correct |
2 ms |
2900 KB |
Output is correct |
12 |
Incorrect |
4 ms |
3004 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
3132 KB |
Output isn't correct |
14 |
Correct |
3 ms |
3132 KB |
Output is correct |
15 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
16 |
Correct |
2 ms |
2900 KB |
Output is correct |
17 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
18 |
Correct |
2 ms |
2900 KB |
Output is correct |
19 |
Incorrect |
2 ms |
2900 KB |
Output isn't correct |
20 |
Correct |
2 ms |
2900 KB |
Output is correct |
21 |
Incorrect |
3 ms |
3028 KB |
Output isn't correct |
22 |
Correct |
2 ms |
3028 KB |
Output is correct |
23 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
24 |
Correct |
3 ms |
3028 KB |
Output is correct |
25 |
Incorrect |
3 ms |
3000 KB |
Output isn't correct |
26 |
Correct |
2 ms |
3000 KB |
Output is correct |
27 |
Incorrect |
3 ms |
3132 KB |
Output isn't correct |
28 |
Correct |
3 ms |
3156 KB |
Output is correct |
29 |
Incorrect |
3 ms |
3156 KB |
Output isn't correct |
30 |
Correct |
3 ms |
3136 KB |
Output is correct |
31 |
Incorrect |
3 ms |
3156 KB |
Output isn't correct |
32 |
Correct |
3 ms |
3156 KB |
Output is correct |
33 |
Incorrect |
11 ms |
4268 KB |
Output isn't correct |
34 |
Correct |
12 ms |
4388 KB |
Output is correct |
35 |
Correct |
23 ms |
5452 KB |
Output is correct |
36 |
Incorrect |
14 ms |
4600 KB |
Output isn't correct |
37 |
Correct |
14 ms |
4576 KB |
Output is correct |
38 |
Correct |
29 ms |
5828 KB |
Output is correct |
39 |
Incorrect |
17 ms |
4820 KB |
Output isn't correct |
40 |
Correct |
17 ms |
4768 KB |
Output is correct |
41 |
Correct |
41 ms |
6220 KB |
Output is correct |
42 |
Incorrect |
19 ms |
5076 KB |
Output isn't correct |
43 |
Correct |
19 ms |
5076 KB |
Output is correct |
44 |
Correct |
44 ms |
6636 KB |
Output is correct |
45 |
Incorrect |
23 ms |
5212 KB |
Output isn't correct |
46 |
Correct |
23 ms |
5224 KB |
Output is correct |
47 |
Correct |
57 ms |
7032 KB |
Output is correct |
48 |
Incorrect |
29 ms |
5588 KB |
Output isn't correct |
49 |
Correct |
29 ms |
5584 KB |
Output is correct |
50 |
Correct |
62 ms |
7372 KB |
Output is correct |
51 |
Incorrect |
34 ms |
5840 KB |
Output isn't correct |
52 |
Correct |
31 ms |
5824 KB |
Output is correct |
53 |
Correct |
101 ms |
7868 KB |
Output is correct |
54 |
Incorrect |
42 ms |
6028 KB |
Output isn't correct |
55 |
Correct |
42 ms |
6088 KB |
Output is correct |
56 |
Correct |
116 ms |
8272 KB |
Output is correct |
57 |
Incorrect |
43 ms |
6284 KB |
Output isn't correct |
58 |
Correct |
43 ms |
6292 KB |
Output is correct |
59 |
Correct |
115 ms |
8788 KB |
Output is correct |
60 |
Incorrect |
52 ms |
6604 KB |
Output isn't correct |
61 |
Correct |
46 ms |
6604 KB |
Output is correct |
62 |
Correct |
123 ms |
9136 KB |
Output is correct |
63 |
Incorrect |
107 ms |
9136 KB |
Output isn't correct |
64 |
Correct |
175 ms |
9104 KB |
Output is correct |
65 |
Correct |
146 ms |
9088 KB |
Output is correct |
66 |
Incorrect |
130 ms |
9088 KB |
Output isn't correct |
67 |
Correct |
135 ms |
9136 KB |
Output is correct |
68 |
Incorrect |
69 ms |
8880 KB |
Output isn't correct |
69 |
Correct |
64 ms |
9164 KB |
Output is correct |
70 |
Correct |
64 ms |
9152 KB |
Output is correct |
71 |
Correct |
61 ms |
9136 KB |
Output is correct |
72 |
Incorrect |
59 ms |
7180 KB |
Output isn't correct |
73 |
Incorrect |
58 ms |
9284 KB |
Output isn't correct |
74 |
Correct |
70 ms |
9344 KB |
Output is correct |
75 |
Correct |
78 ms |
9412 KB |
Output is correct |
76 |
Correct |
87 ms |
9564 KB |
Output is correct |
77 |
Correct |
86 ms |
9408 KB |
Output is correct |
78 |
Correct |
97 ms |
8024 KB |
Output is correct |
79 |
Correct |
70 ms |
7668 KB |
Output is correct |
80 |
Correct |
79 ms |
7824 KB |
Output is correct |
81 |
Correct |
78 ms |
7868 KB |
Output is correct |
82 |
Correct |
82 ms |
7796 KB |
Output is correct |
83 |
Incorrect |
105 ms |
8048 KB |
Output isn't correct |
84 |
Correct |
85 ms |
7840 KB |
Output is correct |
85 |
Correct |
91 ms |
8148 KB |
Output is correct |
86 |
Correct |
107 ms |
7984 KB |
Output is correct |
87 |
Correct |
83 ms |
7980 KB |
Output is correct |
88 |
Incorrect |
92 ms |
8148 KB |
Output isn't correct |
89 |
Correct |
133 ms |
8000 KB |
Output is correct |
90 |
Correct |
120 ms |
8004 KB |
Output is correct |
91 |
Correct |
111 ms |
8144 KB |
Output is correct |
92 |
Correct |
94 ms |
8140 KB |
Output is correct |