# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
953195 |
2024-03-25T16:48:02 Z |
tmtxangel |
Mecho (IOI09_mecho) |
C++17 |
|
121 ms |
6532 KB |
#include <bits/stdc++.h>
#define lli long long
#define ld long double
#define tmt angel
using namespace std;
const int maxn = 802;
int vis[maxn][maxn], n, m;
char a[maxn][maxn];
int tim[maxn][maxn];
int hi, hj, sti, stj;
int x[4] = {1, -1, 0, 0};
int y[4] = {0, 0, 1, -1};
deque<pair<pair<int, int>, int>> s;
bool flag = false;
void gocheck(int i, int j, int cost)
{
if(i < 1 || j < 1 || i > n || j > n || vis[i][j] == 1 || a[i][j] == 'D') return;
vis[i][j] = 1;
tim[i][j] = cost;
s.push_back({{i, j}, cost});
}
void spread(int i, int j, int cost, int step)
{
if(vis[hi][hj] == 1) return;
if(i < 1 || j < 1 || i > n || j > n || vis[i][j] == 1 || tim[i][j] < cost) return;
vis[i][j] = 1;
// cout << i << " " << j << " " << cost << " " << step << '\n';
if(vis[hi][hj] == 1) return;
if(step == m)
{
//tim[1][i][j] = cost;
s.push_back({{i, j}, cost});
}
else
{
// tim[1][i][j] = cost;
for(int f = 0; f < 4; f++)
{
spread(i + x[f], j + y[f], cost, step + 1);
if(vis[hi][hj] == 1) break;
}
}
}
void Bfs()
{
while(!s.empty())
{
int i = s.front().first.first;
int j = s.front().first.second;
int c = s.front().second;
s.pop_front();
for(int f = 0; f < 4; f++)
{
gocheck(i + x[f], j + y[f], c+1);
}
}
}
bool checked(int st)
{
s.clear();
flag = false;
// if(st == 0) s.push_back({ {sti, stj},{2, 0} });
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
vis[i][j] = a[i][j] == 'G' || a[i][j] == 'D' ? 0 : 1;
}
}
s.push_back({{sti, stj}, st});
while(!s.empty() && vis[hi][hj] == 0)
{
int i = s.front().first.first;
int j = s.front().first.second;
int c = s.front().second;
s.pop_front();
for(int f = 0; f < 4; f++)
{
spread(i + x[f], j + y[f], c+1, 1);
if(vis[hi][hj] == 1) break;
}
}
return vis[hi][hj] == 1;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(".INP", "r" , stdin);
// freopen(".OUT", "w" , stdout);
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
cin >> a[i][j];
if(a[i][j] == 'M')
{
vis[i][j] = 1;
sti = i;
stj = j;
}
else vis[i][j] = a[i][j] == 'G' ? 0 : 1;
if(a[i][j] == 'D')
{
hi = i;
hj = j;
}
if(a[i][j] == 'H')
{
s.push_back({{i, j}, 0});
vis[i][j] = 1;
}
}
}
Bfs();
tim[hi][hj] = 1e9;
//cout << checked(1);
int low = 0, high = n, mid;
while(low <= high)
{
mid = (low + high) / 2;
if(checked(mid)) low = mid+1;
else high = mid - 1;
}
cout << high;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Incorrect |
85 ms |
6288 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
30 |
Incorrect |
1 ms |
4696 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
33 |
Incorrect |
4 ms |
4700 KB |
Output isn't correct |
34 |
Incorrect |
4 ms |
4764 KB |
Output isn't correct |
35 |
Correct |
18 ms |
4700 KB |
Output is correct |
36 |
Incorrect |
5 ms |
4700 KB |
Output isn't correct |
37 |
Incorrect |
5 ms |
4876 KB |
Output isn't correct |
38 |
Correct |
23 ms |
4956 KB |
Output is correct |
39 |
Incorrect |
6 ms |
4956 KB |
Output isn't correct |
40 |
Incorrect |
6 ms |
4964 KB |
Output isn't correct |
41 |
Correct |
31 ms |
5156 KB |
Output is correct |
42 |
Incorrect |
8 ms |
4956 KB |
Output isn't correct |
43 |
Incorrect |
7 ms |
4956 KB |
Output isn't correct |
44 |
Correct |
43 ms |
5460 KB |
Output is correct |
45 |
Incorrect |
8 ms |
5212 KB |
Output isn't correct |
46 |
Incorrect |
9 ms |
5212 KB |
Output isn't correct |
47 |
Correct |
46 ms |
5464 KB |
Output is correct |
48 |
Incorrect |
10 ms |
5464 KB |
Output isn't correct |
49 |
Incorrect |
11 ms |
5468 KB |
Output isn't correct |
50 |
Correct |
56 ms |
5636 KB |
Output is correct |
51 |
Incorrect |
12 ms |
5720 KB |
Output isn't correct |
52 |
Incorrect |
13 ms |
5464 KB |
Output isn't correct |
53 |
Correct |
74 ms |
5824 KB |
Output is correct |
54 |
Incorrect |
14 ms |
5720 KB |
Output isn't correct |
55 |
Incorrect |
15 ms |
5808 KB |
Output isn't correct |
56 |
Correct |
81 ms |
5988 KB |
Output is correct |
57 |
Incorrect |
16 ms |
5720 KB |
Output isn't correct |
58 |
Incorrect |
15 ms |
5960 KB |
Output isn't correct |
59 |
Correct |
92 ms |
5976 KB |
Output is correct |
60 |
Incorrect |
19 ms |
5976 KB |
Output isn't correct |
61 |
Incorrect |
18 ms |
5980 KB |
Output isn't correct |
62 |
Correct |
104 ms |
6356 KB |
Output is correct |
63 |
Correct |
81 ms |
6100 KB |
Output is correct |
64 |
Incorrect |
119 ms |
6232 KB |
Output isn't correct |
65 |
Correct |
121 ms |
6228 KB |
Output is correct |
66 |
Incorrect |
99 ms |
5976 KB |
Output isn't correct |
67 |
Correct |
84 ms |
6104 KB |
Output is correct |
68 |
Correct |
38 ms |
5980 KB |
Output is correct |
69 |
Correct |
34 ms |
5980 KB |
Output is correct |
70 |
Correct |
32 ms |
5980 KB |
Output is correct |
71 |
Correct |
32 ms |
5980 KB |
Output is correct |
72 |
Incorrect |
51 ms |
5980 KB |
Output isn't correct |
73 |
Incorrect |
64 ms |
6520 KB |
Output isn't correct |
74 |
Incorrect |
60 ms |
6488 KB |
Output isn't correct |
75 |
Incorrect |
68 ms |
6492 KB |
Output isn't correct |
76 |
Incorrect |
57 ms |
6492 KB |
Output isn't correct |
77 |
Incorrect |
66 ms |
6492 KB |
Output isn't correct |
78 |
Correct |
67 ms |
6492 KB |
Output is correct |
79 |
Incorrect |
79 ms |
6532 KB |
Output isn't correct |
80 |
Incorrect |
72 ms |
6492 KB |
Output isn't correct |
81 |
Incorrect |
64 ms |
6492 KB |
Output isn't correct |
82 |
Incorrect |
64 ms |
6496 KB |
Output isn't correct |
83 |
Incorrect |
73 ms |
6232 KB |
Output isn't correct |
84 |
Incorrect |
76 ms |
6256 KB |
Output isn't correct |
85 |
Incorrect |
70 ms |
6400 KB |
Output isn't correct |
86 |
Incorrect |
75 ms |
6412 KB |
Output isn't correct |
87 |
Incorrect |
81 ms |
6236 KB |
Output isn't correct |
88 |
Incorrect |
72 ms |
6236 KB |
Output isn't correct |
89 |
Incorrect |
88 ms |
6236 KB |
Output isn't correct |
90 |
Incorrect |
86 ms |
6344 KB |
Output isn't correct |
91 |
Incorrect |
81 ms |
6232 KB |
Output isn't correct |
92 |
Incorrect |
84 ms |
6232 KB |
Output isn't correct |