# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
973047 |
2024-05-01T12:52:50 Z |
njoop |
Mecho (IOI09_mecho) |
C++14 |
|
288 ms |
10580 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+(cs ? 1 : 0) >= 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 << l;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
4696 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
4444 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 |
146 ms |
9420 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Incorrect |
1 ms |
4568 KB |
Output isn't correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Incorrect |
8 ms |
7260 KB |
Output isn't correct |
34 |
Correct |
12 ms |
7512 KB |
Output is correct |
35 |
Correct |
35 ms |
7380 KB |
Output is correct |
36 |
Incorrect |
9 ms |
7260 KB |
Output isn't correct |
37 |
Correct |
10 ms |
7516 KB |
Output is correct |
38 |
Correct |
48 ms |
7712 KB |
Output is correct |
39 |
Incorrect |
12 ms |
7516 KB |
Output isn't correct |
40 |
Correct |
15 ms |
7516 KB |
Output is correct |
41 |
Correct |
61 ms |
7688 KB |
Output is correct |
42 |
Incorrect |
16 ms |
7772 KB |
Output isn't correct |
43 |
Correct |
19 ms |
8024 KB |
Output is correct |
44 |
Correct |
77 ms |
7848 KB |
Output is correct |
45 |
Incorrect |
17 ms |
7772 KB |
Output isn't correct |
46 |
Correct |
17 ms |
7960 KB |
Output is correct |
47 |
Correct |
90 ms |
8012 KB |
Output is correct |
48 |
Incorrect |
20 ms |
8024 KB |
Output isn't correct |
49 |
Correct |
21 ms |
8028 KB |
Output is correct |
50 |
Correct |
119 ms |
8432 KB |
Output is correct |
51 |
Incorrect |
23 ms |
8308 KB |
Output isn't correct |
52 |
Correct |
29 ms |
8284 KB |
Output is correct |
53 |
Correct |
130 ms |
8336 KB |
Output is correct |
54 |
Incorrect |
29 ms |
8284 KB |
Output isn't correct |
55 |
Correct |
33 ms |
8460 KB |
Output is correct |
56 |
Correct |
163 ms |
8756 KB |
Output is correct |
57 |
Incorrect |
28 ms |
8540 KB |
Output isn't correct |
58 |
Correct |
29 ms |
8540 KB |
Output is correct |
59 |
Correct |
172 ms |
8536 KB |
Output is correct |
60 |
Incorrect |
31 ms |
8536 KB |
Output isn't correct |
61 |
Correct |
33 ms |
8780 KB |
Output is correct |
62 |
Correct |
213 ms |
8824 KB |
Output is correct |
63 |
Correct |
138 ms |
8780 KB |
Output is correct |
64 |
Correct |
288 ms |
8800 KB |
Output is correct |
65 |
Correct |
230 ms |
8796 KB |
Output is correct |
66 |
Incorrect |
172 ms |
8780 KB |
Output isn't correct |
67 |
Incorrect |
169 ms |
9032 KB |
Output isn't correct |
68 |
Correct |
75 ms |
8948 KB |
Output is correct |
69 |
Correct |
69 ms |
8784 KB |
Output is correct |
70 |
Correct |
57 ms |
8948 KB |
Output is correct |
71 |
Correct |
56 ms |
8792 KB |
Output is correct |
72 |
Incorrect |
47 ms |
8788 KB |
Output isn't correct |
73 |
Incorrect |
61 ms |
10388 KB |
Output isn't correct |
74 |
Correct |
112 ms |
10260 KB |
Output is correct |
75 |
Correct |
113 ms |
10436 KB |
Output is correct |
76 |
Correct |
105 ms |
10580 KB |
Output is correct |
77 |
Correct |
107 ms |
10320 KB |
Output is correct |
78 |
Incorrect |
130 ms |
10260 KB |
Output isn't correct |
79 |
Correct |
97 ms |
10020 KB |
Output is correct |
80 |
Correct |
112 ms |
10416 KB |
Output is correct |
81 |
Correct |
107 ms |
10068 KB |
Output is correct |
82 |
Correct |
102 ms |
10260 KB |
Output is correct |
83 |
Correct |
130 ms |
9968 KB |
Output is correct |
84 |
Correct |
114 ms |
9820 KB |
Output is correct |
85 |
Correct |
114 ms |
9812 KB |
Output is correct |
86 |
Correct |
127 ms |
10004 KB |
Output is correct |
87 |
Correct |
120 ms |
9816 KB |
Output is correct |
88 |
Correct |
137 ms |
9520 KB |
Output is correct |
89 |
Correct |
157 ms |
9736 KB |
Output is correct |
90 |
Correct |
157 ms |
9732 KB |
Output is correct |
91 |
Correct |
133 ms |
9448 KB |
Output is correct |
92 |
Correct |
136 ms |
9476 KB |
Output is correct |