# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
935004 |
2024-02-28T10:42:52 Z |
May27_th |
Mecho (IOI09_mecho) |
C++17 |
|
136 ms |
7000 KB |
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
void World_Final();
void Solve();
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if (fopen(taskname".in", "r")) {
freopen(taskname".in", "r", stdin);
freopen(taskname".out", "w", stdout);
}
World_Final();
}
void World_Final(){
int Tests = 1;
//cin >> Tests;
while (Tests --) {
Solve();
}
}
const int MAXN = 805;
int N, S, bee[MAXN][MAXN], bear[MAXN][MAXN]; char G[MAXN][MAXN];
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
pair<int, int> st, en;
bool query(int rest){
memset(bear, -1, sizeof(bear));
queue<pair<int, int>> q; q.push(st); bear[st.first][st.second] = 0;
while (!q.empty()) {
int u, v; tie(u, v) = q.front();
//cout << u << " " << v << "\n";
q.pop();
for (int i = 0; i < 4; i ++) {
int nu = u + dx[i];
int nv = v + dy[i];
if (nu >= 1 && nu <= N && nv >= 1 && nv <= N) {
if (G[nu][nv] == 'G' && bear[nu][nv] == -1) {
int t = (bear[u][v] + 1)/S;
if (t < bee[nu][nv] - rest) {
bear[nu][nv] = bear[u][v] + 1;
q.push(make_pair(nu, nv));
}
}
if (G[nu][nv] == 'D' && bear[nu][nv] == -1) {
bear[nu][nv] = bear[u][v] + 1;
q.push(make_pair(nu, nv));
}
}
}
}
return bear[en.first][en.second] != -1;
}
void Solve(){
cin >> N >> S;
for (int i = 1; i <= N; i ++) {
for (int j = 1; j <= N; j ++) {
cin >> G[i][j];
}
}
memset(bee, -1, sizeof(bee)); queue<pair<int, int>> q;
for (int i = 1; i <= N; i ++) {
for (int j = 1; j <= N; j ++) {
if (G[i][j] == 'H') {
bee[i][j] = 0;
q.push(make_pair(i, j));
}
if (G[i][j] == 'M') st = make_pair(i, j);
if (G[i][j] == 'D') en = make_pair(i, j);
}
}
while (!q.empty()) {
int u, v; tie(u, v) = q.front();
q.pop();
for (int i = 0; i < 4; i ++) {
int nu = u + dx[i];
int nv = v + dy[i];
if (nu >= 1 && nu <= N && nv >= 1 && nv <= N) {
if ((G[nu][nv] == 'G' || G[nu][nv] == 'M') && bee[nu][nv] == -1) {
bee[nu][nv] = bee[u][v] + 1;
q.push(make_pair(nu, nv));
}
}
}
}
int l = 0, h = 1e9;
while (l <= h) {
int mid = (l + h) / 2;
//cout << mid << "\n";
if (query(mid)) l = mid + 1;
else h = mid - 1;
} cout << h;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen(taskname".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5980 KB |
Output is correct |
2 |
Correct |
3 ms |
5980 KB |
Output is correct |
3 |
Correct |
3 ms |
5980 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
3 ms |
5980 KB |
Output is correct |
7 |
Correct |
75 ms |
6128 KB |
Output is correct |
8 |
Correct |
3 ms |
5980 KB |
Output is correct |
9 |
Correct |
3 ms |
5980 KB |
Output is correct |
10 |
Correct |
3 ms |
5980 KB |
Output is correct |
11 |
Correct |
3 ms |
5980 KB |
Output is correct |
12 |
Incorrect |
3 ms |
5980 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
5980 KB |
Output isn't correct |
14 |
Correct |
3 ms |
5836 KB |
Output is correct |
15 |
Correct |
3 ms |
6008 KB |
Output is correct |
16 |
Correct |
3 ms |
5980 KB |
Output is correct |
17 |
Correct |
3 ms |
5980 KB |
Output is correct |
18 |
Correct |
3 ms |
5980 KB |
Output is correct |
19 |
Correct |
3 ms |
5980 KB |
Output is correct |
20 |
Correct |
3 ms |
5980 KB |
Output is correct |
21 |
Correct |
3 ms |
6020 KB |
Output is correct |
22 |
Correct |
3 ms |
5980 KB |
Output is correct |
23 |
Correct |
3 ms |
5980 KB |
Output is correct |
24 |
Correct |
3 ms |
5976 KB |
Output is correct |
25 |
Correct |
3 ms |
5980 KB |
Output is correct |
26 |
Correct |
3 ms |
5980 KB |
Output is correct |
27 |
Correct |
3 ms |
5976 KB |
Output is correct |
28 |
Correct |
3 ms |
5980 KB |
Output is correct |
29 |
Correct |
3 ms |
5980 KB |
Output is correct |
30 |
Correct |
3 ms |
5980 KB |
Output is correct |
31 |
Correct |
3 ms |
5980 KB |
Output is correct |
32 |
Correct |
3 ms |
5976 KB |
Output is correct |
33 |
Correct |
5 ms |
6236 KB |
Output is correct |
34 |
Correct |
6 ms |
6096 KB |
Output is correct |
35 |
Correct |
18 ms |
6236 KB |
Output is correct |
36 |
Correct |
6 ms |
6232 KB |
Output is correct |
37 |
Correct |
6 ms |
6236 KB |
Output is correct |
38 |
Correct |
22 ms |
6248 KB |
Output is correct |
39 |
Correct |
7 ms |
6236 KB |
Output is correct |
40 |
Correct |
9 ms |
6236 KB |
Output is correct |
41 |
Correct |
30 ms |
6236 KB |
Output is correct |
42 |
Correct |
7 ms |
6236 KB |
Output is correct |
43 |
Correct |
7 ms |
6188 KB |
Output is correct |
44 |
Correct |
37 ms |
6208 KB |
Output is correct |
45 |
Correct |
9 ms |
6232 KB |
Output is correct |
46 |
Correct |
8 ms |
6236 KB |
Output is correct |
47 |
Correct |
43 ms |
6360 KB |
Output is correct |
48 |
Correct |
10 ms |
6232 KB |
Output is correct |
49 |
Correct |
11 ms |
6168 KB |
Output is correct |
50 |
Correct |
63 ms |
6332 KB |
Output is correct |
51 |
Correct |
12 ms |
6236 KB |
Output is correct |
52 |
Correct |
12 ms |
6236 KB |
Output is correct |
53 |
Correct |
68 ms |
6488 KB |
Output is correct |
54 |
Correct |
15 ms |
6232 KB |
Output is correct |
55 |
Correct |
15 ms |
6488 KB |
Output is correct |
56 |
Correct |
77 ms |
6460 KB |
Output is correct |
57 |
Correct |
13 ms |
6232 KB |
Output is correct |
58 |
Correct |
13 ms |
6492 KB |
Output is correct |
59 |
Correct |
81 ms |
6504 KB |
Output is correct |
60 |
Correct |
15 ms |
6488 KB |
Output is correct |
61 |
Correct |
17 ms |
6488 KB |
Output is correct |
62 |
Correct |
96 ms |
6488 KB |
Output is correct |
63 |
Correct |
80 ms |
6532 KB |
Output is correct |
64 |
Correct |
136 ms |
6488 KB |
Output is correct |
65 |
Correct |
132 ms |
6564 KB |
Output is correct |
66 |
Correct |
109 ms |
6488 KB |
Output is correct |
67 |
Correct |
82 ms |
6488 KB |
Output is correct |
68 |
Correct |
37 ms |
6492 KB |
Output is correct |
69 |
Correct |
37 ms |
6380 KB |
Output is correct |
70 |
Correct |
27 ms |
6488 KB |
Output is correct |
71 |
Correct |
28 ms |
6488 KB |
Output is correct |
72 |
Incorrect |
25 ms |
6492 KB |
Output isn't correct |
73 |
Incorrect |
26 ms |
6744 KB |
Output isn't correct |
74 |
Correct |
48 ms |
6748 KB |
Output is correct |
75 |
Correct |
53 ms |
6744 KB |
Output is correct |
76 |
Correct |
47 ms |
6748 KB |
Output is correct |
77 |
Correct |
53 ms |
6744 KB |
Output is correct |
78 |
Correct |
64 ms |
6804 KB |
Output is correct |
79 |
Correct |
43 ms |
6624 KB |
Output is correct |
80 |
Correct |
59 ms |
6748 KB |
Output is correct |
81 |
Correct |
57 ms |
6768 KB |
Output is correct |
82 |
Correct |
50 ms |
6776 KB |
Output is correct |
83 |
Correct |
63 ms |
6760 KB |
Output is correct |
84 |
Correct |
55 ms |
6592 KB |
Output is correct |
85 |
Correct |
59 ms |
6648 KB |
Output is correct |
86 |
Correct |
60 ms |
7000 KB |
Output is correct |
87 |
Correct |
57 ms |
6780 KB |
Output is correct |
88 |
Correct |
64 ms |
6732 KB |
Output is correct |
89 |
Correct |
64 ms |
6688 KB |
Output is correct |
90 |
Correct |
68 ms |
6744 KB |
Output is correct |
91 |
Correct |
61 ms |
6492 KB |
Output is correct |
92 |
Correct |
70 ms |
6748 KB |
Output is correct |