Submission #611819

# Submission time Handle Problem Language Result Execution time Memory
611819 2022-07-29T07:54:21 Z Belgutei Mecho (IOI09_mecho) C++17
20 / 100
1000 ms 13940 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n,m;
int b[805][806];
queue<pair<int,int> > q;
int stx, sty;
int cnt[805][805];
int tmp[805][805];
bool check = 0;
char ch[805][805];

int main() {
	IOS
	cin >> n >> m;
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= n; j ++) {
			cin >> ch[i][j];
			if(ch[i][j] == 'H') {
				b[i][j] = 1;
				q.push({i,j});
			}
			if(ch[i][j] == 'M') {
				stx = i;
				sty = j;
			}
		}
	}
	while(q.size() > 0) {
		int x = q.front().ff;
		int y = q.front().ss;
		q.pop();
		if(x > 1 && b[x - 1][y] == 0 && ch[x - 1][y] != 'T' && ch[x - 1][y] != 'D') {
			q.push({x - 1, y});
			b[x - 1][y] = b[x][y] + 1;
		}
		if(x < n && b[x + 1][y] == 0 && ch[x + 1][y] != 'T' && ch[x + 1][y] != 'D') {
			q.push({x + 1, y});
			b[x + 1][y] = b[x][y] + 1;
		}
		if(y > 1 && b[x][y - 1] == 0 && ch[x][y - 1] != 'T' && ch[x][y - 1] != 'D') {
			q.push({x, y - 1});
			b[x][y - 1] = b[x][y] + 1;
		}
		if(y < n && b[x][y + 1] == 0 && ch[x][y + 1] != 'T' && ch[x][y + 1] != 'D') {
			q.push({x, y + 1});
			b[x][y + 1] = b[x][y] + 1;
		}		
	}
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= n; j ++) {
			if(b[i][j] == 0) b[i][j] = 1e9;
			else b[i][j] --;
		}
	} 

	int l = 0;
	int r = n * n;
	while(l < r) {
		int mid = (l + r + 1) / 2;
		memset(cnt, -1, sizeof(cnt));
		while(q.size() > 0) q.pop();
		//
		q.push({stx, sty});
		if(mid >= b[stx][sty]) {
			r = mid - 1;
			continue;
		}
		cnt[stx][sty] = mid;
		bool ok = 0;
		//
		while(q.size() > 0) {
			int x = q.front().ff;
			int y = q.front().ss;
			q.pop();
			if(ch[x][y] == 'D') {
				ok = 1;
				break;
			}
			for(int i = 1; i <= m; i ++) {
				for(int j = 0; j <= i; j ++) {
					int xx = x - j;
					int yy = y - (i - j);
					if(cnt[xx][yy] == -1 && cnt[x][y] + 1 < b[xx][yy] && ch[xx][yy] != 'T') {
						q.push({xx,yy});
						cnt[xx][yy] = cnt[x][y] + 1;
					} 
				}
				for(int j = 0; j <= i; j ++) {
					int xx = x - (i - j);
					int yy = y + j;
					if(cnt[xx][yy] == -1 && cnt[x][y] + 1 < b[xx][yy] && ch[xx][yy] != 'T') {
						q.push({xx,yy});
						cnt[xx][yy] = cnt[x][y] + 1;
					} 
				}
				for(int j = 0; j <= i; j ++) {
					int xx = x + j;
					int yy = y + (i - j);
					if(cnt[xx][yy] == -1 && cnt[x][y] + 1 < b[xx][yy] && ch[xx][yy] != 'T') {
						q.push({xx,yy});
						cnt[xx][yy] = cnt[x][y] + 1;
					} 
				}
				for(int j = 0; j <= i; j ++) {
					int xx = x + (i - j);
					int yy = x - j;
					if(cnt[xx][yy] == -1 && cnt[x][y] + 1 < b[xx][yy] && ch[xx][yy] != 'T') {
						q.push({xx,yy});
						cnt[xx][yy] = cnt[x][y] + 1;
					} 
				}
			}
		}	
		if(ok == 1) {
			check = 1;
			l = mid;
		}
		else r = mid - 1;

	}
	if(check == 1){
		cout << l;
	} 
	else cout << -1;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2900 KB Output is correct
2 Correct 1 ms 2900 KB Output is correct
3 Correct 2 ms 2900 KB Output is correct
4 Correct 1 ms 2900 KB Output is correct
5 Incorrect 2 ms 2900 KB Output isn't correct
6 Incorrect 3 ms 2900 KB Output isn't correct
7 Execution timed out 1082 ms 6688 KB Time limit exceeded
8 Incorrect 2 ms 2900 KB Output isn't correct
9 Correct 2 ms 2896 KB Output is correct
10 Incorrect 2 ms 2900 KB Output isn't correct
11 Incorrect 3 ms 2900 KB Output isn't correct
12 Correct 3 ms 3028 KB Output is correct
13 Incorrect 2 ms 3028 KB Output isn't correct
14 Incorrect 4 ms 3028 KB Output isn't correct
15 Correct 2 ms 2900 KB Output is correct
16 Incorrect 3 ms 2900 KB Output isn't correct
17 Correct 2 ms 2900 KB Output is correct
18 Incorrect 4 ms 2920 KB Output isn't correct
19 Correct 3 ms 2900 KB Output is correct
20 Incorrect 3 ms 2900 KB Output isn't correct
21 Correct 2 ms 3028 KB Output is correct
22 Incorrect 4 ms 3028 KB Output isn't correct
23 Correct 2 ms 3028 KB Output is correct
24 Incorrect 7 ms 3092 KB Output isn't correct
25 Correct 3 ms 3028 KB Output is correct
26 Incorrect 12 ms 3028 KB Output isn't correct
27 Correct 4 ms 3028 KB Output is correct
28 Incorrect 16 ms 3028 KB Output isn't correct
29 Correct 3 ms 3156 KB Output is correct
30 Incorrect 15 ms 3160 KB Output isn't correct
31 Correct 3 ms 3164 KB Output is correct
32 Incorrect 21 ms 3196 KB Output isn't correct
33 Correct 7 ms 4324 KB Output is correct
34 Execution timed out 1074 ms 4584 KB Time limit exceeded
35 Execution timed out 1079 ms 4880 KB Time limit exceeded
36 Correct 7 ms 4564 KB Output is correct
37 Execution timed out 1073 ms 4868 KB Time limit exceeded
38 Execution timed out 1081 ms 5188 KB Time limit exceeded
39 Correct 8 ms 4820 KB Output is correct
40 Execution timed out 1085 ms 5288 KB Time limit exceeded
41 Execution timed out 1077 ms 5520 KB Time limit exceeded
42 Correct 10 ms 5068 KB Output is correct
43 Execution timed out 1086 ms 5576 KB Time limit exceeded
44 Execution timed out 1089 ms 5804 KB Time limit exceeded
45 Correct 10 ms 5332 KB Output is correct
46 Execution timed out 1073 ms 6060 KB Time limit exceeded
47 Execution timed out 1079 ms 6224 KB Time limit exceeded
48 Correct 11 ms 5588 KB Output is correct
49 Execution timed out 1077 ms 6240 KB Time limit exceeded
50 Execution timed out 1067 ms 6776 KB Time limit exceeded
51 Correct 16 ms 5836 KB Output is correct
52 Execution timed out 1072 ms 6476 KB Time limit exceeded
53 Execution timed out 1064 ms 7352 KB Time limit exceeded
54 Correct 15 ms 6100 KB Output is correct
55 Execution timed out 1092 ms 6904 KB Time limit exceeded
56 Execution timed out 1078 ms 7656 KB Time limit exceeded
57 Correct 18 ms 6332 KB Output is correct
58 Execution timed out 1093 ms 7084 KB Time limit exceeded
59 Execution timed out 1067 ms 8180 KB Time limit exceeded
60 Correct 18 ms 6500 KB Output is correct
61 Execution timed out 1085 ms 7492 KB Time limit exceeded
62 Execution timed out 1081 ms 8864 KB Time limit exceeded
63 Incorrect 25 ms 6488 KB Output isn't correct
64 Runtime error 36 ms 13940 KB Execution killed with signal 11
65 Incorrect 28 ms 6516 KB Output isn't correct
66 Incorrect 30 ms 6476 KB Output isn't correct
67 Incorrect 38 ms 6552 KB Output isn't correct
68 Execution timed out 1087 ms 6688 KB Time limit exceeded
69 Execution timed out 1079 ms 6920 KB Time limit exceeded
70 Incorrect 632 ms 6560 KB Output isn't correct
71 Incorrect 329 ms 6552 KB Output isn't correct
72 Execution timed out 1075 ms 6688 KB Time limit exceeded
73 Correct 134 ms 6928 KB Output is correct
74 Execution timed out 1085 ms 6936 KB Time limit exceeded
75 Incorrect 668 ms 6804 KB Output isn't correct
76 Incorrect 379 ms 6804 KB Output isn't correct
77 Execution timed out 1082 ms 6796 KB Time limit exceeded
78 Execution timed out 1084 ms 6776 KB Time limit exceeded
79 Execution timed out 1077 ms 6744 KB Time limit exceeded
80 Incorrect 76 ms 6780 KB Output isn't correct
81 Incorrect 41 ms 6732 KB Output isn't correct
82 Incorrect 615 ms 6772 KB Output isn't correct
83 Incorrect 75 ms 6708 KB Output isn't correct
84 Execution timed out 1083 ms 6772 KB Time limit exceeded
85 Incorrect 387 ms 6744 KB Output isn't correct
86 Incorrect 55 ms 6624 KB Output isn't correct
87 Incorrect 331 ms 6740 KB Output isn't correct
88 Incorrect 119 ms 6888 KB Output isn't correct
89 Execution timed out 1069 ms 7988 KB Time limit exceeded
90 Incorrect 600 ms 6684 KB Output isn't correct
91 Execution timed out 1089 ms 6604 KB Time limit exceeded
92 Incorrect 274 ms 6692 KB Output isn't correct