Submission #599779

# Submission time Handle Problem Language Result Execution time Memory
599779 2022-07-19T21:37:06 Z alexz1205 Mecho (IOI09_mecho) C++14
2 / 100
1000 ms 4424 KB
#include <iostream>
#include <vector>
using namespace std;

int n, s, dist[800][800];
pair<int, int> beg, home;
vector<pair<int, int> > hives;

void setup(){
	cin >> n >> s;
	for (int x = 0; x < n; x ++){
		for (int y = 0; y < n; y ++){
			dist[x][y] = -1;
			char c;
			cin >> c;
			switch (c){
				case 'T':
					dist[x][y] = 0;
					break;
				case 'G':
					break;
				case 'M':
					beg = make_pair(x, y);
					break;
				case 'D':
					home = make_pair(x, y);
					break;
				case 'H':
					dist[x][y] = 0;
					hives.push_back(make_pair(x, y));
					break;
			}
		}
	}
}

void calc(){
	vector<pair<int, int> > que = hives;
	while (!que.empty()){
		int i = que.front().first, j = que.front().second;
		que.erase(que.begin());
		if (i != 0){
			if (dist[i-1][j] == -1){
				dist[i-1][j] = dist[i][j] + s;
				que.push_back(make_pair(i-1, j));
			}
		}
		if (i != n-1){
			if (dist[i+1][j] == -1){
				dist[i+1][j] = dist[i][j] + s;
				que.push_back(make_pair(i+1, j));
			}
		}
		if (j != 0){
			if (dist[i][j-1] == -1){
				dist[i][j-1] = dist[i][j] + s;
				que.push_back(make_pair(i, j-1));
			}
		}
		if (j != n-1){
			if (dist[i][j+1] == -1){
				dist[i][j+1] = dist[i][j] + s;
				que.push_back(make_pair(i, j+1));
			}
		}
	}
}

bool pos(int mid){
	vector<pair<pair<int, int>, int> > que;
	que.push_back(make_pair(beg, mid));
//	cout << beg.first << " " << beg.second << endl;
	while (!que.empty()){
		int i = que.front().first.first, j = que.front().first.second;
		int d = que.front().second;
//		cout << i << " " << j << " " << d << endl;
		que.erase(que.begin());
		if (i == home.first && j == home.second){
			return true;
		}
		if (i != 0){
			if (dist[i-1][j] > d){
				que.push_back(make_pair(make_pair(i-1, j), d+1));
			}
		}
		if (i != n-1){
			if (dist[i+1][j] > d){
				que.push_back(make_pair(make_pair(i+1, j), d+1));
			}
		}
		if (j != 0){
			if (dist[i][j-1] > d){
				que.push_back(make_pair(make_pair(i, j-1), d+1));
			}
		}
		if (j != n-1){
			if (dist[i][j+1] > d){
				que.push_back(make_pair(make_pair(i, j+1), d+1));
			}
		}
	}
	return false;
}

int main() {
	setup();
	calc();
	int lo = 0, hi = dist[beg.first][beg.second]/s+1;
	while (lo <= hi){
		int mid = lo + (hi-lo+1)/2;
		if (pos(s*mid)){
			lo = mid+1;
		}else {
			hi = mid-1;
		}
	}
	cout << lo-1 << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Execution timed out 1076 ms 1228 KB Time limit exceeded
7 Execution timed out 1081 ms 3668 KB Time limit exceeded
8 Incorrect 2 ms 340 KB Output isn't correct
9 Execution timed out 1086 ms 1976 KB Time limit exceeded
10 Execution timed out 1078 ms 1972 KB Time limit exceeded
11 Execution timed out 1081 ms 1224 KB Time limit exceeded
12 Incorrect 1 ms 468 KB Output isn't correct
13 Execution timed out 1081 ms 2112 KB Time limit exceeded
14 Execution timed out 1077 ms 2216 KB Time limit exceeded
15 Incorrect 1 ms 340 KB Output isn't correct
16 Execution timed out 1069 ms 1352 KB Time limit exceeded
17 Incorrect 1 ms 308 KB Output isn't correct
18 Execution timed out 1087 ms 1212 KB Time limit exceeded
19 Incorrect 0 ms 340 KB Output isn't correct
20 Execution timed out 1089 ms 1304 KB Time limit exceeded
21 Incorrect 1 ms 340 KB Output isn't correct
22 Execution timed out 1048 ms 1232 KB Time limit exceeded
23 Incorrect 1 ms 436 KB Output isn't correct
24 Execution timed out 1088 ms 1296 KB Time limit exceeded
25 Incorrect 1 ms 468 KB Output isn't correct
26 Execution timed out 1062 ms 1484 KB Time limit exceeded
27 Incorrect 1 ms 468 KB Output isn't correct
28 Execution timed out 1077 ms 1520 KB Time limit exceeded
29 Incorrect 1 ms 468 KB Output isn't correct
30 Execution timed out 1080 ms 1572 KB Time limit exceeded
31 Incorrect 2 ms 468 KB Output isn't correct
32 Execution timed out 1083 ms 1492 KB Time limit exceeded
33 Incorrect 9 ms 1492 KB Output isn't correct
34 Execution timed out 1089 ms 2428 KB Time limit exceeded
35 Execution timed out 1085 ms 2524 KB Time limit exceeded
36 Incorrect 10 ms 1620 KB Output isn't correct
37 Execution timed out 1075 ms 2616 KB Time limit exceeded
38 Execution timed out 1075 ms 2708 KB Time limit exceeded
39 Incorrect 14 ms 2004 KB Output isn't correct
40 Execution timed out 1068 ms 2760 KB Time limit exceeded
41 Execution timed out 1083 ms 2796 KB Time limit exceeded
42 Incorrect 17 ms 2004 KB Output isn't correct
43 Execution timed out 1092 ms 2992 KB Time limit exceeded
44 Execution timed out 1084 ms 3052 KB Time limit exceeded
45 Incorrect 19 ms 2248 KB Output isn't correct
46 Execution timed out 1083 ms 3192 KB Time limit exceeded
47 Execution timed out 1087 ms 3304 KB Time limit exceeded
48 Incorrect 23 ms 2508 KB Output isn't correct
49 Execution timed out 1079 ms 3508 KB Time limit exceeded
50 Execution timed out 1082 ms 3444 KB Time limit exceeded
51 Incorrect 27 ms 2636 KB Output isn't correct
52 Execution timed out 1078 ms 3704 KB Time limit exceeded
53 Execution timed out 1088 ms 3708 KB Time limit exceeded
54 Incorrect 30 ms 2884 KB Output isn't correct
55 Execution timed out 1093 ms 3792 KB Time limit exceeded
56 Execution timed out 1089 ms 3820 KB Time limit exceeded
57 Incorrect 35 ms 3128 KB Output isn't correct
58 Execution timed out 1089 ms 4004 KB Time limit exceeded
59 Execution timed out 1090 ms 4196 KB Time limit exceeded
60 Incorrect 40 ms 3404 KB Output isn't correct
61 Execution timed out 1090 ms 4260 KB Time limit exceeded
62 Execution timed out 1063 ms 4312 KB Time limit exceeded
63 Execution timed out 1089 ms 4328 KB Time limit exceeded
64 Execution timed out 1065 ms 4296 KB Time limit exceeded
65 Execution timed out 1091 ms 4312 KB Time limit exceeded
66 Execution timed out 1094 ms 4316 KB Time limit exceeded
67 Execution timed out 1048 ms 4236 KB Time limit exceeded
68 Execution timed out 1090 ms 4404 KB Time limit exceeded
69 Execution timed out 1089 ms 4244 KB Time limit exceeded
70 Execution timed out 1094 ms 4304 KB Time limit exceeded
71 Execution timed out 1043 ms 4116 KB Time limit exceeded
72 Execution timed out 1096 ms 4424 KB Time limit exceeded
73 Execution timed out 1058 ms 3932 KB Time limit exceeded
74 Execution timed out 1092 ms 4040 KB Time limit exceeded
75 Execution timed out 1085 ms 3912 KB Time limit exceeded
76 Execution timed out 1086 ms 3960 KB Time limit exceeded
77 Execution timed out 1084 ms 3916 KB Time limit exceeded
78 Execution timed out 1086 ms 3904 KB Time limit exceeded
79 Execution timed out 1052 ms 3904 KB Time limit exceeded
80 Execution timed out 1091 ms 3860 KB Time limit exceeded
81 Execution timed out 1081 ms 3920 KB Time limit exceeded
82 Execution timed out 1044 ms 4116 KB Time limit exceeded
83 Execution timed out 1092 ms 3948 KB Time limit exceeded
84 Execution timed out 1087 ms 3884 KB Time limit exceeded
85 Execution timed out 1079 ms 3840 KB Time limit exceeded
86 Execution timed out 1087 ms 3888 KB Time limit exceeded
87 Execution timed out 1088 ms 3888 KB Time limit exceeded
88 Execution timed out 1084 ms 3824 KB Time limit exceeded
89 Execution timed out 1085 ms 3756 KB Time limit exceeded
90 Execution timed out 1088 ms 3824 KB Time limit exceeded
91 Execution timed out 1088 ms 3924 KB Time limit exceeded
92 Execution timed out 1082 ms 3852 KB Time limit exceeded