# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
393890 |
2021-04-24T19:02:15 Z |
MaisyDoge13 |
Mecho (IOI09_mecho) |
C++17 |
|
288 ms |
16360 KB |
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <array>
#include <set>
#include <climits>
#include <map>
#include <memory>
#include <string>
#include <deque>
using namespace std;
#define input "mecho.in"
#define output "mecho.out"
#define int long long
int n, s;
int ans=-1; //will be maxed during the binary search
vector<vector<int>> bees_reach;
deque<pair<int, int>> bees_bfs; //r, c start off while taking input
vector<string> a;//input field
vector<vector<int>> reach_copy;
deque<pair<int, int>> bfs_copy;
vector<pair<int, int>> dirs = {
{1, 0},
{-1, 0},
{0, 1},
{0, -1}
};
bool check(int m) {
vector<vector<int>> mecho_reach = reach_copy;
deque<pair<int, int>> mecho_bfs = bfs_copy;
if (bees_reach[mecho_bfs.front().first][mecho_bfs.front().second]<=(m*s)) return 0;
//do bfs with mecho's location except mech can never go to a tile with bees there less than or equal to (m*s)+steps
while (!mecho_bfs.empty()) {
pair<int, int> curr=mecho_bfs.front();
mecho_bfs.pop_front();
int r=curr.first, c=curr.second;
int curr_steps=mecho_reach[r][c];
//cout << "r " << r << " c " << c << " curr_steps " << curr_steps << endl;
if (a[r][c]=='D') {
return 1;
}
for (pair<int, int> dir: dirs) {
int new_r=r+dir.first, new_c=c+dir.second;
if (new_r<0 || new_r>=n || new_c<0 || new_c>=n || a[new_r][new_c]=='T' || mecho_reach[new_r][new_c]!=-1) continue;
if (bees_reach[new_r][new_c]<=(m*s)+curr_steps+1 && bees_reach[new_r][new_c]!=-1) continue;
mecho_reach[new_r][new_c]=curr_steps+1;
mecho_bfs.push_back({new_r, new_c});
}
}
return 0;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen(input, "r", stdin);
//freopen(output, "w", stdout);
cin >> n >> s;
bees_reach.resize(n, vector<int>(n, -1));
reach_copy.resize(n, vector<int>(n, -1));
a.reserve(n);
for (int r=0;r<n;r++) {
string s; cin >> s;
a.push_back(s);
for (int c=0;c<n;c++) {
if (a[r][c]=='H') {
bees_bfs.push_back({r, c});
bees_reach[r][c]=0;
}
else if (a[r][c]=='M') {
bfs_copy.push_back({r, c});
reach_copy[r][c]=0;
}
}
}
while (!bees_bfs.empty()) {
pair<int, int> curr=bees_bfs.front();
bees_bfs.pop_front();
int r=curr.first, c=curr.second; int curr_steps=bees_reach[r][c];
for (pair<int, int> dir: dirs) {
int new_r=r+dir.first, new_c=c+dir.second;
if (new_r<0 || new_r>=n || new_c<0 || new_c>=n || a[new_r][new_c]=='T' || a[new_r][new_c]=='D') continue;
if (bees_reach[new_r][new_c]==-1) {
bees_reach[new_r][new_c]=curr_steps+s;
bees_bfs.push_back({new_r, new_c});
}
}
}
int l=0, r=1000*1000;
while (l<=r) {
int m=(l+r)/2;
//cout << m << endl;
if (check(m)) {
ans=m;
l=m+1;
}
else {
r=m-1;
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
169 ms |
16340 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
10 ms |
3368 KB |
Output is correct |
34 |
Correct |
7 ms |
3384 KB |
Output is correct |
35 |
Correct |
30 ms |
3380 KB |
Output is correct |
36 |
Correct |
7 ms |
4300 KB |
Output is correct |
37 |
Correct |
7 ms |
4300 KB |
Output is correct |
38 |
Correct |
40 ms |
4364 KB |
Output is correct |
39 |
Correct |
20 ms |
5360 KB |
Output is correct |
40 |
Correct |
10 ms |
5324 KB |
Output is correct |
41 |
Correct |
59 ms |
5388 KB |
Output is correct |
42 |
Correct |
21 ms |
6596 KB |
Output is correct |
43 |
Correct |
13 ms |
6524 KB |
Output is correct |
44 |
Correct |
64 ms |
6636 KB |
Output is correct |
45 |
Correct |
25 ms |
7872 KB |
Output is correct |
46 |
Correct |
14 ms |
7844 KB |
Output is correct |
47 |
Correct |
94 ms |
7888 KB |
Output is correct |
48 |
Correct |
33 ms |
9308 KB |
Output is correct |
49 |
Correct |
18 ms |
9248 KB |
Output is correct |
50 |
Correct |
106 ms |
9288 KB |
Output is correct |
51 |
Correct |
37 ms |
10776 KB |
Output is correct |
52 |
Correct |
23 ms |
10804 KB |
Output is correct |
53 |
Correct |
119 ms |
10820 KB |
Output is correct |
54 |
Correct |
47 ms |
12492 KB |
Output is correct |
55 |
Correct |
27 ms |
12452 KB |
Output is correct |
56 |
Correct |
159 ms |
12620 KB |
Output is correct |
57 |
Correct |
53 ms |
14404 KB |
Output is correct |
58 |
Correct |
31 ms |
14232 KB |
Output is correct |
59 |
Correct |
174 ms |
14296 KB |
Output is correct |
60 |
Correct |
35 ms |
16084 KB |
Output is correct |
61 |
Correct |
35 ms |
16076 KB |
Output is correct |
62 |
Correct |
209 ms |
16200 KB |
Output is correct |
63 |
Correct |
194 ms |
16172 KB |
Output is correct |
64 |
Correct |
288 ms |
16136 KB |
Output is correct |
65 |
Correct |
245 ms |
16288 KB |
Output is correct |
66 |
Correct |
198 ms |
16184 KB |
Output is correct |
67 |
Correct |
179 ms |
16176 KB |
Output is correct |
68 |
Correct |
105 ms |
16256 KB |
Output is correct |
69 |
Correct |
110 ms |
16240 KB |
Output is correct |
70 |
Correct |
98 ms |
16260 KB |
Output is correct |
71 |
Correct |
88 ms |
16244 KB |
Output is correct |
72 |
Correct |
80 ms |
16220 KB |
Output is correct |
73 |
Correct |
95 ms |
16312 KB |
Output is correct |
74 |
Correct |
125 ms |
16360 KB |
Output is correct |
75 |
Correct |
127 ms |
16264 KB |
Output is correct |
76 |
Correct |
119 ms |
16228 KB |
Output is correct |
77 |
Correct |
127 ms |
16256 KB |
Output is correct |
78 |
Correct |
133 ms |
16268 KB |
Output is correct |
79 |
Correct |
109 ms |
16232 KB |
Output is correct |
80 |
Correct |
116 ms |
16212 KB |
Output is correct |
81 |
Correct |
133 ms |
16248 KB |
Output is correct |
82 |
Correct |
107 ms |
16336 KB |
Output is correct |
83 |
Correct |
152 ms |
16216 KB |
Output is correct |
84 |
Correct |
143 ms |
16228 KB |
Output is correct |
85 |
Correct |
135 ms |
16220 KB |
Output is correct |
86 |
Correct |
146 ms |
16236 KB |
Output is correct |
87 |
Correct |
145 ms |
16252 KB |
Output is correct |
88 |
Correct |
153 ms |
16208 KB |
Output is correct |
89 |
Correct |
156 ms |
16240 KB |
Output is correct |
90 |
Correct |
168 ms |
16236 KB |
Output is correct |
91 |
Correct |
152 ms |
16220 KB |
Output is correct |
92 |
Correct |
159 ms |
16264 KB |
Output is correct |