Submission #138697

# Submission time Handle Problem Language Result Execution time Memory
138697 2019-07-30T08:44:24 Z tinjyu Mecho (IOI09_mecho) C++14
50 / 100
307 ms 17768 KB
#include <iostream>
using namespace std;
int n,s;
char map[1005][1005],tmap[1005][1005],tag[1005][1005];
int ex,ey,beetag[1005][1005],beartag[1005][1005],sx,sy,bee[1000005][3],bear[1000005][3];
int check(int step)
{
	
	//cout<<step<<endl;
	int beep=0,beepp=-1,bearp=0,bearpp=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			tag[i][j]=0;
			beartag[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(map[i][j]=='H')
			{
				beepp++;
				bee[beepp][0]=i;
				bee[beepp][1]=j;
				bee[beepp][2]=0;
			}
			if(map[i][j]=='M')
			{
				bear[0][0]=i;
				bear[0][1]=j;
				bear[0][2]=0;
				tag[i][j]=1;
				map[i][j]='G';
			}
		}
	}
	while(beep<=beepp)
	{
		if(bee[beep][2]==step)break;
		int nowx=bee[beep][0],nowy=bee[beep][1];
		for(int i=1;i<=4;i++)
		{
			int tmpx=nowx,tmpy=nowy;
			if(i==1)tmpx++;
			if(i==2)tmpy++;
			if(i==3)tmpx--;
			if(i==4)tmpy--;
			if((map[tmpx][tmpy]=='G' || map[tmpx][tmpy]=='M') && tmpx>0 && tmpy<=n && tmpy>0 && tmpy<=n)
			{
				beepp++;
				bee[beepp][0]=tmpx;
				bee[beepp][1]=tmpy;
				bee[beepp][2]=bee[beep][2]+1;
				map[tmpx][tmpy]='H';
			}
		}
		beep++;
	}
	for(int i=1;i<=n;i++)
	{
		//for(int j=1;j<=n;j++)cout<<map[i][j];
		//cout<<endl;
	}
	int count=n*2,bearstep=0;
	while(count--)
	{
		bearstep+=s;
		while(bearp<=bearpp)
		{
			//cout<<bear[bearp][0]<<" "<<bear[bearp][1]<<" "<<bear[bearp][2]<<endl;
			if(bear[bearp][2]==bearstep)break;
			int nowx=bear[bearp][0],nowy=bear[bearp][1];
			if(map[nowx][nowy]=='H')
			{
				bearp++;
				continue;
			}
			for(int i=1;i<=4;i++)
			{
				int tmpx=nowx,tmpy=nowy;
				if(i==1)tmpx++;
				if(i==2)tmpy++;
				if(i==3)tmpx--;
				if(i==4)tmpy--;
				if(map[tmpx][tmpy]=='D')return 1;
				if(map[tmpx][tmpy]=='G' && tmpx>0 && tmpy<=n && tmpy>0 && tmpy<=n && tag[tmpx][tmpy]==0)
				{
					bearpp++;
					bear[bearpp][0]=tmpx;
					bear[bearpp][1]=tmpy;
					bear[bearpp][2]=bear[bearp][2]+1;
					tag[tmpx][tmpy]=1;
				}
			}
			bearp++;
		}
		step++;
		//cout<<step<<" "<<count<<endl;
		while(beep<=beepp)
		{
			//cout<<bee[beep][0]<<" "<<bee[beep][1]<<" "<<bee[beep][2]<<endl;
			if(bee[beep][2]==step)break;
			int nowx=bee[beep][0],nowy=bee[beep][1];
			for(int i=1;i<=4;i++)
			{
				int tmpx=nowx,tmpy=nowy;
				if(i==1)tmpx++;
				if(i==2)tmpy++;
				if(i==3)tmpx--;
				if(i==4)tmpy--;
				if(map[tmpx][tmpy]=='G' && tmpx>0 && tmpy<=n && tmpy>0 && tmpy<=n)
				{
					beepp++;
					bee[beepp][0]=tmpx;
					bee[beepp][1]=tmpy;
					bee[beepp][2]=bee[beep][2]+1;
					map[tmpx][tmpy]='H';
				}
			}
			beep++;
		}
		for(int i=1;i<=n;i++)
		{
			//for(int j=1;j<=n;j++)cout<<map[i][j];
			//cout<<endl;
		}
		//cout<<endl;
	}
	return 0;
}
int main()
{
	cin>>n>>s;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>map[i][j];
			tmap[i][j]=map[i][j];
		}
	}
	int l=0,r=n*2,ans=-1;
	while(l<=r)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				map[i][j]=tmap[i][j];
			}
		}
		int mid=(l+r)/2;
		if(check(mid)==1)
		{
			ans=mid;
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 266 ms 17696 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Incorrect 3 ms 760 KB Output isn't correct
13 Correct 3 ms 760 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Incorrect 2 ms 504 KB Output isn't correct
16 Incorrect 2 ms 504 KB Output isn't correct
17 Incorrect 2 ms 504 KB Output isn't correct
18 Incorrect 2 ms 504 KB Output isn't correct
19 Incorrect 2 ms 632 KB Output isn't correct
20 Incorrect 3 ms 632 KB Output isn't correct
21 Incorrect 2 ms 632 KB Output isn't correct
22 Incorrect 2 ms 632 KB Output isn't correct
23 Incorrect 3 ms 760 KB Output isn't correct
24 Incorrect 3 ms 760 KB Output isn't correct
25 Incorrect 3 ms 760 KB Output isn't correct
26 Incorrect 3 ms 760 KB Output isn't correct
27 Incorrect 3 ms 760 KB Output isn't correct
28 Incorrect 3 ms 888 KB Output isn't correct
29 Incorrect 3 ms 888 KB Output isn't correct
30 Incorrect 3 ms 888 KB Output isn't correct
31 Incorrect 3 ms 888 KB Output isn't correct
32 Incorrect 3 ms 888 KB Output isn't correct
33 Incorrect 20 ms 2812 KB Output isn't correct
34 Incorrect 21 ms 2936 KB Output isn't correct
35 Correct 46 ms 4984 KB Output is correct
36 Incorrect 25 ms 3192 KB Output isn't correct
37 Incorrect 27 ms 3320 KB Output isn't correct
38 Correct 65 ms 6136 KB Output is correct
39 Incorrect 35 ms 3704 KB Output isn't correct
40 Incorrect 31 ms 3704 KB Output isn't correct
41 Correct 83 ms 7204 KB Output is correct
42 Incorrect 37 ms 4116 KB Output isn't correct
43 Incorrect 37 ms 4088 KB Output isn't correct
44 Correct 93 ms 8440 KB Output is correct
45 Incorrect 46 ms 4472 KB Output isn't correct
46 Incorrect 45 ms 4600 KB Output isn't correct
47 Correct 112 ms 9932 KB Output is correct
48 Incorrect 65 ms 4856 KB Output isn't correct
49 Incorrect 53 ms 4856 KB Output isn't correct
50 Correct 146 ms 11068 KB Output is correct
51 Incorrect 62 ms 5240 KB Output isn't correct
52 Incorrect 64 ms 5260 KB Output isn't correct
53 Correct 166 ms 12796 KB Output is correct
54 Incorrect 70 ms 5596 KB Output isn't correct
55 Incorrect 71 ms 5752 KB Output isn't correct
56 Correct 193 ms 14360 KB Output is correct
57 Incorrect 80 ms 6008 KB Output isn't correct
58 Incorrect 80 ms 6136 KB Output isn't correct
59 Correct 225 ms 15992 KB Output is correct
60 Incorrect 91 ms 6436 KB Output isn't correct
61 Incorrect 91 ms 6520 KB Output isn't correct
62 Correct 262 ms 17768 KB Output is correct
63 Incorrect 255 ms 14620 KB Output isn't correct
64 Correct 307 ms 14968 KB Output is correct
65 Correct 297 ms 15028 KB Output is correct
66 Correct 279 ms 14208 KB Output is correct
67 Correct 256 ms 13176 KB Output is correct
68 Correct 263 ms 12056 KB Output is correct
69 Correct 224 ms 12024 KB Output is correct
70 Correct 247 ms 11692 KB Output is correct
71 Correct 264 ms 11556 KB Output is correct
72 Correct 230 ms 10872 KB Output is correct
73 Correct 252 ms 16880 KB Output is correct
74 Correct 257 ms 15740 KB Output is correct
75 Correct 235 ms 15992 KB Output is correct
76 Correct 247 ms 15912 KB Output is correct
77 Correct 244 ms 16248 KB Output is correct
78 Correct 256 ms 17176 KB Output is correct
79 Correct 231 ms 16376 KB Output is correct
80 Correct 230 ms 16092 KB Output is correct
81 Correct 250 ms 16376 KB Output is correct
82 Correct 239 ms 15700 KB Output is correct
83 Correct 277 ms 17016 KB Output is correct
84 Correct 237 ms 16888 KB Output is correct
85 Correct 247 ms 16732 KB Output is correct
86 Correct 255 ms 16936 KB Output is correct
87 Correct 274 ms 16732 KB Output is correct
88 Correct 295 ms 17144 KB Output is correct
89 Correct 244 ms 17352 KB Output is correct
90 Correct 248 ms 17272 KB Output is correct
91 Correct 244 ms 17144 KB Output is correct
92 Correct 247 ms 17144 KB Output is correct