# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
973043 |
2024-05-01T12:49:13 Z |
njoop |
Mecho (IOI09_mecho) |
C++14 |
|
238 ms |
10432 KB |
#include <bits/stdc++.h>
#define pi pair<int, int>
#define ti tuple<int, int, int>
#define tii tuple<int, int, int, int>
using namespace std;
int n, s, bee[810][810], stx, sty, enx, eny, cx, cy, cs, cdi, l=0, r=1e9, mid;
int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
pi mec[810][810];
vector<pi> hi;
char arr[810][810];
bool solve(int mn) {
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
mec[i][j] = {1e9, 1e9};
}
}
queue<tii> q;
q.push({stx, sty, 0, 0});
while(q.size()) {
cx = get<0>(q.front());
cy = get<1>(q.front());
cdi = get<2>(q.front());
cs = get<3>(q.front());
q.pop();
if(cs == s) {
cs = 0;
cdi++;
}
if(cx < 1 || cx > n || cy < 1 || cy > n || arr[cx][cy] == 'T' || mec[cx][cy].first <= cdi) continue;
if(mec[cx][cy].first == cdi && mec[cx][cy].second <= cs) continue;
if(cdi+mn >= bee[cx][cy]) continue;
mec[cx][cy] = {cdi, cs};
for(int i=0; i<4; i++) {
q.push({cx+di[i], cy+dj[i], cdi, cs+1});
}
}
return mec[enx][eny].first != 1e9;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> s;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
bee[i][j] = 1e9;
cin >> arr[i][j];
if(arr[i][j] == 'M') {
stx = i;
sty = j;
} else if(arr[i][j] == 'D') {
enx = i;
eny = j;
} else if(arr[i][j] == 'H') {
hi.push_back({i, j});
}
}
}
queue<ti> q;
for(auto i: hi) {
q.push({i.first, i.second, 0});
}
while(q.size()) {
cx = get<0>(q.front());
cy = get<1>(q.front());
cdi = get<2>(q.front());
q.pop();
if(cx < 1 || cx > n || cy < 1 || cy > n || arr[cx][cy] == 'T' || bee[cx][cy] <= cdi) continue;
bee[cx][cy] = cdi;
for(int i=0; i<4; i++) {
q.push({cx+di[i], cy+dj[i], cdi+1});
}
}
while(l < r) {
mid = (l+r)>>1;
if(solve(mid)) {
l = mid+1;
} else {
r = mid;
}
}
cout << max(0, l-1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4568 KB |
Output isn't correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
7 |
Incorrect |
140 ms |
9424 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4540 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4440 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
8 ms |
7352 KB |
Output is correct |
34 |
Correct |
9 ms |
7260 KB |
Output is correct |
35 |
Correct |
35 ms |
7380 KB |
Output is correct |
36 |
Correct |
11 ms |
7256 KB |
Output is correct |
37 |
Correct |
10 ms |
7524 KB |
Output is correct |
38 |
Correct |
45 ms |
7516 KB |
Output is correct |
39 |
Correct |
11 ms |
7512 KB |
Output is correct |
40 |
Correct |
12 ms |
7512 KB |
Output is correct |
41 |
Correct |
57 ms |
7516 KB |
Output is correct |
42 |
Correct |
13 ms |
7824 KB |
Output is correct |
43 |
Correct |
13 ms |
7772 KB |
Output is correct |
44 |
Correct |
86 ms |
8104 KB |
Output is correct |
45 |
Correct |
16 ms |
7772 KB |
Output is correct |
46 |
Correct |
17 ms |
7772 KB |
Output is correct |
47 |
Correct |
92 ms |
8012 KB |
Output is correct |
48 |
Correct |
20 ms |
8148 KB |
Output is correct |
49 |
Correct |
21 ms |
8028 KB |
Output is correct |
50 |
Correct |
120 ms |
8168 KB |
Output is correct |
51 |
Correct |
29 ms |
8300 KB |
Output is correct |
52 |
Correct |
25 ms |
8280 KB |
Output is correct |
53 |
Correct |
129 ms |
8336 KB |
Output is correct |
54 |
Correct |
28 ms |
8280 KB |
Output is correct |
55 |
Correct |
37 ms |
8284 KB |
Output is correct |
56 |
Correct |
152 ms |
8276 KB |
Output is correct |
57 |
Correct |
28 ms |
8536 KB |
Output is correct |
58 |
Correct |
30 ms |
8536 KB |
Output is correct |
59 |
Correct |
180 ms |
8544 KB |
Output is correct |
60 |
Correct |
32 ms |
8764 KB |
Output is correct |
61 |
Correct |
34 ms |
8720 KB |
Output is correct |
62 |
Correct |
201 ms |
9040 KB |
Output is correct |
63 |
Correct |
169 ms |
8784 KB |
Output is correct |
64 |
Correct |
232 ms |
8796 KB |
Output is correct |
65 |
Correct |
238 ms |
8792 KB |
Output is correct |
66 |
Correct |
166 ms |
8796 KB |
Output is correct |
67 |
Incorrect |
172 ms |
9044 KB |
Output isn't correct |
68 |
Correct |
72 ms |
8784 KB |
Output is correct |
69 |
Correct |
62 ms |
8784 KB |
Output is correct |
70 |
Correct |
59 ms |
8784 KB |
Output is correct |
71 |
Correct |
53 ms |
8944 KB |
Output is correct |
72 |
Correct |
47 ms |
8784 KB |
Output is correct |
73 |
Correct |
55 ms |
10128 KB |
Output is correct |
74 |
Correct |
103 ms |
10124 KB |
Output is correct |
75 |
Correct |
111 ms |
10320 KB |
Output is correct |
76 |
Correct |
122 ms |
10432 KB |
Output is correct |
77 |
Correct |
106 ms |
10324 KB |
Output is correct |
78 |
Incorrect |
127 ms |
10260 KB |
Output isn't correct |
79 |
Correct |
93 ms |
10024 KB |
Output is correct |
80 |
Correct |
102 ms |
10068 KB |
Output is correct |
81 |
Correct |
118 ms |
10256 KB |
Output is correct |
82 |
Correct |
95 ms |
10072 KB |
Output is correct |
83 |
Correct |
139 ms |
10032 KB |
Output is correct |
84 |
Correct |
116 ms |
9812 KB |
Output is correct |
85 |
Correct |
111 ms |
10012 KB |
Output is correct |
86 |
Correct |
124 ms |
10008 KB |
Output is correct |
87 |
Correct |
130 ms |
10000 KB |
Output is correct |
88 |
Correct |
130 ms |
9452 KB |
Output is correct |
89 |
Correct |
162 ms |
9732 KB |
Output is correct |
90 |
Correct |
142 ms |
9732 KB |
Output is correct |
91 |
Correct |
129 ms |
9628 KB |
Output is correct |
92 |
Correct |
156 ms |
9656 KB |
Output is correct |