# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
789654 |
2023-07-21T16:06:45 Z |
phongcd |
Mecho (IOI09_mecho) |
C++14 |
|
316 ms |
65536 KB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const ll N = 8e2 + 2;
const ll MOD = 1e9;
const ll INF = 1e18;
const ll base = 311;
const int BLOCK_SIZE = 2000;
int n, s;
ii start, target, d[N][N];
char a[N][N];
int mtime[N][N];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
void addstep(ii &a) {
a.se += 1;
if (a.se > s) a.fi ++, a.se = 1;
}
bool cmp(ii a, ii b) {
if (a.fi != b.fi) return a.fi < b.fi;
return a.se < b.se;
}
bool check(int x) {
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++) d[i][j] = {2e9, 0};
queue <ii> h;
h.push(start);
d[start.fi][start.se] = {x + 1, 0};
while (!h.empty()) {
auto [x, y] = h.front(); h.pop();
ii res = d[x][y];
addstep(res);
for (int j = 0; j <= 3; j ++) {
int u = x + dx[j];
int v = y + dy[j];
if (a[u][v] == 'G' && res.fi <= mtime[u][v] && !cmp(d[u][v], res)) {
h.push({u, v});
d[u][v] = res;
}
}
}
return d[target.fi][target.se].fi != 2e9;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> s;
queue <ii> bee;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++) {
cin >> a[i][j];
mtime[i][j] = 2e9;
if (a[i][j] == 'H')
bee.push({i, j}), mtime[i][j] = 0;
if (a[i][j] == 'M')
a[i][j] = 'G', start = {i, j};
if (a[i][j] == 'D')
a[i][j] = 'G', target = {i, j};
}
while (!bee.empty()) {
auto [x, y] = bee.front(); bee.pop();
int res = mtime[x][y] + 1;
for (int j = 0; j <= 3; j ++) {
int u = x + dx[j];
int v = y + dy[j];
if (a[u][v] == 'G' && mtime[u][v] > res) {
bee.push({u, v});
mtime[u][v] = res;
}
}
}
int l = 1, r = 2e3;
while (l < r) {
int mid = l + (r - l + 1) / 2;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << (check(l) ? l : -1);
}
/*
/\_/\ zzZ
(= -_-)
/ >u >u
*/
Compilation message
mecho.cpp: In function 'bool check(int)':
mecho.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | auto [x, y] = h.front(); h.pop();
| ^
mecho.cpp: In function 'int main()':
mecho.cpp:81:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
81 | auto [x, y] = bee.front(); bee.pop();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Runtime error |
191 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Incorrect |
0 ms |
724 KB |
Output isn't correct |
13 |
Runtime error |
316 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Runtime error |
265 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
28 |
Correct |
1 ms |
852 KB |
Output is correct |
29 |
Incorrect |
1 ms |
852 KB |
Output isn't correct |
30 |
Correct |
1 ms |
852 KB |
Output is correct |
31 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Incorrect |
10 ms |
3908 KB |
Output isn't correct |
34 |
Incorrect |
13 ms |
3916 KB |
Output isn't correct |
35 |
Runtime error |
209 ms |
65536 KB |
Execution killed with signal 9 |
36 |
Incorrect |
13 ms |
4372 KB |
Output isn't correct |
37 |
Incorrect |
20 ms |
4396 KB |
Output isn't correct |
38 |
Runtime error |
189 ms |
65536 KB |
Execution killed with signal 9 |
39 |
Incorrect |
18 ms |
4928 KB |
Output isn't correct |
40 |
Incorrect |
21 ms |
4820 KB |
Output isn't correct |
41 |
Runtime error |
190 ms |
65536 KB |
Execution killed with signal 9 |
42 |
Incorrect |
20 ms |
5376 KB |
Output isn't correct |
43 |
Incorrect |
27 ms |
5440 KB |
Output isn't correct |
44 |
Runtime error |
182 ms |
65536 KB |
Execution killed with signal 9 |
45 |
Incorrect |
24 ms |
5948 KB |
Output isn't correct |
46 |
Incorrect |
30 ms |
5844 KB |
Output isn't correct |
47 |
Runtime error |
196 ms |
65536 KB |
Execution killed with signal 9 |
48 |
Incorrect |
28 ms |
6460 KB |
Output isn't correct |
49 |
Incorrect |
36 ms |
6436 KB |
Output isn't correct |
50 |
Runtime error |
180 ms |
65536 KB |
Execution killed with signal 9 |
51 |
Incorrect |
33 ms |
6868 KB |
Output isn't correct |
52 |
Incorrect |
46 ms |
6960 KB |
Output isn't correct |
53 |
Runtime error |
185 ms |
65536 KB |
Execution killed with signal 9 |
54 |
Incorrect |
41 ms |
7364 KB |
Output isn't correct |
55 |
Incorrect |
55 ms |
7460 KB |
Output isn't correct |
56 |
Runtime error |
202 ms |
65536 KB |
Execution killed with signal 9 |
57 |
Incorrect |
50 ms |
7892 KB |
Output isn't correct |
58 |
Incorrect |
56 ms |
7968 KB |
Output isn't correct |
59 |
Runtime error |
181 ms |
65536 KB |
Execution killed with signal 9 |
60 |
Incorrect |
51 ms |
8476 KB |
Output isn't correct |
61 |
Incorrect |
62 ms |
8404 KB |
Output isn't correct |
62 |
Runtime error |
200 ms |
65536 KB |
Execution killed with signal 9 |
63 |
Incorrect |
90 ms |
8592 KB |
Output isn't correct |
64 |
Correct |
154 ms |
8456 KB |
Output is correct |
65 |
Correct |
161 ms |
8484 KB |
Output is correct |
66 |
Incorrect |
121 ms |
8464 KB |
Output isn't correct |
67 |
Correct |
98 ms |
8480 KB |
Output is correct |
68 |
Incorrect |
40 ms |
8404 KB |
Output isn't correct |
69 |
Correct |
43 ms |
8508 KB |
Output is correct |
70 |
Correct |
39 ms |
8476 KB |
Output is correct |
71 |
Correct |
36 ms |
8504 KB |
Output is correct |
72 |
Incorrect |
29 ms |
8508 KB |
Output isn't correct |
73 |
Runtime error |
181 ms |
65536 KB |
Execution killed with signal 9 |
74 |
Runtime error |
207 ms |
65536 KB |
Execution killed with signal 9 |
75 |
Runtime error |
177 ms |
65536 KB |
Execution killed with signal 9 |
76 |
Runtime error |
176 ms |
65536 KB |
Execution killed with signal 9 |
77 |
Runtime error |
202 ms |
65536 KB |
Execution killed with signal 9 |
78 |
Runtime error |
187 ms |
65536 KB |
Execution killed with signal 9 |
79 |
Runtime error |
191 ms |
65536 KB |
Execution killed with signal 9 |
80 |
Runtime error |
193 ms |
65536 KB |
Execution killed with signal 9 |
81 |
Runtime error |
178 ms |
65536 KB |
Execution killed with signal 9 |
82 |
Runtime error |
182 ms |
65536 KB |
Execution killed with signal 9 |
83 |
Runtime error |
195 ms |
65536 KB |
Execution killed with signal 9 |
84 |
Runtime error |
194 ms |
65536 KB |
Execution killed with signal 9 |
85 |
Runtime error |
189 ms |
65536 KB |
Execution killed with signal 9 |
86 |
Runtime error |
181 ms |
65536 KB |
Execution killed with signal 9 |
87 |
Runtime error |
201 ms |
65536 KB |
Execution killed with signal 9 |
88 |
Runtime error |
192 ms |
65536 KB |
Execution killed with signal 9 |
89 |
Runtime error |
178 ms |
65536 KB |
Execution killed with signal 9 |
90 |
Runtime error |
186 ms |
65536 KB |
Execution killed with signal 9 |
91 |
Runtime error |
186 ms |
65536 KB |
Execution killed with signal 9 |
92 |
Runtime error |
179 ms |
65536 KB |
Execution killed with signal 9 |