# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1038767 |
2024-07-30T07:21:28 Z |
Tepeyac |
Mecho (IOI09_mecho) |
C++11 |
|
139 ms |
6992 KB |
#include <bits/stdc++.h>
using namespace std;
int n, s;
char ma[802][802];
int enj[802][802];
int pa[802][802];
int r, c;
int r2, c2;
int mov[4][2] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1} };
bool isvalidBee(int x, int y)
{
if(!x || !y || x > n || y > n)
return false;
if(ma[x][y] == 'T' || ma[x][y] == 'D')
return false;
if(enj[x][y] != -1)
return false;
return true;
}
void BeeFS()
{
queue<pair<int, int> > q;
pair<int, int> act;
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
{
if(ma[i][j] == 'H')
{
q.push({i, j});
}
else
enj[i][j] = -1;
}
}
while(!q.empty())
{
act = q.front();
q.pop();
for(int i = 0; i < 4; ++i)
{
int nx = act.first + mov[i][0];
int ny = act.second + mov[i][1];
if(isvalidBee(nx, ny))
{
enj[nx][ny] = enj[act.first][act.second] + s;
q.push({nx, ny});
}
}
}
}
bool isvalidMecho(int x, int y, int time)
{
if(!x || !y || x > n || y > n)
return false;
if(ma[x][y] == 'T')
return false;
if(ma[x][y] == 'D')
return true;
if(pa[x][y] != -1)
return false;
if(time >= enj[x][y])
return false;
return true;
}
bool monotone(int m)
{
queue<pair<int, int> > q;
pair<int, int> act;
for( int i = 1; i <= n; i++ )
for( int j = 1; j <= n; j++ )
pa[i][j] = -1;
q.push({r, c});
pa[r][c] = m * s;
if(enj[r][c] <= pa[r][c]) return false;
while(!q.empty())
{
act = q.front();
q.pop();
int time = pa[act.first][act.second] + 1;
for(int i = 0; i < 4; ++i)
{
int nx = act.first + mov[i][0];
int ny = act.second + mov[i][1];
if(isvalidMecho(nx, ny, time))
{
q.push({nx, ny});
pa[nx][ny] = time;
}
}
}
return pa[r2][c2] != -1;
}
int Binary(int a, int b)
{
while(a != b)
{
int m = (a + b) / 2 + 1;
if(monotone(m))
{
a = m;
}
else
b = m - 1;
}
return a;
}
int main()
{
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> s;
for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
{
cin >> ma[i][j];
if(ma[i][j] == 'M')
{
r = i, c = j;
}
if(ma[i][j] == 'D')
{
r2 = i, c2 = j;
}
}
}
BeeFS();
if(!monotone(0))
{
cout << "-1\n"; return 0;
}
int maxm = enj[r][c];
cout << Binary(0, maxm);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
67 ms |
6532 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is 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 |
Correct |
1 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
860 KB |
Output is correct |
26 |
Correct |
0 ms |
860 KB |
Output is correct |
27 |
Correct |
1 ms |
860 KB |
Output is correct |
28 |
Correct |
0 ms |
860 KB |
Output is correct |
29 |
Correct |
1 ms |
860 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
1 ms |
860 KB |
Output is correct |
32 |
Correct |
1 ms |
860 KB |
Output is correct |
33 |
Correct |
5 ms |
2908 KB |
Output is correct |
34 |
Correct |
5 ms |
2908 KB |
Output is correct |
35 |
Correct |
17 ms |
2980 KB |
Output is correct |
36 |
Correct |
6 ms |
3416 KB |
Output is correct |
37 |
Correct |
6 ms |
3420 KB |
Output is correct |
38 |
Correct |
22 ms |
3468 KB |
Output is correct |
39 |
Correct |
8 ms |
3856 KB |
Output is correct |
40 |
Correct |
7 ms |
3684 KB |
Output is correct |
41 |
Correct |
31 ms |
3676 KB |
Output is correct |
42 |
Correct |
9 ms |
4188 KB |
Output is correct |
43 |
Correct |
8 ms |
4188 KB |
Output is correct |
44 |
Correct |
36 ms |
4228 KB |
Output is correct |
45 |
Correct |
10 ms |
4444 KB |
Output is correct |
46 |
Incorrect |
19 ms |
4660 KB |
Output isn't correct |
47 |
Correct |
41 ms |
4472 KB |
Output is correct |
48 |
Correct |
12 ms |
4956 KB |
Output is correct |
49 |
Incorrect |
17 ms |
4952 KB |
Output isn't correct |
50 |
Correct |
56 ms |
4956 KB |
Output is correct |
51 |
Correct |
14 ms |
5464 KB |
Output is correct |
52 |
Incorrect |
37 ms |
5592 KB |
Output isn't correct |
53 |
Correct |
68 ms |
5468 KB |
Output is correct |
54 |
Correct |
15 ms |
5720 KB |
Output is correct |
55 |
Incorrect |
34 ms |
5724 KB |
Output isn't correct |
56 |
Correct |
72 ms |
5748 KB |
Output is correct |
57 |
Correct |
21 ms |
6236 KB |
Output is correct |
58 |
Incorrect |
32 ms |
6236 KB |
Output isn't correct |
59 |
Correct |
90 ms |
6108 KB |
Output is correct |
60 |
Correct |
20 ms |
6420 KB |
Output is correct |
61 |
Incorrect |
40 ms |
6488 KB |
Output isn't correct |
62 |
Correct |
91 ms |
6492 KB |
Output is correct |
63 |
Correct |
83 ms |
6488 KB |
Output is correct |
64 |
Correct |
139 ms |
6492 KB |
Output is correct |
65 |
Correct |
125 ms |
6600 KB |
Output is correct |
66 |
Correct |
109 ms |
6484 KB |
Output is correct |
67 |
Correct |
27 ms |
6492 KB |
Output is correct |
68 |
Correct |
40 ms |
6492 KB |
Output is correct |
69 |
Correct |
43 ms |
6640 KB |
Output is correct |
70 |
Correct |
32 ms |
6480 KB |
Output is correct |
71 |
Correct |
34 ms |
6444 KB |
Output is correct |
72 |
Correct |
33 ms |
6484 KB |
Output is correct |
73 |
Correct |
28 ms |
6748 KB |
Output is correct |
74 |
Correct |
51 ms |
6736 KB |
Output is correct |
75 |
Correct |
51 ms |
6992 KB |
Output is correct |
76 |
Correct |
62 ms |
6736 KB |
Output is correct |
77 |
Correct |
52 ms |
6704 KB |
Output is correct |
78 |
Correct |
25 ms |
6736 KB |
Output is correct |
79 |
Correct |
51 ms |
6748 KB |
Output is correct |
80 |
Correct |
53 ms |
6764 KB |
Output is correct |
81 |
Correct |
52 ms |
6868 KB |
Output is correct |
82 |
Correct |
49 ms |
6732 KB |
Output is correct |
83 |
Correct |
70 ms |
6748 KB |
Output is correct |
84 |
Correct |
64 ms |
6744 KB |
Output is correct |
85 |
Correct |
56 ms |
6736 KB |
Output is correct |
86 |
Correct |
57 ms |
6748 KB |
Output is correct |
87 |
Correct |
60 ms |
6740 KB |
Output is correct |
88 |
Correct |
66 ms |
6564 KB |
Output is correct |
89 |
Correct |
71 ms |
6740 KB |
Output is correct |
90 |
Correct |
65 ms |
6768 KB |
Output is correct |
91 |
Correct |
70 ms |
6748 KB |
Output is correct |
92 |
Correct |
77 ms |
6740 KB |
Output is correct |