# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
886612 |
2023-12-12T12:18:01 Z |
gnu |
Mecho (IOI09_mecho) |
C++17 |
|
209 ms |
11684 KB |
#include <bits/stdc++.h>
using namespace std;
int n, S;
vector<string> board;
vector<vector<int>> vis;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
struct point{
int i, j;
point(int i, int j) {
this->i = i;
this->j = j;
}
};
void solve()
{
n, S; cin >> n >> S;
board = vector<string>(n);
vis = vector<vector<int>> (n, vector<int> (n));
for (int i = 0; i < n; ++i) cin >> board[i];
point mecho(0,0), home(0,0);
vector<point> honey;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (board[i][j] == 'H') honey.emplace_back(i, j);
else if (board[i][j] == 'M') mecho = {i, j};
else if (board[i][j] == 'D') home = {i, j};
}
}
queue<point> mq;
vector<vector<int>> dist(n, vector<int> (n, 0 ));
for (auto x : honey) {
mq.push(x);
vis[x.i][x.j] = 1;
dist[x.i][x.j] = 0;
}
while (!mq.empty()) {
point u = mq.front();
mq.pop();
for (int i = 0; i < 4; ++i) {
if (u.i + dx[i] < 0 || u.i + dx[i] >= n || u.j + dy[i] < 0 || u.j + dy[i] >= n || vis[u.i+dx[i]][u.j+dy[i]] || (board[u.i+dx[i]][u.j+dy[i]] != 'G' && board[u.i+dx[i]][u.j+dy[i]] != 'M')) continue;
mq.emplace(u.i + dx[i], u.j + dy[i]);
vis[u.i + dx[i]][u.j + dy[i]] = 1;
dist[u.i + dx[i]][u.j + dy[i]] = dist[u.i][u.j] + 1;
}
}
// for (auto &x : dist)
// {
// for (auto y : x) cout << y << ' ';
// cout << '\n';
// }
int l = -1, r = 1e9;
// return;
while (l + 1 < r) {
vector<vector<int>> md(n, vector<int> (n));
int m = (l + r) / 2;
vis = vector<vector<int>> (n, vector<int> (n));
queue<point> q;
q.emplace(mecho.i, mecho.j);
vis[mecho.i][mecho.j] = 1;
if (m >= dist[mecho.i][mecho.j]) q.pop();
while (!q.empty()) {
point u = q.front();
q.pop();
for (int i = 0; i < 4; ++i) {
int ni = u.i + dx[i], nj = u.j + dy[i];
if (((md[u.i][u.j]+1) / S >= (dist[u.i][u.j] - m))) continue;
if (u.i + dx[i] < 0 || u.i + dx[i] >= n || u.j + dy[i] < 0 || u.j + dy[i] >= n || vis[u.i+dx[i]][u.j+dy[i]] || (board[u.i+dx[i]][u.j+dy[i]] != 'G' && board[u.i+dx[i]][u.j+dy[i]] != 'M')) continue;
q.emplace(ni, nj);
md[ni][nj] = md[u.i][u.j] + 1;
vis[ni][nj] = 1;
}
}
bool ok = false;
for (int i = 0; i < 4; ++i) {
point u = home;
if (((md[u.i][u.j]+1) / S >= (dist[u.i][u.j] - m))) continue;
if (u.i + dx[i] < 0 || u.i + dx[i] >= n || u.j + dy[i] < 0 || u.j + dy[i] >= n || board[u.i+dx[i]][u.j+dy[i]] != 'G') continue;
if (vis[home.i + dx[i]][home.j+dy[i]]) ok = true;
}
if (ok) {
l = m;
} else r = m;
}
cout << l;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(nullptr);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
solve();
}
Compilation message
mecho.cpp: In function 'void solve()':
mecho.cpp:17:5: warning: left operand of comma operator has no effect [-Wunused-value]
17 | n, S; cin >> n >> S;
| ^
mecho.cpp:17:9: warning: right operand of comma operator has no effect [-Wunused-value]
17 | n, S; cin >> n >> S;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
117 ms |
11376 KB |
Output isn't correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
532 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
29 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
33 |
Incorrect |
18 ms |
2560 KB |
Output isn't correct |
34 |
Incorrect |
25 ms |
2548 KB |
Output isn't correct |
35 |
Incorrect |
23 ms |
2552 KB |
Output isn't correct |
36 |
Incorrect |
22 ms |
3164 KB |
Output isn't correct |
37 |
Incorrect |
35 ms |
3212 KB |
Output isn't correct |
38 |
Incorrect |
28 ms |
3164 KB |
Output isn't correct |
39 |
Incorrect |
31 ms |
3936 KB |
Output isn't correct |
40 |
Incorrect |
43 ms |
4132 KB |
Output isn't correct |
41 |
Incorrect |
35 ms |
4152 KB |
Output isn't correct |
42 |
Incorrect |
42 ms |
4724 KB |
Output isn't correct |
43 |
Incorrect |
55 ms |
4708 KB |
Output isn't correct |
44 |
Incorrect |
48 ms |
4764 KB |
Output isn't correct |
45 |
Incorrect |
44 ms |
5596 KB |
Output isn't correct |
46 |
Incorrect |
66 ms |
5580 KB |
Output isn't correct |
47 |
Incorrect |
57 ms |
5620 KB |
Output isn't correct |
48 |
Incorrect |
53 ms |
6608 KB |
Output isn't correct |
49 |
Incorrect |
82 ms |
6608 KB |
Output isn't correct |
50 |
Incorrect |
75 ms |
6584 KB |
Output isn't correct |
51 |
Incorrect |
65 ms |
7604 KB |
Output isn't correct |
52 |
Incorrect |
99 ms |
7636 KB |
Output isn't correct |
53 |
Incorrect |
105 ms |
7848 KB |
Output isn't correct |
54 |
Incorrect |
73 ms |
8776 KB |
Output isn't correct |
55 |
Incorrect |
117 ms |
8768 KB |
Output isn't correct |
56 |
Incorrect |
95 ms |
8808 KB |
Output isn't correct |
57 |
Incorrect |
96 ms |
9980 KB |
Output isn't correct |
58 |
Incorrect |
130 ms |
9984 KB |
Output isn't correct |
59 |
Incorrect |
140 ms |
10000 KB |
Output isn't correct |
60 |
Incorrect |
103 ms |
11316 KB |
Output isn't correct |
61 |
Incorrect |
156 ms |
11284 KB |
Output isn't correct |
62 |
Incorrect |
148 ms |
11320 KB |
Output isn't correct |
63 |
Incorrect |
102 ms |
11324 KB |
Output isn't correct |
64 |
Incorrect |
209 ms |
11320 KB |
Output isn't correct |
65 |
Incorrect |
192 ms |
11312 KB |
Output isn't correct |
66 |
Incorrect |
160 ms |
11320 KB |
Output isn't correct |
67 |
Correct |
130 ms |
11292 KB |
Output is correct |
68 |
Incorrect |
64 ms |
11376 KB |
Output isn't correct |
69 |
Incorrect |
78 ms |
11440 KB |
Output isn't correct |
70 |
Incorrect |
61 ms |
11356 KB |
Output isn't correct |
71 |
Incorrect |
58 ms |
11380 KB |
Output isn't correct |
72 |
Incorrect |
83 ms |
11336 KB |
Output isn't correct |
73 |
Incorrect |
61 ms |
11404 KB |
Output isn't correct |
74 |
Incorrect |
121 ms |
11600 KB |
Output isn't correct |
75 |
Incorrect |
104 ms |
11440 KB |
Output isn't correct |
76 |
Incorrect |
89 ms |
11396 KB |
Output isn't correct |
77 |
Incorrect |
97 ms |
11420 KB |
Output isn't correct |
78 |
Correct |
88 ms |
11372 KB |
Output is correct |
79 |
Incorrect |
120 ms |
11376 KB |
Output isn't correct |
80 |
Incorrect |
89 ms |
11304 KB |
Output isn't correct |
81 |
Incorrect |
88 ms |
11300 KB |
Output isn't correct |
82 |
Incorrect |
108 ms |
11372 KB |
Output isn't correct |
83 |
Incorrect |
112 ms |
11684 KB |
Output isn't correct |
84 |
Incorrect |
147 ms |
11388 KB |
Output isn't correct |
85 |
Incorrect |
87 ms |
11368 KB |
Output isn't correct |
86 |
Incorrect |
114 ms |
11340 KB |
Output isn't correct |
87 |
Incorrect |
108 ms |
11380 KB |
Output isn't correct |
88 |
Incorrect |
105 ms |
11428 KB |
Output isn't correct |
89 |
Incorrect |
122 ms |
11324 KB |
Output isn't correct |
90 |
Incorrect |
113 ms |
11340 KB |
Output isn't correct |
91 |
Incorrect |
117 ms |
11400 KB |
Output isn't correct |
92 |
Incorrect |
99 ms |
11412 KB |
Output isn't correct |