# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1100001 |
2024-10-12T11:05:35 Z |
chaoslong |
Mecho (IOI09_mecho) |
C++14 |
|
169 ms |
18076 KB |
// Calm down.
// Think three times, code twice.
#include "bits/stdc++.h"
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <ll,ll>
#define pll pair <ll,ll>
#define piii pair <ll,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7; // 998244353
const ll oo = 1e18;
pii bd, en;
ll n, s, dx[] {1, -1, 0, 0}, dy[] {0, 0, 1, -1}, d[1005][1005], d1[1005][1005];
char a[1005][1005];
queue<piii> q;
bool check(ll x, ll y) {
if(x > n || x < 1 || y > n || y < 1 || a[x][y] == 'T') return false;
return true;
}
bool kt(ll mid) {
if(mid >= d[bd.st][bd.nd]) return false;
memset(d1, 0, sizeof d1);
q.push({mid * s, {bd.st, bd.nd}});
while(q.size()) {
ll dxy = q.front().st, x = q.front().nd.st, y = q.front().nd.nd; q.pop();
if(d1[x][y]) continue;
d1[x][y] = 1;
forr(i, 0, 3) {
ll nx = x + dx[i], ny = y + dy[i];
if(!check(nx, ny)) continue;
if((dxy + 1) / s < d[nx][ny]) {
// cout << nx << " " << ny << " " << dxy + 1 << " " << d[nx][ny] << " " << (dxy + 1) / s + ((dxy + 1) % s != 0) << "\n";
q.push({dxy + 1, {nx, ny}});
}
}
}
return d1[en.st][en.nd];
}
void to_nho_cau() {
cin >> n >> s;
memset(d, 63, sizeof d);
forr(i, 1, n) {
forr(j, 1, n) {
cin >> a[i][j];
if(a[i][j] == 'H') {
d[i][j] = 0;
q.push({0, {i, j}});
}
if(a[i][j] == 'M') bd = {i, j};
if(a[i][j] == 'D') en = {i, j};
}
}
while(q.size()) {
ll dxy = q.front().st, x = q.front().nd.st, y = q.front().nd.nd; q.pop();
if(d[x][y] < dxy) continue;
forr(i, 0, 3) {
ll nx = x + dx[i], ny = y + dy[i];
if(!check(nx, ny) || a[nx][ny] == 'D') continue;
if(dxy + 1 < d[nx][ny]) {
d[nx][ny] = dxy + 1;
q.push({dxy + 1, {nx, ny}});
}
}
}
ll l = 0, r = mod, ans = -1;
while(l <= r) {
ll mid = (l + r) >> 1;
if(kt(mid)) {
ans = mid;
l = mid + 1;
} else r = mid - 1;
}
cout << ans << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
// #ifdef LOCAL
//freopen(file".inp","r",stdin);
//freopen(file".out","w",stdout);
// #endif
int t = 1;
//cin >> t;
while(t--) to_nho_cau();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16988 KB |
Output is correct |
2 |
Correct |
3 ms |
16988 KB |
Output is correct |
3 |
Correct |
3 ms |
17076 KB |
Output is correct |
4 |
Correct |
3 ms |
16988 KB |
Output is correct |
5 |
Correct |
3 ms |
16988 KB |
Output is correct |
6 |
Correct |
3 ms |
16988 KB |
Output is correct |
7 |
Correct |
132 ms |
17572 KB |
Output is correct |
8 |
Correct |
3 ms |
16984 KB |
Output is correct |
9 |
Correct |
3 ms |
16984 KB |
Output is correct |
10 |
Correct |
4 ms |
17092 KB |
Output is correct |
11 |
Correct |
2 ms |
16988 KB |
Output is correct |
12 |
Correct |
3 ms |
16988 KB |
Output is correct |
13 |
Correct |
3 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
3 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
16988 KB |
Output is correct |
17 |
Correct |
4 ms |
16988 KB |
Output is correct |
18 |
Correct |
3 ms |
16984 KB |
Output is correct |
19 |
Correct |
3 ms |
16988 KB |
Output is correct |
20 |
Correct |
3 ms |
16988 KB |
Output is correct |
21 |
Correct |
4 ms |
16984 KB |
Output is correct |
22 |
Correct |
3 ms |
16988 KB |
Output is correct |
23 |
Correct |
3 ms |
16988 KB |
Output is correct |
24 |
Correct |
3 ms |
16988 KB |
Output is correct |
25 |
Correct |
3 ms |
16988 KB |
Output is correct |
26 |
Correct |
3 ms |
16988 KB |
Output is correct |
27 |
Correct |
3 ms |
16988 KB |
Output is correct |
28 |
Correct |
3 ms |
16984 KB |
Output is correct |
29 |
Correct |
3 ms |
16984 KB |
Output is correct |
30 |
Correct |
3 ms |
16988 KB |
Output is correct |
31 |
Correct |
4 ms |
16988 KB |
Output is correct |
32 |
Correct |
3 ms |
16988 KB |
Output is correct |
33 |
Correct |
7 ms |
17220 KB |
Output is correct |
34 |
Correct |
7 ms |
17244 KB |
Output is correct |
35 |
Correct |
32 ms |
17244 KB |
Output is correct |
36 |
Correct |
7 ms |
17244 KB |
Output is correct |
37 |
Correct |
7 ms |
17244 KB |
Output is correct |
38 |
Correct |
42 ms |
17240 KB |
Output is correct |
39 |
Correct |
9 ms |
17240 KB |
Output is correct |
40 |
Correct |
8 ms |
17244 KB |
Output is correct |
41 |
Correct |
52 ms |
17260 KB |
Output is correct |
42 |
Correct |
8 ms |
17244 KB |
Output is correct |
43 |
Correct |
7 ms |
17244 KB |
Output is correct |
44 |
Correct |
67 ms |
17240 KB |
Output is correct |
45 |
Correct |
11 ms |
17240 KB |
Output is correct |
46 |
Correct |
10 ms |
17244 KB |
Output is correct |
47 |
Correct |
81 ms |
17284 KB |
Output is correct |
48 |
Correct |
13 ms |
17244 KB |
Output is correct |
49 |
Correct |
13 ms |
17256 KB |
Output is correct |
50 |
Correct |
103 ms |
17244 KB |
Output is correct |
51 |
Correct |
14 ms |
17240 KB |
Output is correct |
52 |
Correct |
14 ms |
17244 KB |
Output is correct |
53 |
Correct |
110 ms |
17264 KB |
Output is correct |
54 |
Correct |
16 ms |
17244 KB |
Output is correct |
55 |
Correct |
18 ms |
17260 KB |
Output is correct |
56 |
Correct |
129 ms |
17268 KB |
Output is correct |
57 |
Correct |
14 ms |
17244 KB |
Output is correct |
58 |
Correct |
12 ms |
17248 KB |
Output is correct |
59 |
Correct |
150 ms |
17500 KB |
Output is correct |
60 |
Correct |
17 ms |
17244 KB |
Output is correct |
61 |
Correct |
16 ms |
17244 KB |
Output is correct |
62 |
Correct |
169 ms |
17288 KB |
Output is correct |
63 |
Correct |
94 ms |
17240 KB |
Output is correct |
64 |
Correct |
168 ms |
17256 KB |
Output is correct |
65 |
Correct |
156 ms |
17244 KB |
Output is correct |
66 |
Correct |
110 ms |
17232 KB |
Output is correct |
67 |
Correct |
96 ms |
17256 KB |
Output is correct |
68 |
Correct |
45 ms |
17344 KB |
Output is correct |
69 |
Correct |
41 ms |
17332 KB |
Output is correct |
70 |
Correct |
28 ms |
17236 KB |
Output is correct |
71 |
Correct |
29 ms |
17232 KB |
Output is correct |
72 |
Correct |
25 ms |
17244 KB |
Output is correct |
73 |
Correct |
43 ms |
18076 KB |
Output is correct |
74 |
Correct |
83 ms |
18000 KB |
Output is correct |
75 |
Correct |
94 ms |
18008 KB |
Output is correct |
76 |
Correct |
80 ms |
18012 KB |
Output is correct |
77 |
Correct |
87 ms |
18008 KB |
Output is correct |
78 |
Correct |
105 ms |
17752 KB |
Output is correct |
79 |
Correct |
76 ms |
17748 KB |
Output is correct |
80 |
Correct |
83 ms |
17744 KB |
Output is correct |
81 |
Correct |
98 ms |
17756 KB |
Output is correct |
82 |
Correct |
78 ms |
17752 KB |
Output is correct |
83 |
Correct |
125 ms |
17768 KB |
Output is correct |
84 |
Correct |
102 ms |
17756 KB |
Output is correct |
85 |
Correct |
97 ms |
17756 KB |
Output is correct |
86 |
Correct |
112 ms |
17752 KB |
Output is correct |
87 |
Correct |
108 ms |
17756 KB |
Output is correct |
88 |
Correct |
125 ms |
17724 KB |
Output is correct |
89 |
Correct |
119 ms |
17496 KB |
Output is correct |
90 |
Correct |
132 ms |
17496 KB |
Output is correct |
91 |
Correct |
119 ms |
17492 KB |
Output is correct |
92 |
Correct |
129 ms |
17492 KB |
Output is correct |