Submission #948114

# Submission time Handle Problem Language Result Execution time Memory
948114 2024-03-17T15:27:29 Z packmani Mecho (IOI09_mecho) C++14
4 / 100
33 ms 7260 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;
	if(time>=board[s.first][s.second]) return 0;
	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]=='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;
	int ans=-1;
	while(l<=r)
	{
		//cout << l << ' ' << r << ' ' << m << '\n';
		m = l + (r+0.5-l)/2;
		if(bfs(m)==1) 
		{
			l=m+1;
			ans=m;
		}
		else r=m-1;
		
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4700 KB Output isn't correct
2 Incorrect 1 ms 4700 KB Output isn't correct
3 Incorrect 1 ms 4700 KB Output isn't correct
4 Incorrect 1 ms 4700 KB Output isn't correct
5 Incorrect 1 ms 4700 KB Output isn't correct
6 Incorrect 1 ms 4696 KB Output isn't correct
7 Incorrect 19 ms 7004 KB Output isn't correct
8 Correct 1 ms 4700 KB Output is correct
9 Incorrect 1 ms 4700 KB Output isn't correct
10 Incorrect 1 ms 4700 KB Output isn't correct
11 Incorrect 1 ms 4700 KB Output isn't correct
12 Incorrect 1 ms 4700 KB Output isn't correct
13 Incorrect 1 ms 4696 KB Output isn't correct
14 Correct 1 ms 4696 KB Output is correct
15 Incorrect 1 ms 4700 KB Output isn't correct
16 Incorrect 1 ms 4700 KB Output isn't correct
17 Incorrect 1 ms 4696 KB Output isn't correct
18 Incorrect 1 ms 4700 KB Output isn't correct
19 Incorrect 1 ms 4700 KB Output isn't correct
20 Incorrect 1 ms 4700 KB Output isn't correct
21 Incorrect 1 ms 4700 KB Output isn't correct
22 Incorrect 1 ms 4696 KB Output isn't correct
23 Incorrect 1 ms 4700 KB Output isn't correct
24 Incorrect 1 ms 4700 KB Output isn't correct
25 Incorrect 1 ms 4696 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 4700 KB Output isn't correct
29 Incorrect 1 ms 4696 KB Output isn't correct
30 Incorrect 1 ms 4700 KB Output isn't correct
31 Incorrect 1 ms 4700 KB Output isn't correct
32 Incorrect 1 ms 4700 KB Output isn't correct
33 Incorrect 3 ms 6748 KB Output isn't correct
34 Incorrect 3 ms 6748 KB Output isn't correct
35 Incorrect 4 ms 6748 KB Output isn't correct
36 Incorrect 4 ms 6616 KB Output isn't correct
37 Incorrect 4 ms 6748 KB Output isn't correct
38 Incorrect 5 ms 6748 KB Output isn't correct
39 Incorrect 6 ms 6744 KB Output isn't correct
40 Incorrect 5 ms 6748 KB Output isn't correct
41 Incorrect 6 ms 6612 KB Output isn't correct
42 Incorrect 6 ms 6748 KB Output isn't correct
43 Incorrect 6 ms 6748 KB Output isn't correct
44 Incorrect 7 ms 6748 KB Output isn't correct
45 Incorrect 7 ms 6748 KB Output isn't correct
46 Incorrect 8 ms 6748 KB Output isn't correct
47 Incorrect 9 ms 6748 KB Output isn't correct
48 Incorrect 9 ms 6748 KB Output isn't correct
49 Incorrect 7 ms 6744 KB Output isn't correct
50 Incorrect 10 ms 6748 KB Output isn't correct
51 Incorrect 10 ms 6744 KB Output isn't correct
52 Incorrect 9 ms 6748 KB Output isn't correct
53 Incorrect 10 ms 6748 KB Output isn't correct
54 Incorrect 12 ms 6620 KB Output isn't correct
55 Incorrect 14 ms 6748 KB Output isn't correct
56 Incorrect 12 ms 6748 KB Output isn't correct
57 Incorrect 11 ms 6748 KB Output isn't correct
58 Incorrect 11 ms 6748 KB Output isn't correct
59 Incorrect 22 ms 6748 KB Output isn't correct
60 Incorrect 13 ms 6620 KB Output isn't correct
61 Incorrect 19 ms 6748 KB Output isn't correct
62 Incorrect 16 ms 6620 KB Output isn't correct
63 Incorrect 25 ms 6620 KB Output isn't correct
64 Incorrect 24 ms 6632 KB Output isn't correct
65 Incorrect 24 ms 6748 KB Output isn't correct
66 Incorrect 25 ms 6740 KB Output isn't correct
67 Correct 26 ms 6744 KB Output is correct
68 Incorrect 28 ms 6676 KB Output isn't correct
69 Incorrect 30 ms 6660 KB Output isn't correct
70 Incorrect 31 ms 6684 KB Output isn't correct
71 Incorrect 30 ms 6736 KB Output isn't correct
72 Incorrect 27 ms 6748 KB Output isn't correct
73 Incorrect 26 ms 7172 KB Output isn't correct
74 Incorrect 31 ms 7176 KB Output isn't correct
75 Incorrect 25 ms 7248 KB Output isn't correct
76 Incorrect 24 ms 7184 KB Output isn't correct
77 Incorrect 22 ms 7260 KB Output isn't correct
78 Correct 31 ms 7168 KB Output is correct
79 Incorrect 21 ms 7256 KB Output isn't correct
80 Incorrect 21 ms 7124 KB Output isn't correct
81 Incorrect 24 ms 7260 KB Output isn't correct
82 Incorrect 20 ms 7260 KB Output isn't correct
83 Incorrect 25 ms 7000 KB Output isn't correct
84 Incorrect 33 ms 7004 KB Output isn't correct
85 Incorrect 20 ms 7044 KB Output isn't correct
86 Incorrect 20 ms 7004 KB Output isn't correct
87 Incorrect 22 ms 7004 KB Output isn't correct
88 Incorrect 21 ms 7132 KB Output isn't correct
89 Incorrect 24 ms 7000 KB Output isn't correct
90 Incorrect 20 ms 7000 KB Output isn't correct
91 Incorrect 22 ms 6944 KB Output isn't correct
92 Incorrect 22 ms 6996 KB Output isn't correct