# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
499625 |
2021-12-29T05:42:22 Z |
rampu |
Mecho (IOI09_mecho) |
C++14 |
|
242 ms |
6128 KB |
#include <iostream>
#include <vector>
#include <climits>
#include <queue>
#define F first
#define S second
using namespace std;
using pii = pair <int, int>;
const int N = 801;
const int dx[] = { 0, -1, 1, 0 };
const int dy[] = { 1, 0, 0, -1 };
int n, s;
char c[N][N];
int tAcc[N][N];
vector <pii> hive;
pii honeypot, home;
inline bool Unreachable(const int &x, const int &y) {
return x < 1 || x > n || y < 1 || y > n || c[x][y] == 'D' || c[x][y] == 'T';
}
inline bool UnrB(const int &x, const int &y) {
return x < 1 || x > n || y < 1 || y > n || c[x][y] == 'T';
}
void CalcTAcc() {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) tAcc[i][j] = INT_MAX;
queue <pii> q;
for (auto p: hive) q.push(p), tAcc[p.F][p.S] = -1;
while (q.size()) {
int ux = q.front().F;
int uy = q.front().S;
q.pop();
for (int d = 0; d < 4; d++) {
int vx = ux + dx[d];
int vy = uy + dy[d];
if (Unreachable(vx, vy) || tAcc[vx][vy] != INT_MAX) continue;
tAcc[vx][vy] = tAcc[ux][uy] + 1;
q.push({ vx, vy });
}
}
}
bool isFine(int t) {
vector <vector <int> > step(n + 1);
for (auto &v: step) v.resize(n + 1, INT_MAX);
queue <pii> q;
q.push(honeypot), step[honeypot.F][honeypot.S] = 0;
while (q.size()) {
int ux = q.front().F;
int uy = q.front().S;
q.pop();
for (int d = 0; d < 4; d++) {
int vx = ux + dx[d];
int vy = uy + dy[d];
if (UnrB(vx, vy) || step[vx][vy] != INT_MAX) continue;
step[vx][vy] = step[ux][uy] + 1;
if (t + step[vx][vy] / s > tAcc[vx][vy]) continue;
if (c[vx][vy] == 'D') return true;
q.push({ vx, vy });
}
}
return false;
}
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> c[i][j];
if (c[i][j] == 'H') hive.push_back({ i, j });
else if (c[i][j] == 'M') honeypot = { i, j };
else if (c[i][j] == 'D') home = { i, j };
}
CalcTAcc();
int l = 0, r = n * n, mid, out = -1;
while (l <= r) {
mid = l + (r - l >> 1);
if (isFine(mid)) out = mid, l = mid + 1;
else r = mid - 1;
}
cout << out;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:93:22: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
93 | mid = l + (r - l >> 1);
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
120 ms |
6044 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
588 KB |
Output is correct |
30 |
Correct |
1 ms |
588 KB |
Output is correct |
31 |
Correct |
1 ms |
588 KB |
Output is correct |
32 |
Correct |
1 ms |
588 KB |
Output is correct |
33 |
Correct |
12 ms |
2156 KB |
Output is correct |
34 |
Correct |
11 ms |
2220 KB |
Output is correct |
35 |
Correct |
29 ms |
2156 KB |
Output is correct |
36 |
Correct |
20 ms |
2508 KB |
Output is correct |
37 |
Correct |
17 ms |
2492 KB |
Output is correct |
38 |
Correct |
44 ms |
2620 KB |
Output is correct |
39 |
Correct |
18 ms |
2876 KB |
Output is correct |
40 |
Correct |
19 ms |
2864 KB |
Output is correct |
41 |
Correct |
51 ms |
3000 KB |
Output is correct |
42 |
Correct |
23 ms |
3292 KB |
Output is correct |
43 |
Correct |
26 ms |
3248 KB |
Output is correct |
44 |
Correct |
65 ms |
3276 KB |
Output is correct |
45 |
Correct |
36 ms |
3636 KB |
Output is correct |
46 |
Correct |
28 ms |
3668 KB |
Output is correct |
47 |
Correct |
71 ms |
3684 KB |
Output is correct |
48 |
Correct |
33 ms |
4108 KB |
Output is correct |
49 |
Correct |
40 ms |
4120 KB |
Output is correct |
50 |
Correct |
81 ms |
4072 KB |
Output is correct |
51 |
Correct |
39 ms |
4524 KB |
Output is correct |
52 |
Correct |
41 ms |
4560 KB |
Output is correct |
53 |
Correct |
100 ms |
4508 KB |
Output is correct |
54 |
Correct |
46 ms |
5024 KB |
Output is correct |
55 |
Correct |
46 ms |
5036 KB |
Output is correct |
56 |
Correct |
114 ms |
4992 KB |
Output is correct |
57 |
Correct |
59 ms |
5520 KB |
Output is correct |
58 |
Correct |
53 ms |
5516 KB |
Output is correct |
59 |
Correct |
149 ms |
5504 KB |
Output is correct |
60 |
Correct |
60 ms |
6000 KB |
Output is correct |
61 |
Correct |
60 ms |
6000 KB |
Output is correct |
62 |
Correct |
154 ms |
5984 KB |
Output is correct |
63 |
Correct |
149 ms |
5968 KB |
Output is correct |
64 |
Correct |
242 ms |
5972 KB |
Output is correct |
65 |
Correct |
183 ms |
5972 KB |
Output is correct |
66 |
Correct |
176 ms |
6092 KB |
Output is correct |
67 |
Correct |
162 ms |
5968 KB |
Output is correct |
68 |
Correct |
89 ms |
6036 KB |
Output is correct |
69 |
Correct |
90 ms |
6012 KB |
Output is correct |
70 |
Correct |
83 ms |
5996 KB |
Output is correct |
71 |
Correct |
100 ms |
6008 KB |
Output is correct |
72 |
Incorrect |
72 ms |
6008 KB |
Output isn't correct |
73 |
Incorrect |
79 ms |
6068 KB |
Output isn't correct |
74 |
Correct |
101 ms |
6024 KB |
Output is correct |
75 |
Correct |
118 ms |
6016 KB |
Output is correct |
76 |
Correct |
149 ms |
6128 KB |
Output is correct |
77 |
Correct |
99 ms |
6024 KB |
Output is correct |
78 |
Correct |
118 ms |
6012 KB |
Output is correct |
79 |
Correct |
89 ms |
6004 KB |
Output is correct |
80 |
Correct |
103 ms |
6020 KB |
Output is correct |
81 |
Correct |
113 ms |
6020 KB |
Output is correct |
82 |
Correct |
140 ms |
6024 KB |
Output is correct |
83 |
Correct |
116 ms |
6024 KB |
Output is correct |
84 |
Correct |
112 ms |
6020 KB |
Output is correct |
85 |
Correct |
128 ms |
6104 KB |
Output is correct |
86 |
Correct |
113 ms |
6044 KB |
Output is correct |
87 |
Correct |
109 ms |
6024 KB |
Output is correct |
88 |
Correct |
123 ms |
6092 KB |
Output is correct |
89 |
Correct |
120 ms |
6012 KB |
Output is correct |
90 |
Correct |
132 ms |
6040 KB |
Output is correct |
91 |
Correct |
118 ms |
6000 KB |
Output is correct |
92 |
Correct |
125 ms |
6024 KB |
Output is correct |