# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
393882 |
2021-04-24T18:47:03 Z |
MaisyDoge13 |
Mecho (IOI09_mecho) |
C++17 |
|
254 ms |
16416 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;
//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 |
204 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 |
162 ms |
16228 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 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
336 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 |
3372 KB |
Output is correct |
34 |
Correct |
7 ms |
3356 KB |
Output is correct |
35 |
Correct |
30 ms |
3372 KB |
Output is correct |
36 |
Correct |
7 ms |
4304 KB |
Output is correct |
37 |
Correct |
7 ms |
4308 KB |
Output is correct |
38 |
Correct |
42 ms |
4300 KB |
Output is correct |
39 |
Correct |
17 ms |
5376 KB |
Output is correct |
40 |
Correct |
11 ms |
5356 KB |
Output is correct |
41 |
Correct |
48 ms |
5420 KB |
Output is correct |
42 |
Correct |
21 ms |
6568 KB |
Output is correct |
43 |
Correct |
13 ms |
6532 KB |
Output is correct |
44 |
Correct |
65 ms |
6572 KB |
Output is correct |
45 |
Correct |
25 ms |
7860 KB |
Output is correct |
46 |
Correct |
16 ms |
7828 KB |
Output is correct |
47 |
Correct |
80 ms |
7904 KB |
Output is correct |
48 |
Correct |
34 ms |
9300 KB |
Output is correct |
49 |
Correct |
18 ms |
9228 KB |
Output is correct |
50 |
Correct |
102 ms |
9320 KB |
Output is correct |
51 |
Correct |
39 ms |
10808 KB |
Output is correct |
52 |
Correct |
22 ms |
10804 KB |
Output is correct |
53 |
Correct |
123 ms |
10840 KB |
Output is correct |
54 |
Correct |
44 ms |
12516 KB |
Output is correct |
55 |
Correct |
29 ms |
12460 KB |
Output is correct |
56 |
Correct |
142 ms |
12500 KB |
Output is correct |
57 |
Correct |
54 ms |
14328 KB |
Output is correct |
58 |
Correct |
32 ms |
14228 KB |
Output is correct |
59 |
Correct |
173 ms |
14276 KB |
Output is correct |
60 |
Correct |
33 ms |
16204 KB |
Output is correct |
61 |
Correct |
33 ms |
16112 KB |
Output is correct |
62 |
Correct |
203 ms |
16244 KB |
Output is correct |
63 |
Correct |
165 ms |
16156 KB |
Output is correct |
64 |
Correct |
250 ms |
16164 KB |
Output is correct |
65 |
Correct |
254 ms |
16176 KB |
Output is correct |
66 |
Correct |
202 ms |
16212 KB |
Output is correct |
67 |
Correct |
174 ms |
16180 KB |
Output is correct |
68 |
Correct |
105 ms |
16244 KB |
Output is correct |
69 |
Correct |
106 ms |
16244 KB |
Output is correct |
70 |
Correct |
100 ms |
16228 KB |
Output is correct |
71 |
Correct |
91 ms |
16416 KB |
Output is correct |
72 |
Incorrect |
84 ms |
16284 KB |
Output isn't correct |
73 |
Incorrect |
85 ms |
16300 KB |
Output isn't correct |
74 |
Correct |
120 ms |
16236 KB |
Output is correct |
75 |
Correct |
132 ms |
16284 KB |
Output is correct |
76 |
Correct |
119 ms |
16236 KB |
Output is correct |
77 |
Correct |
124 ms |
16288 KB |
Output is correct |
78 |
Correct |
129 ms |
16272 KB |
Output is correct |
79 |
Correct |
112 ms |
16280 KB |
Output is correct |
80 |
Correct |
124 ms |
16200 KB |
Output is correct |
81 |
Correct |
131 ms |
16300 KB |
Output is correct |
82 |
Correct |
119 ms |
16360 KB |
Output is correct |
83 |
Correct |
157 ms |
16232 KB |
Output is correct |
84 |
Correct |
145 ms |
16272 KB |
Output is correct |
85 |
Correct |
139 ms |
16228 KB |
Output is correct |
86 |
Correct |
151 ms |
16228 KB |
Output is correct |
87 |
Correct |
149 ms |
16244 KB |
Output is correct |
88 |
Correct |
152 ms |
16196 KB |
Output is correct |
89 |
Correct |
158 ms |
16216 KB |
Output is correct |
90 |
Correct |
162 ms |
16312 KB |
Output is correct |
91 |
Correct |
156 ms |
16296 KB |
Output is correct |
92 |
Correct |
157 ms |
16224 KB |
Output is correct |