Submission #60050

# Submission time Handle Problem Language Result Execution time Memory
60050 2018-07-23T14:04:20 Z nvmdava Mecho (IOI09_mecho) C++17
84 / 100
476 ms 6652 KB
#include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
using namespace std;
int n,s;
int t[802][802];
char c[802][802];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int  chk[802][802];
queue<pair<int, int > > q;

bool pos(int x,int y, int now){
	memset(chk,0,sizeof(chk));
	chk[x][y] = now;
	while(!q.empty()){
		q.pop();
	}
	q.push(mp(x,y));
	while(!q.empty()){
		x = q.front().ff;
		y = q.front().ss;
		q.pop();
		for(int i = 0; i < 4; i++){
			if(c[x + dx[i]][y + dy[i]]=='D'){
				return 1;
			}
			if(chk[x + dx[i]][y + dy[i]]==0 && t[x + dx[i]][y + dy[i]] > chk[x][y] + 1){
				chk[x + dx[i]][y + dy[i]] = chk[x][y] + 1;
				q.push( mp(x + dx[i] , y + dy[i]) );
			}
		}
	}
	return 0;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int i,j,xx,yy;
	cin>>n>>s;
	for(i = 1; i <= n; i++){
		for(j = 1; j <= n; j++){
			cin>>c[i][j];
			if(c[i][j]=='H'){
				q.push(mp(i,j));
			} else if(c[i][j]=='M'){
				xx=i;
				yy=j;
			}
		}
	}
	int x,y;
	while(!q.empty()){
		x=q.front().ff;
		y=q.front().ss;
		q.pop();
		for(i=0;i<4;i++){
			if(c[x + dx[i]][y + dy[i]]=='G'&&t[x + dx[i]][y + dy[i]]==0){
				t[x + dx[i]][y + dy[i]] = t[x][y]+s;
				q.push(mp(x + dx[i] , y + dy[i]));
			}
		}
	}
	int l = 0 , r = 1e9,m;
	if(pos(xx,yy,0)==0){
		cout<<-1;
		return 0;
	}
	while(l + 1 != r){
		m = (l + r) / 2;
		if(pos(xx,yy,m)){
			l = m;
		} else {
			r = m;
		}
	}
	cout<<l/s;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:68:8: warning: 'yy' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if(pos(xx,yy,0)==0){
     ~~~^~~~~~~~~
mecho.cpp:68:8: warning: 'xx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2808 KB Output is correct
2 Correct 9 ms 2916 KB Output is correct
3 Correct 9 ms 2992 KB Output is correct
4 Correct 7 ms 2992 KB Output is correct
5 Correct 10 ms 3068 KB Output is correct
6 Correct 12 ms 3272 KB Output is correct
7 Correct 273 ms 6380 KB Output is correct
8 Correct 5 ms 6380 KB Output is correct
9 Correct 11 ms 6380 KB Output is correct
10 Correct 10 ms 6380 KB Output is correct
11 Correct 9 ms 6380 KB Output is correct
12 Incorrect 11 ms 6380 KB Output isn't correct
13 Incorrect 10 ms 6380 KB Output isn't correct
14 Correct 6 ms 6380 KB Output is correct
15 Correct 11 ms 6380 KB Output is correct
16 Correct 10 ms 6380 KB Output is correct
17 Correct 10 ms 6380 KB Output is correct
18 Correct 11 ms 6380 KB Output is correct
19 Correct 11 ms 6380 KB Output is correct
20 Correct 8 ms 6380 KB Output is correct
21 Correct 10 ms 6380 KB Output is correct
22 Correct 10 ms 6380 KB Output is correct
23 Correct 10 ms 6380 KB Output is correct
24 Correct 10 ms 6380 KB Output is correct
25 Correct 9 ms 6380 KB Output is correct
26 Correct 11 ms 6380 KB Output is correct
27 Correct 10 ms 6380 KB Output is correct
28 Correct 10 ms 6380 KB Output is correct
29 Correct 10 ms 6380 KB Output is correct
30 Correct 9 ms 6380 KB Output is correct
31 Correct 10 ms 6380 KB Output is correct
32 Correct 9 ms 6380 KB Output is correct
33 Correct 17 ms 6380 KB Output is correct
34 Correct 14 ms 6380 KB Output is correct
35 Correct 80 ms 6380 KB Output is correct
36 Correct 14 ms 6380 KB Output is correct
37 Correct 15 ms 6380 KB Output is correct
38 Correct 90 ms 6380 KB Output is correct
39 Correct 18 ms 6380 KB Output is correct
40 Correct 19 ms 6380 KB Output is correct
41 Correct 130 ms 6380 KB Output is correct
42 Correct 17 ms 6380 KB Output is correct
43 Correct 17 ms 6380 KB Output is correct
44 Correct 147 ms 6380 KB Output is correct
45 Correct 20 ms 6380 KB Output is correct
46 Correct 19 ms 6380 KB Output is correct
47 Correct 155 ms 6380 KB Output is correct
48 Correct 25 ms 6380 KB Output is correct
49 Correct 28 ms 6380 KB Output is correct
50 Correct 214 ms 6380 KB Output is correct
51 Correct 30 ms 6380 KB Output is correct
52 Correct 23 ms 6380 KB Output is correct
53 Correct 286 ms 6380 KB Output is correct
54 Correct 33 ms 6380 KB Output is correct
55 Correct 29 ms 6380 KB Output is correct
56 Correct 326 ms 6380 KB Output is correct
57 Correct 30 ms 6380 KB Output is correct
58 Correct 37 ms 6380 KB Output is correct
59 Correct 381 ms 6380 KB Output is correct
60 Correct 35 ms 6380 KB Output is correct
61 Correct 38 ms 6380 KB Output is correct
62 Correct 476 ms 6380 KB Output is correct
63 Correct 176 ms 6380 KB Output is correct
64 Correct 409 ms 6380 KB Output is correct
65 Correct 344 ms 6380 KB Output is correct
66 Correct 276 ms 6380 KB Output is correct
67 Correct 72 ms 6424 KB Output is correct
68 Correct 129 ms 6424 KB Output is correct
69 Correct 105 ms 6424 KB Output is correct
70 Correct 65 ms 6424 KB Output is correct
71 Correct 76 ms 6424 KB Output is correct
72 Incorrect 48 ms 6424 KB Output isn't correct
73 Incorrect 139 ms 6524 KB Output isn't correct
74 Correct 173 ms 6524 KB Output is correct
75 Correct 133 ms 6524 KB Output is correct
76 Correct 150 ms 6524 KB Output is correct
77 Correct 169 ms 6524 KB Output is correct
78 Correct 49 ms 6524 KB Output is correct
79 Correct 189 ms 6524 KB Output is correct
80 Correct 159 ms 6524 KB Output is correct
81 Correct 169 ms 6528 KB Output is correct
82 Correct 170 ms 6652 KB Output is correct
83 Correct 192 ms 6652 KB Output is correct
84 Correct 204 ms 6652 KB Output is correct
85 Correct 185 ms 6652 KB Output is correct
86 Correct 165 ms 6652 KB Output is correct
87 Correct 221 ms 6652 KB Output is correct
88 Correct 224 ms 6652 KB Output is correct
89 Correct 232 ms 6652 KB Output is correct
90 Correct 187 ms 6652 KB Output is correct
91 Correct 252 ms 6652 KB Output is correct
92 Correct 175 ms 6652 KB Output is correct