# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
977532 |
2024-05-08T06:22:31 Z |
farica |
Mecho (IOI09_mecho) |
C++14 |
|
1000 ms |
6740 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N = 4e5 + 5;
int n, s, dist[800][800], sx, sy;
string grid[800];
bool test(int m) {
priority_queue<pair<int, pair<int,int>>>pq;
vector<vector<bool>>visited(n, vector<bool>(n, 0));
pq.push({0, {sx, sy}});
while(!pq.empty()) {
int x = pq.top().second.first, y = pq.top().second.second, cnt = -1 * pq.top().first;
pq.pop();
if(visited[x][y]) continue;
visited[x][y] = 1;
if(grid[x][y] == 'D') return true;
int cost = ((cnt+1) / s) + ((cnt+1) % s > 0 ? 1 : 0) + m;
if(x && grid[x-1][y] != 'T' && dist[x-1][y] >= cost) pq.push({(cnt + 1) * -1, {x-1, y}});
if(y && grid[x][y-1] != 'T' && dist[x][y-1] >= cost) pq.push({(cnt + 1) * -1, {x, y-1}});
if(x+1<n && grid[x+1][y] != 'T' && dist[x+1][y] >= cost) pq.push({(cnt + 1) * -1, {x+1, y}});
if(y+1<n && grid[x][y+1] != 'T' && dist[x][y+1] >= cost) pq.push({(cnt + 1) * -1, {x, y+1}});
}
return false;
}
void solve() {
cin >> n >> s;
queue<pair<int,int>>q;
for(int i=0; i<n; ++i) {
cin >> grid[i];
for(int j=0; j<n; ++j) {
dist[i][j] = -1;
if(grid[i][j] == 'H') {
q.push({i, j});
dist[i][j] = 0;
} else if(grid[i][j] == 'M') sx=i, sy=j;
}
}
while(!q.empty()) {
int i = q.front().first, j = q.front().second;
q.pop();
if(i && dist[i-1][j] == -1 && grid[i-1][j] != 'T') {
dist[i-1][j] = dist[i][j] + 1;
q.push({i-1, j});
}
if(j && dist[i][j-1] == -1 && grid[i][j-1] != 'T') {
dist[i][j-1] = dist[i][j] + 1;
q.push({i, j-1});
}
if(i<n-1 && dist[i+1][j] == -1 && grid[i+1][j] != 'T') {
dist[i+1][j] = dist[i][j] + 1;
q.push({i+1, j});
}
if(j<n-1 && dist[i][j+1] == -1 && grid[i][j+1] != 'T') {
dist[i][j+1] = dist[i][j] + 1;
q.push({i, j+1});
}
}
if(!test(0)) {
cout << -1 << endl;
return;
}
int l=0, r=dist[sx][sy], mid;
while(l<=r) {
mid = (l+r)/2;
if(test(mid)) l = mid + 1;
else r = mid - 1;
}
cout << l - 1 << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 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 |
1 ms |
348 KB |
Output isn't correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Execution timed out |
1039 ms |
6476 KB |
Time limit exceeded |
8 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Incorrect |
2 ms |
2648 KB |
Output isn't correct |
34 |
Correct |
3 ms |
2652 KB |
Output is correct |
35 |
Correct |
192 ms |
2868 KB |
Output is correct |
36 |
Incorrect |
3 ms |
4696 KB |
Output isn't correct |
37 |
Correct |
3 ms |
4696 KB |
Output is correct |
38 |
Correct |
261 ms |
4956 KB |
Output is correct |
39 |
Incorrect |
4 ms |
4952 KB |
Output isn't correct |
40 |
Correct |
5 ms |
4956 KB |
Output is correct |
41 |
Correct |
356 ms |
5048 KB |
Output is correct |
42 |
Incorrect |
4 ms |
4956 KB |
Output isn't correct |
43 |
Correct |
4 ms |
5060 KB |
Output is correct |
44 |
Correct |
429 ms |
5084 KB |
Output is correct |
45 |
Incorrect |
5 ms |
4952 KB |
Output isn't correct |
46 |
Correct |
5 ms |
4956 KB |
Output is correct |
47 |
Correct |
528 ms |
5176 KB |
Output is correct |
48 |
Incorrect |
5 ms |
4956 KB |
Output isn't correct |
49 |
Correct |
6 ms |
5120 KB |
Output is correct |
50 |
Correct |
667 ms |
5256 KB |
Output is correct |
51 |
Incorrect |
5 ms |
5208 KB |
Output isn't correct |
52 |
Correct |
6 ms |
5212 KB |
Output is correct |
53 |
Correct |
784 ms |
5332 KB |
Output is correct |
54 |
Incorrect |
7 ms |
5468 KB |
Output isn't correct |
55 |
Correct |
7 ms |
5468 KB |
Output is correct |
56 |
Correct |
922 ms |
5552 KB |
Output is correct |
57 |
Incorrect |
9 ms |
5724 KB |
Output isn't correct |
58 |
Correct |
8 ms |
5720 KB |
Output is correct |
59 |
Execution timed out |
1054 ms |
5972 KB |
Time limit exceeded |
60 |
Incorrect |
9 ms |
6236 KB |
Output isn't correct |
61 |
Correct |
9 ms |
6284 KB |
Output is correct |
62 |
Execution timed out |
1071 ms |
6236 KB |
Time limit exceeded |
63 |
Correct |
415 ms |
6480 KB |
Output is correct |
64 |
Correct |
725 ms |
6296 KB |
Output is correct |
65 |
Correct |
726 ms |
6236 KB |
Output is correct |
66 |
Incorrect |
537 ms |
6300 KB |
Output isn't correct |
67 |
Correct |
55 ms |
6236 KB |
Output is correct |
68 |
Correct |
103 ms |
6276 KB |
Output is correct |
69 |
Correct |
94 ms |
6236 KB |
Output is correct |
70 |
Correct |
67 ms |
6272 KB |
Output is correct |
71 |
Correct |
39 ms |
6268 KB |
Output is correct |
72 |
Incorrect |
30 ms |
6232 KB |
Output isn't correct |
73 |
Incorrect |
322 ms |
6720 KB |
Output isn't correct |
74 |
Correct |
777 ms |
6684 KB |
Output is correct |
75 |
Correct |
656 ms |
6492 KB |
Output is correct |
76 |
Correct |
680 ms |
6700 KB |
Output is correct |
77 |
Correct |
735 ms |
6692 KB |
Output is correct |
78 |
Correct |
137 ms |
6488 KB |
Output is correct |
79 |
Correct |
656 ms |
6640 KB |
Output is correct |
80 |
Correct |
711 ms |
6640 KB |
Output is correct |
81 |
Correct |
749 ms |
6488 KB |
Output is correct |
82 |
Correct |
639 ms |
6740 KB |
Output is correct |
83 |
Correct |
998 ms |
6740 KB |
Output is correct |
84 |
Correct |
894 ms |
6564 KB |
Output is correct |
85 |
Correct |
799 ms |
6556 KB |
Output is correct |
86 |
Correct |
979 ms |
6568 KB |
Output is correct |
87 |
Correct |
846 ms |
6564 KB |
Output is correct |
88 |
Execution timed out |
1035 ms |
6492 KB |
Time limit exceeded |
89 |
Execution timed out |
1047 ms |
6472 KB |
Time limit exceeded |
90 |
Execution timed out |
1036 ms |
6512 KB |
Time limit exceeded |
91 |
Execution timed out |
1058 ms |
6468 KB |
Time limit exceeded |
92 |
Execution timed out |
1073 ms |
6236 KB |
Time limit exceeded |