Submission #217540

# Submission time Handle Problem Language Result Execution time Memory
217540 2020-03-30T08:05:49 Z t12345 Mecho (IOI09_mecho) C++14
84 / 100
225 ms 9592 KB
#include <iostream>
#include <cstdio>
#include <queue>
#define N 805
#define PR pair<int, int>
#define F first
#define S second
using namespace std;

int n, k, mi, mj, di, dj, v[N][N], x[N][N], y[N][N];
int lt, rt, md, ans;
char a[N][N];
queue<PR> qu;
int dr[4] = {1,0,-1,0};
int dc[4] = {0,1,0,-1};

int f(int p) {
	int i, j, r, c, t;
	for(i=0; i<n; i++) for(j=0; j<n; j++) v[i][j] = 0;
	while(!qu.empty()) qu.pop();
	y[mi][mj] = p * k;
	if(y[mi][mj] < x[mi][mj]) {
		v[mi][mj] = 1;
		qu.push({mi, mj});
	}
	while(!qu.empty()) {
		r = qu.front().F;
		c = qu.front().S;
		qu.pop();
		for(t=0; t<4; t++) {
			i = r + dr[t];
			j = c + dc[t];
			if(0<=i && i<n && 0<=j && j<n && y[r][c]+1 < x[i][j] && !v[i][j] && (a[i][j]=='G' || a[i][j]=='D')) {
				v[i][j] = 1;
				y[i][j] = y[r][c] + 1;
				qu.push({i, j});
			}
		}
	}
	return v[di][dj];
}

int main() {
	int i, j, r, c, t;
	cin >> n >> k;
	for(i=0; i<n; i++) {
		cin >> a[i];
		for(j=0; j<n; j++) {
			x[i][j] = 1e9;
			if(a[i][j]=='H') {
				x[i][j] = 0;
				v[i][j] = 1;
				qu.push({i,j});
			}
			else if(a[i][j]=='M') mi=i, mj=j;
			else if(a[i][j]=='D') di=i, dj=j;
		}
	}
	while(!qu.empty()) {
		r = qu.front().F;
		c = qu.front().S;
		qu.pop();
		for(t=0; t<4; t++) {
			i = r + dr[t];
			j = c + dc[t];
			if(0<=i && i<n && 0<=j && j<n && !v[i][j] && (a[i][j]=='G' || a[i][j]=='M')) {
				v[i][j] = 1;
				x[i][j] = x[r][c] + k;
				qu.push({i, j});
			}
		}
	}
	rt = n*n;
	while(lt <= rt) {
		md = lt+rt >> 1;
		if(f(md)) ans=md, lt=md+1;
		else rt=md-1;
	}
	cout << ans;
	return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:75:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   md = lt+rt >> 1;
        ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 118 ms 8312 KB Output is correct
8 Incorrect 5 ms 512 KB Output isn't correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 6 ms 768 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Incorrect 6 ms 896 KB Output isn't correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 5 ms 768 KB Output is correct
24 Correct 5 ms 768 KB Output is correct
25 Correct 5 ms 768 KB Output is correct
26 Correct 5 ms 896 KB Output is correct
27 Correct 5 ms 896 KB Output is correct
28 Correct 5 ms 896 KB Output is correct
29 Correct 6 ms 896 KB Output is correct
30 Correct 6 ms 896 KB Output is correct
31 Correct 5 ms 896 KB Output is correct
32 Correct 5 ms 1016 KB Output is correct
33 Correct 15 ms 3200 KB Output is correct
34 Correct 17 ms 3456 KB Output is correct
35 Correct 31 ms 3968 KB Output is correct
36 Correct 18 ms 3584 KB Output is correct
37 Correct 18 ms 3968 KB Output is correct
38 Correct 41 ms 4608 KB Output is correct
39 Correct 22 ms 4096 KB Output is correct
40 Correct 23 ms 4480 KB Output is correct
41 Correct 49 ms 5120 KB Output is correct
42 Correct 24 ms 4480 KB Output is correct
43 Correct 26 ms 4992 KB Output is correct
44 Correct 63 ms 5632 KB Output is correct
45 Correct 31 ms 4992 KB Output is correct
46 Correct 29 ms 5504 KB Output is correct
47 Correct 77 ms 6272 KB Output is correct
48 Correct 35 ms 5376 KB Output is correct
49 Correct 37 ms 5888 KB Output is correct
50 Correct 95 ms 6904 KB Output is correct
51 Correct 38 ms 5888 KB Output is correct
52 Correct 39 ms 6392 KB Output is correct
53 Correct 109 ms 7416 KB Output is correct
54 Correct 42 ms 6392 KB Output is correct
55 Correct 46 ms 6948 KB Output is correct
56 Correct 135 ms 7928 KB Output is correct
57 Correct 54 ms 6776 KB Output is correct
58 Correct 49 ms 7416 KB Output is correct
59 Correct 146 ms 8568 KB Output is correct
60 Correct 53 ms 7288 KB Output is correct
61 Correct 56 ms 7928 KB Output is correct
62 Correct 179 ms 9208 KB Output is correct
63 Correct 138 ms 9208 KB Output is correct
64 Correct 225 ms 9208 KB Output is correct
65 Correct 174 ms 9208 KB Output is correct
66 Correct 156 ms 9208 KB Output is correct
67 Incorrect 148 ms 9208 KB Output isn't correct
68 Correct 85 ms 9208 KB Output is correct
69 Correct 82 ms 9208 KB Output is correct
70 Correct 70 ms 9208 KB Output is correct
71 Correct 79 ms 9240 KB Output is correct
72 Correct 67 ms 7288 KB Output is correct
73 Correct 67 ms 9480 KB Output is correct
74 Correct 89 ms 9464 KB Output is correct
75 Correct 104 ms 9464 KB Output is correct
76 Correct 102 ms 9592 KB Output is correct
77 Correct 96 ms 9464 KB Output is correct
78 Incorrect 118 ms 8056 KB Output isn't correct
79 Correct 80 ms 7800 KB Output is correct
80 Correct 90 ms 7928 KB Output is correct
81 Correct 105 ms 7928 KB Output is correct
82 Correct 90 ms 7928 KB Output is correct
83 Correct 117 ms 8056 KB Output is correct
84 Correct 102 ms 7928 KB Output is correct
85 Correct 109 ms 8032 KB Output is correct
86 Correct 106 ms 8056 KB Output is correct
87 Correct 109 ms 8056 KB Output is correct
88 Correct 111 ms 8312 KB Output is correct
89 Correct 114 ms 8184 KB Output is correct
90 Correct 123 ms 8056 KB Output is correct
91 Correct 117 ms 8184 KB Output is correct
92 Correct 123 ms 8184 KB Output is correct