# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
948112 |
2024-03-17T15:22:50 Z |
packmani |
Mecho (IOI09_mecho) |
C++14 |
|
149 ms |
7348 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int n,speed;
char inp[805][805];
int board[805][805];
bool visited[805][805];
queue<pair<int,int>> q;
pair<int,int> s,e;
int cr,cc,er,ec;
int dr[]={0,-1,0,1};
int dc[]={1,0,-1,0};
int maxTime=0;
int l,m,r;
int layer,tillNext,inNext;
bool bfs(int start)
{
queue<pair<int,int>> tempq;
memset(visited,0,sizeof(visited));
int time=start;
tempq.push({s.first,s.second});
tillNext=1;
inNext=0;
layer=0;
while(!tempq.empty())
{
cr = tempq.front().first;
cc = tempq.front().second;
tempq.pop();
if(board[cr][cc]>time or inp[cr][cc]=='M')//bees have not reached this spot yet
{
//cout << time;
for(int i=0;i<4;i++)
{
er = cr + dr[i];
ec = cc + dc[i];
if(er<0 or ec<0 or er>=n or ec>=n) continue;
if(inp[er][ec]=='D') return 1;
if(visited[er][ec]) continue;
if(board[er][ec]==-1) continue;
if(board[er][ec]<=time) continue;
tempq.push({er,ec});
visited[er][ec]=1;
inNext++;
}
}
tillNext--;
if(tillNext==0)
{
tillNext = inNext;
inNext = 0;
layer++;
if(layer%speed==0) time++;
}
}
return 0;
}
int32_t main()
{
cin.tie(0); ios_base::sync_with_stdio(false);
cin >> n >> speed;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin >> inp[i][j];
if(inp[i][j]=='T') board[i][j]=-1; //no one can traverse
if(inp[i][j]=='H')
{
board[i][j]=0; //not walkable since the 0th sec
q.push({i,j});
}
if(inp[i][j]=='M') s={i,j};
if(inp[i][j]=='D') e={i,j};
if(inp[i][j]=='G') board[i][j] = 1000000;
}
}
//bees
while(!q.empty())
{
cr = q.front().first;
cc = q.front().second;
q.pop();
for(int i=0;i<4;i++)
{
er = cr + dr[i];
ec = cc + dc[i];
if(er<0 or ec<0 or er>=n or ec>=n) continue;
if(board[er][ec]==-1 or board[er][ec]=='D' or board[er][ec]=='M' or board[er][ec]=='H') continue;
if(board[er][ec]<=board[cr][cc]+1) continue;
board[er][ec]=board[cr][cc]+1;
q.push({er,ec});
maxTime=max(maxTime,board[er][ec]);
}
}
l=0;
r=n*n;
m = l + (r-l)/2;
while(l<=r)
{
//cout << l << ' ' << r << ' ' << m << '\n';
if(bfs(m)==1) l=m+1;
else r=m-1;
m = l + (r+0.5-l)/2;
}
if(m==0 and bfs(0)==0) cout << -1;
else cout << m;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
1 ms |
4952 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
57 ms |
6856 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4708 KB |
Output is correct |
10 |
Correct |
1 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
14 |
Correct |
1 ms |
4700 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
1 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
1 ms |
4700 KB |
Output is correct |
21 |
Correct |
1 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4948 KB |
Output is correct |
27 |
Correct |
1 ms |
4696 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4700 KB |
Output is correct |
31 |
Correct |
1 ms |
4700 KB |
Output is correct |
32 |
Correct |
1 ms |
4700 KB |
Output is correct |
33 |
Correct |
5 ms |
6748 KB |
Output is correct |
34 |
Correct |
4 ms |
6744 KB |
Output is correct |
35 |
Correct |
15 ms |
6748 KB |
Output is correct |
36 |
Correct |
4 ms |
6748 KB |
Output is correct |
37 |
Correct |
4 ms |
6748 KB |
Output is correct |
38 |
Correct |
18 ms |
6624 KB |
Output is correct |
39 |
Correct |
5 ms |
6748 KB |
Output is correct |
40 |
Correct |
5 ms |
6748 KB |
Output is correct |
41 |
Correct |
24 ms |
6628 KB |
Output is correct |
42 |
Correct |
6 ms |
7000 KB |
Output is correct |
43 |
Correct |
6 ms |
6748 KB |
Output is correct |
44 |
Correct |
33 ms |
6800 KB |
Output is correct |
45 |
Correct |
7 ms |
6748 KB |
Output is correct |
46 |
Correct |
7 ms |
6620 KB |
Output is correct |
47 |
Correct |
39 ms |
6784 KB |
Output is correct |
48 |
Correct |
8 ms |
6624 KB |
Output is correct |
49 |
Correct |
8 ms |
6748 KB |
Output is correct |
50 |
Correct |
44 ms |
6788 KB |
Output is correct |
51 |
Correct |
11 ms |
6748 KB |
Output is correct |
52 |
Correct |
9 ms |
6748 KB |
Output is correct |
53 |
Correct |
54 ms |
6784 KB |
Output is correct |
54 |
Correct |
11 ms |
6748 KB |
Output is correct |
55 |
Correct |
11 ms |
6620 KB |
Output is correct |
56 |
Correct |
64 ms |
6620 KB |
Output is correct |
57 |
Correct |
11 ms |
6744 KB |
Output is correct |
58 |
Correct |
11 ms |
6748 KB |
Output is correct |
59 |
Correct |
67 ms |
6748 KB |
Output is correct |
60 |
Correct |
14 ms |
6620 KB |
Output is correct |
61 |
Correct |
13 ms |
6744 KB |
Output is correct |
62 |
Correct |
77 ms |
6748 KB |
Output is correct |
63 |
Correct |
95 ms |
6740 KB |
Output is correct |
64 |
Correct |
149 ms |
6748 KB |
Output is correct |
65 |
Correct |
117 ms |
6744 KB |
Output is correct |
66 |
Correct |
93 ms |
6788 KB |
Output is correct |
67 |
Correct |
98 ms |
6628 KB |
Output is correct |
68 |
Correct |
44 ms |
6928 KB |
Output is correct |
69 |
Correct |
44 ms |
6848 KB |
Output is correct |
70 |
Correct |
32 ms |
6624 KB |
Output is correct |
71 |
Correct |
35 ms |
6748 KB |
Output is correct |
72 |
Incorrect |
31 ms |
7004 KB |
Output isn't correct |
73 |
Incorrect |
51 ms |
7340 KB |
Output isn't correct |
74 |
Correct |
41 ms |
7228 KB |
Output is correct |
75 |
Correct |
50 ms |
7188 KB |
Output is correct |
76 |
Correct |
43 ms |
7260 KB |
Output is correct |
77 |
Correct |
49 ms |
7348 KB |
Output is correct |
78 |
Correct |
57 ms |
7276 KB |
Output is correct |
79 |
Correct |
35 ms |
7304 KB |
Output is correct |
80 |
Correct |
42 ms |
7128 KB |
Output is correct |
81 |
Correct |
57 ms |
7252 KB |
Output is correct |
82 |
Correct |
42 ms |
7260 KB |
Output is correct |
83 |
Correct |
62 ms |
7200 KB |
Output is correct |
84 |
Correct |
52 ms |
7000 KB |
Output is correct |
85 |
Correct |
51 ms |
7052 KB |
Output is correct |
86 |
Correct |
55 ms |
7004 KB |
Output is correct |
87 |
Correct |
51 ms |
7004 KB |
Output is correct |
88 |
Correct |
59 ms |
7000 KB |
Output is correct |
89 |
Correct |
60 ms |
7100 KB |
Output is correct |
90 |
Correct |
73 ms |
7108 KB |
Output is correct |
91 |
Correct |
57 ms |
7004 KB |
Output is correct |
92 |
Correct |
59 ms |
7192 KB |
Output is correct |