# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
597557 |
2022-07-16T10:20:42 Z |
l_reho |
Mecho (IOI09_mecho) |
C++14 |
|
308 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int N, S;
vector<string> V;
vector<vector<int>> P;
int dirs[4][2] = {{1, 0},{0, 1},{-1, 0},{0, -1}};
struct info{
int r, c, d;
info(){}
info(int _r, int _c, int _d): r(_r), c(_c), d(_d) {}
};
void precompute(vector<pair<int, int>> starts){
queue<info> q;
for(int i = 0; i < (int)starts.size(); i++){
q.push(info(starts[i].first, starts[i].second, 0));
P[starts[i].first][starts[i].second] = 0;
}
while(!q.empty()){
info curr = q.front();
q.pop();
int r = curr.r;
int c = curr.c;
int depth = curr.d;
for(int i = 0; i < 4; i++){
int nr = r + dirs[i][0];
int nc = c + dirs[i][1];
if(nr < 0 || nr >= N || nc < 0 || nc >= N || V[nr][nc] != 'G' || P[nr][nc] != INT_MAX) continue;
P[nr][nc] = depth+1;
q.push(info(nr, nc, depth+1));
}
}
}
bool solver(int r, int c, int dr, int dc, int l){
queue<info> q;
q.push(info(r, c, l+1));
vector<vector<bool>> visited(N, vector<bool>(N, false));
while(!q.empty()){
info curr = q.front();
q.pop();
int r = curr.r;
int c = curr.c;
int depth = curr.d;
visited[r][c] = true;
// cout<<"DEBUG-->"<<l<<" "<<r<<" "<<c<<endl;
for(int i = 0; i < 4; i++){
int nr = r + dirs[i][0];
int nc = c + dirs[i][1];
if(nr < 0 || nr >= N || nc < 0 || nc >= N || (V[nr][nc] != 'G' && V[nr][nc] != 'D') || visited[nr][nc] || P[nr][nc] <= (l + (depth-l)/S)) continue;
q.push(info(nr, nc, depth+1));
}
}
return visited[dr][dc];
}
void solve(){
cin>>N>>S;
V.assign(N, "");
P.assign(N, vector<int>(N, INT_MAX));
vector<pair<int, int>> starts;
int sr, sc, dr, dc;
for(int i = 0; i < N; i++){
cin>>V[i];
for(int j = 0; j < N; j++)
if(V[i][j] == 'H') starts.push_back({i, j});
else if(V[i][j] == 'M') sr = i, sc = j;
else if(V[i][j] == 'D') dr = i, dc = j;
}
precompute(starts);
int low = 0;
int high = N*N;
int ans = 0;
while(low <= high){
int mid = low + (high - low)/2;
if(solver(sr, sc, dr, dc, mid)){
ans = mid;
low = mid+1;
}else high = mid-1;
}
cout<<ans<<endl;
}
int main(){
solve();
}
Compilation message
mecho.cpp: In function 'void solve()':
mecho.cpp:117:12: warning: 'dr' may be used uninitialized in this function [-Wmaybe-uninitialized]
117 | if(solver(sr, sc, dr, dc, mid)){
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~
mecho.cpp:117:12: warning: 'dc' may be used uninitialized in this function [-Wmaybe-uninitialized]
mecho.cpp:117:12: warning: 'sr' may be used uninitialized in this function [-Wmaybe-uninitialized]
mecho.cpp:117:12: warning: 'sc' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Runtime error |
211 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Correct |
1 ms |
296 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
13 |
Runtime error |
308 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Runtime error |
179 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
300 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
6 ms |
1108 KB |
Output is correct |
35 |
Runtime error |
194 ms |
65536 KB |
Execution killed with signal 9 |
36 |
Correct |
9 ms |
1236 KB |
Output is correct |
37 |
Correct |
8 ms |
1260 KB |
Output is correct |
38 |
Runtime error |
201 ms |
65536 KB |
Execution killed with signal 9 |
39 |
Correct |
9 ms |
1492 KB |
Output is correct |
40 |
Correct |
10 ms |
1492 KB |
Output is correct |
41 |
Runtime error |
198 ms |
65536 KB |
Execution killed with signal 9 |
42 |
Correct |
14 ms |
2024 KB |
Output is correct |
43 |
Correct |
16 ms |
2004 KB |
Output is correct |
44 |
Runtime error |
209 ms |
65536 KB |
Execution killed with signal 9 |
45 |
Correct |
14 ms |
2284 KB |
Output is correct |
46 |
Correct |
15 ms |
2340 KB |
Output is correct |
47 |
Runtime error |
208 ms |
65536 KB |
Execution killed with signal 9 |
48 |
Correct |
16 ms |
2736 KB |
Output is correct |
49 |
Correct |
18 ms |
2740 KB |
Output is correct |
50 |
Runtime error |
208 ms |
65536 KB |
Execution killed with signal 9 |
51 |
Correct |
18 ms |
3028 KB |
Output is correct |
52 |
Correct |
21 ms |
3000 KB |
Output is correct |
53 |
Runtime error |
207 ms |
65536 KB |
Execution killed with signal 9 |
54 |
Correct |
24 ms |
3384 KB |
Output is correct |
55 |
Correct |
25 ms |
3496 KB |
Output is correct |
56 |
Runtime error |
215 ms |
65536 KB |
Execution killed with signal 9 |
57 |
Correct |
25 ms |
3824 KB |
Output is correct |
58 |
Correct |
27 ms |
3812 KB |
Output is correct |
59 |
Runtime error |
212 ms |
65536 KB |
Execution killed with signal 9 |
60 |
Correct |
29 ms |
4228 KB |
Output is correct |
61 |
Correct |
31 ms |
4300 KB |
Output is correct |
62 |
Runtime error |
220 ms |
65536 KB |
Execution killed with signal 9 |
63 |
Correct |
105 ms |
4360 KB |
Output is correct |
64 |
Correct |
194 ms |
4300 KB |
Output is correct |
65 |
Correct |
147 ms |
4364 KB |
Output is correct |
66 |
Correct |
122 ms |
4428 KB |
Output is correct |
67 |
Incorrect |
117 ms |
4360 KB |
Output isn't correct |
68 |
Correct |
53 ms |
4352 KB |
Output is correct |
69 |
Correct |
52 ms |
4296 KB |
Output is correct |
70 |
Correct |
44 ms |
4280 KB |
Output is correct |
71 |
Correct |
46 ms |
4360 KB |
Output is correct |
72 |
Incorrect |
40 ms |
4356 KB |
Output isn't correct |
73 |
Runtime error |
194 ms |
65536 KB |
Execution killed with signal 9 |
74 |
Runtime error |
189 ms |
65536 KB |
Execution killed with signal 9 |
75 |
Runtime error |
193 ms |
65536 KB |
Execution killed with signal 9 |
76 |
Runtime error |
196 ms |
65536 KB |
Execution killed with signal 9 |
77 |
Runtime error |
195 ms |
65536 KB |
Execution killed with signal 9 |
78 |
Runtime error |
190 ms |
65536 KB |
Execution killed with signal 9 |
79 |
Runtime error |
202 ms |
65536 KB |
Execution killed with signal 9 |
80 |
Runtime error |
208 ms |
65536 KB |
Execution killed with signal 9 |
81 |
Runtime error |
195 ms |
65536 KB |
Execution killed with signal 9 |
82 |
Runtime error |
222 ms |
65536 KB |
Execution killed with signal 9 |
83 |
Runtime error |
218 ms |
65536 KB |
Execution killed with signal 9 |
84 |
Runtime error |
216 ms |
65536 KB |
Execution killed with signal 9 |
85 |
Runtime error |
225 ms |
65536 KB |
Execution killed with signal 9 |
86 |
Runtime error |
239 ms |
65536 KB |
Execution killed with signal 9 |
87 |
Runtime error |
215 ms |
65536 KB |
Execution killed with signal 9 |
88 |
Runtime error |
206 ms |
65536 KB |
Execution killed with signal 9 |
89 |
Runtime error |
207 ms |
65536 KB |
Execution killed with signal 9 |
90 |
Runtime error |
209 ms |
65536 KB |
Execution killed with signal 9 |
91 |
Runtime error |
208 ms |
65536 KB |
Execution killed with signal 9 |
92 |
Runtime error |
203 ms |
65536 KB |
Execution killed with signal 9 |