Submission #73772

# Submission time Handle Problem Language Result Execution time Memory
73772 2018-08-29T02:04:12 Z TuGSGeReL Mecho (IOI09_mecho) C++14
84 / 100
512 ms 6720 KB
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define ss second
#define ff first
#define ext exit(0)
using namespace std;
int n,s,l,r,x,y,zu[801][801],bo[801][801],ax,ay,h[4]={0,0,-1,1},v[4]={-1,1,0,0};
char c[801][801];
queue<pair<pair<int,int>,int> >q,p;
void dfs(){
	memset(bo,0,sizeof bo);
	bo[q.front().ff.ff][q.front().ff.ss]=1;
	zu[q.front().ff.ff][q.front().ff.ss]=0;
	while(!q.empty()){
		int ii=q.front().ff.ff,jj=q.front().ff.ss,zz=q.front().ss;
		for(int k=0;k<4;k++){
			if(ii+h[k]<=n && ii+h[k]>0 && jj+v[k]<=n && jj+v[k]>0 && c[ii+h[k]][jj+v[k]]!='T' && c[ii+h[k]][jj+v[k]]!='D' && !bo[ii+h[k]][jj+v[k]] && zu[ii+h[k]][jj+v[k]]>zz+s){
				bo[ii+h[k]][jj+v[k]]=1;
				zu[ii+h[k]][jj+v[k]]=zz+s;
				q.push(mp(mp(ii+h[k],jj+v[k]),zz+s));
			}
		}
		q.pop();
	}
}
bool can(int k){
	q=p;
	memset(bo,0,sizeof bo);
	q.push(mp(mp(x,y),k));
	bo[x][y]=1;
	while(!q.empty()){
		int xx=q.front().ff.ff,yy=q.front().ff.ss,kk=q.front().ss;
		for(int i=0;i<4;i++){
			if(bo[ax][ay]) return 1;
			if(xx+h[i]>0 && xx+h[i]<=n && yy+v[i]>0 && yy+v[i]<=n && c[xx+h[i]][yy+v[i]]!='T' && !bo[xx+h[i]][yy+v[i]] && zu[xx+h[i]][yy+v[i]]>kk+1){
				bo[xx+h[i]][yy+v[i]]=1;
				q.push(mp(mp(xx+h[i],yy+v[i]),kk+1));
			}
		}
		q.pop();
	}
	return 0;
}
int main (){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>s;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>c[i][j];
			if(c[i][j]=='M') x=i,y=j;
			if(c[i][j]=='D') ax=i,ay=j;
			zu[i][j]=1e9;
		}
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(c[i][j]=='H')q.push(mp(mp(i,j),0));
	dfs();
	if(can(0)==0) {
		cout<<-1;
		ext;
	}
	l=0,r=1e9;
	while(l+1!=r){
		ll mid=(l+r)/2;
		if(can(mid)) l=mid;
		else r=mid;
	}
	cout<<l/s;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2936 KB Output is correct
2 Correct 10 ms 3040 KB Output is correct
3 Correct 13 ms 3040 KB Output is correct
4 Correct 9 ms 3040 KB Output is correct
5 Correct 10 ms 3040 KB Output is correct
6 Correct 9 ms 3040 KB Output is correct
7 Correct 307 ms 6332 KB Output is correct
8 Correct 6 ms 6332 KB Output is correct
9 Correct 9 ms 6332 KB Output is correct
10 Correct 8 ms 6332 KB Output is correct
11 Correct 8 ms 6332 KB Output is correct
12 Incorrect 11 ms 6332 KB Output isn't correct
13 Incorrect 11 ms 6332 KB Output isn't correct
14 Correct 7 ms 6332 KB Output is correct
15 Correct 10 ms 6332 KB Output is correct
16 Correct 10 ms 6332 KB Output is correct
17 Correct 9 ms 6332 KB Output is correct
18 Correct 10 ms 6332 KB Output is correct
19 Correct 11 ms 6332 KB Output is correct
20 Correct 12 ms 6332 KB Output is correct
21 Correct 10 ms 6332 KB Output is correct
22 Correct 9 ms 6332 KB Output is correct
23 Correct 9 ms 6332 KB Output is correct
24 Correct 10 ms 6332 KB Output is correct
25 Correct 9 ms 6332 KB Output is correct
26 Correct 9 ms 6332 KB Output is correct
27 Correct 10 ms 6332 KB Output is correct
28 Correct 12 ms 6332 KB Output is correct
29 Correct 11 ms 6332 KB Output is correct
30 Correct 10 ms 6332 KB Output is correct
31 Correct 9 ms 6332 KB Output is correct
32 Correct 11 ms 6332 KB Output is correct
33 Correct 15 ms 6332 KB Output is correct
34 Correct 16 ms 6332 KB Output is correct
35 Correct 87 ms 6332 KB Output is correct
36 Correct 17 ms 6332 KB Output is correct
37 Correct 17 ms 6332 KB Output is correct
38 Correct 127 ms 6332 KB Output is correct
39 Correct 17 ms 6332 KB Output is correct
40 Correct 22 ms 6332 KB Output is correct
41 Correct 130 ms 6332 KB Output is correct
42 Correct 18 ms 6332 KB Output is correct
43 Correct 21 ms 6332 KB Output is correct
44 Correct 163 ms 6332 KB Output is correct
45 Correct 18 ms 6332 KB Output is correct
46 Correct 19 ms 6332 KB Output is correct
47 Correct 187 ms 6332 KB Output is correct
48 Correct 23 ms 6332 KB Output is correct
49 Correct 28 ms 6332 KB Output is correct
50 Correct 244 ms 6332 KB Output is correct
51 Correct 25 ms 6332 KB Output is correct
52 Correct 29 ms 6332 KB Output is correct
53 Correct 314 ms 6332 KB Output is correct
54 Correct 36 ms 6332 KB Output is correct
55 Correct 29 ms 6332 KB Output is correct
56 Correct 314 ms 6332 KB Output is correct
57 Correct 30 ms 6332 KB Output is correct
58 Correct 36 ms 6332 KB Output is correct
59 Correct 356 ms 6332 KB Output is correct
60 Correct 33 ms 6332 KB Output is correct
61 Correct 38 ms 6332 KB Output is correct
62 Correct 512 ms 6396 KB Output is correct
63 Correct 179 ms 6396 KB Output is correct
64 Correct 481 ms 6396 KB Output is correct
65 Correct 339 ms 6396 KB Output is correct
66 Correct 244 ms 6396 KB Output is correct
67 Correct 64 ms 6396 KB Output is correct
68 Correct 123 ms 6396 KB Output is correct
69 Correct 124 ms 6396 KB Output is correct
70 Correct 70 ms 6396 KB Output is correct
71 Correct 70 ms 6396 KB Output is correct
72 Incorrect 55 ms 6396 KB Output isn't correct
73 Incorrect 104 ms 6652 KB Output isn't correct
74 Correct 219 ms 6720 KB Output is correct
75 Correct 183 ms 6720 KB Output is correct
76 Correct 168 ms 6720 KB Output is correct
77 Correct 232 ms 6720 KB Output is correct
78 Correct 66 ms 6720 KB Output is correct
79 Correct 204 ms 6720 KB Output is correct
80 Correct 171 ms 6720 KB Output is correct
81 Correct 151 ms 6720 KB Output is correct
82 Correct 171 ms 6720 KB Output is correct
83 Correct 230 ms 6720 KB Output is correct
84 Correct 276 ms 6720 KB Output is correct
85 Correct 211 ms 6720 KB Output is correct
86 Correct 241 ms 6720 KB Output is correct
87 Correct 213 ms 6720 KB Output is correct
88 Correct 238 ms 6720 KB Output is correct
89 Correct 263 ms 6720 KB Output is correct
90 Correct 254 ms 6720 KB Output is correct
91 Correct 241 ms 6720 KB Output is correct
92 Correct 223 ms 6720 KB Output is correct