# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
739758 |
2023-05-11T08:46:45 Z |
gigabuffoon |
Mecho (IOI09_mecho) |
C++17 |
|
234 ms |
16960 KB |
#include<bits/stdc++.h>
using namespace std;
#define all(a) begin(a), end(a)
#define sz(a) (int)(size(a))
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define int long long
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
#define CASES 0
int N, S;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
const int MAXN = 800;
string grid[MAXN];
pii start, finish;
int wall[MAXN][MAXN];
int bee[MAXN][MAXN];
inline bool inBounds(const int r, const int c) {
return 0 <= r and r < N and 0 <= c and c < N and !wall[r][c];
}
void solve(int tc) {
cin >> N >> S;
rep(i,0,N) cin >> grid[i];
rep(i,0,N) rep(j,0,N) bee[i][j] = INT_MAX;
queue<pii> bq;
rep(i,0,N) rep(j,0,N) switch(grid[i][j]) {
case 'T':
wall[i][j] = 1;
break;
case 'M':
start = {i, j};
break;
case 'D':
wall[i][j] = 1;
finish = {i, j};
break;
case 'H':
bee[i][j] = 0;
bq.emplace(i, j);
break;
}
// bee-FS
while(sz(bq)) {
int r, c, rr, cc;
tie(r, c) = bq.front(); bq.pop();
rep(d,0,4) if(inBounds(rr = r + dr[d], cc = c+dc[d]))
if(bee[r][c] + S < bee[rr][cc])
bee[rr][cc] = bee[r][c] + S,
bq.emplace(rr, cc);
}
wall[finish.first][finish.second] = 0;
auto test = [&](int delay) {
vvi dist(N, vi(N, INT_MAX));
queue<pii> mq; mq.push(start);
dist[start.first][start.second] = delay * S;
while(sz(mq)) {
if(mq.front() == finish) return true;
int r, c, rr, cc;
tie(r, c) = mq.front(); mq.pop();
rep(d,0,4) if(inBounds(rr = r + dr[d], cc = c+dc[d]))
if(dist[r][c]+1 < dist[rr][cc] and dist[r][c]+1 < bee[rr][cc])
dist[rr][cc] = dist[r][c] + 1,
mq.emplace(rr, cc);
}
return false;
};
int res = -1;
for(int x = 1 << 19; x; x >>= 1)
if(test(res+x)) res += x;
cout << res << '\n';
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int T = 1, t = 0; if(CASES) cin >> T;
while(t++ < T) solve(t);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
115 ms |
13228 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Incorrect |
1 ms |
904 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
14 |
Correct |
1 ms |
852 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
484 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
852 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
1 ms |
852 KB |
Output is correct |
29 |
Correct |
1 ms |
852 KB |
Output is correct |
30 |
Correct |
1 ms |
980 KB |
Output is correct |
31 |
Correct |
1 ms |
864 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
9 ms |
5000 KB |
Output is correct |
34 |
Correct |
10 ms |
5748 KB |
Output is correct |
35 |
Correct |
27 ms |
5404 KB |
Output is correct |
36 |
Correct |
11 ms |
5916 KB |
Output is correct |
37 |
Correct |
13 ms |
6708 KB |
Output is correct |
38 |
Correct |
36 ms |
6344 KB |
Output is correct |
39 |
Correct |
15 ms |
6944 KB |
Output is correct |
40 |
Correct |
15 ms |
7828 KB |
Output is correct |
41 |
Correct |
47 ms |
7380 KB |
Output is correct |
42 |
Correct |
19 ms |
8044 KB |
Output is correct |
43 |
Correct |
22 ms |
9028 KB |
Output is correct |
44 |
Correct |
63 ms |
8448 KB |
Output is correct |
45 |
Correct |
24 ms |
9176 KB |
Output is correct |
46 |
Correct |
25 ms |
10272 KB |
Output is correct |
47 |
Correct |
83 ms |
9516 KB |
Output is correct |
48 |
Correct |
28 ms |
10372 KB |
Output is correct |
49 |
Correct |
27 ms |
11492 KB |
Output is correct |
50 |
Correct |
93 ms |
10692 KB |
Output is correct |
51 |
Correct |
32 ms |
11580 KB |
Output is correct |
52 |
Correct |
32 ms |
12816 KB |
Output is correct |
53 |
Correct |
120 ms |
11912 KB |
Output is correct |
54 |
Correct |
40 ms |
13032 KB |
Output is correct |
55 |
Correct |
36 ms |
14076 KB |
Output is correct |
56 |
Correct |
145 ms |
13060 KB |
Output is correct |
57 |
Correct |
49 ms |
14504 KB |
Output is correct |
58 |
Correct |
45 ms |
15412 KB |
Output is correct |
59 |
Correct |
158 ms |
14380 KB |
Output is correct |
60 |
Correct |
70 ms |
16024 KB |
Output is correct |
61 |
Correct |
48 ms |
16808 KB |
Output is correct |
62 |
Correct |
193 ms |
15716 KB |
Output is correct |
63 |
Correct |
172 ms |
16856 KB |
Output is correct |
64 |
Correct |
234 ms |
16788 KB |
Output is correct |
65 |
Correct |
221 ms |
16824 KB |
Output is correct |
66 |
Correct |
179 ms |
16748 KB |
Output is correct |
67 |
Correct |
166 ms |
16796 KB |
Output is correct |
68 |
Correct |
99 ms |
16864 KB |
Output is correct |
69 |
Correct |
91 ms |
16828 KB |
Output is correct |
70 |
Correct |
81 ms |
16840 KB |
Output is correct |
71 |
Correct |
68 ms |
16900 KB |
Output is correct |
72 |
Incorrect |
69 ms |
16824 KB |
Output isn't correct |
73 |
Incorrect |
73 ms |
16708 KB |
Output isn't correct |
74 |
Correct |
97 ms |
16660 KB |
Output is correct |
75 |
Correct |
107 ms |
16744 KB |
Output is correct |
76 |
Correct |
99 ms |
16696 KB |
Output is correct |
77 |
Correct |
101 ms |
16636 KB |
Output is correct |
78 |
Correct |
113 ms |
16652 KB |
Output is correct |
79 |
Correct |
86 ms |
16624 KB |
Output is correct |
80 |
Correct |
99 ms |
16584 KB |
Output is correct |
81 |
Correct |
106 ms |
16708 KB |
Output is correct |
82 |
Correct |
99 ms |
16612 KB |
Output is correct |
83 |
Correct |
119 ms |
16840 KB |
Output is correct |
84 |
Correct |
119 ms |
16728 KB |
Output is correct |
85 |
Correct |
107 ms |
16776 KB |
Output is correct |
86 |
Correct |
117 ms |
16812 KB |
Output is correct |
87 |
Correct |
118 ms |
16960 KB |
Output is correct |
88 |
Correct |
118 ms |
16600 KB |
Output is correct |
89 |
Correct |
121 ms |
16648 KB |
Output is correct |
90 |
Correct |
122 ms |
16588 KB |
Output is correct |
91 |
Correct |
128 ms |
16660 KB |
Output is correct |
92 |
Correct |
117 ms |
16616 KB |
Output is correct |