Submission #531012

# Submission time Handle Problem Language Result Execution time Memory
531012 2022-02-27T10:31:34 Z Alan Mecho (IOI09_mecho) C++17
100 / 100
146 ms 4444 KB
#include <bits/stdc++.h>
#define I using
#define WA using namespace std;
#define on using ll = long long;
#define Test(x) int AlanIQ = -(x);
#define should ld =
#define quit long double;
#define OI int
#define forever main
#define Alan cin.tie(0);
#define fai(x) ios::ios_base::sync_with_stdio(!x);
#define Sharky return
#define orz 0;

WA on Test (109)

struct bee {
	int r, c, t;
};

int grid[801][801], startr, startc, endr, endc;
bool vi[801][801];

bool ok (int n, int s, int diff) {
	if (grid[startr][startc] - diff <= 0) return false;
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) vi[i][j] = false;
	queue<bee> q;
	q.push({startr, startc, 0});
	vi[startr][startc] = true;
	while (!q.empty()) {
		int r = q.front().r;
		int c = q.front().c;
		int t = q.front().t;
		int tt = (t+2) / s + !!((t+2) % s);
		q.pop();
		if (c < n-1 && tt < grid[r][c+1] - diff + 1 && grid[r][c+1] != 1e9 && !vi[r][c+1]) {q.push({r, c+1, t+1}); vi[r][c+1] = true;}
		if (c > 0 && tt < grid[r][c-1] - diff + 1&& grid[r][c-1] != 1e9 && !vi[r][c-1]) {q.push({r, c-1, t+1}); vi[r][c-1] = true;}
		if (r < n-1 && tt < grid[r+1][c] - diff + 1 && grid[r+1][c] != 1e9 && !vi[r+1][c]) {q.push({r+1, c, t+1}); vi[r+1][c] = true;}
		if (r > 0 && tt < grid[r-1][c] - diff + 1 && grid[r-1][c] != 1e9 && !vi[r-1][c]) {q.push({r-1, c, t+1}); vi[r-1][c] = true;}
	}
	return vi[endr][endc];
}

I should quit OI forever () {
	Alan fai (true)
	int n, s;
	char ch;
	cin >> n >> s;
	queue<bee> q;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> ch;
			if (ch == 'T') grid[i][j] = 1e9;
			else if (ch == 'G') grid[i][j] = 0;
			else if (ch == 'M') {
				startr = i;
				startc = j;
				grid[i][j] = 0;
			} else if (ch == 'D') {
				endr = i;
				endc = j;
				grid[i][j] = 1e8;
			} else if (ch == 'H') {
				q.push({i, j, 0});
				grid[i][j] = 1e9;
			}
		}
	}
	while (!q.empty()) {
		int r = q.front().r;
		int c = q.front().c;
		int t = q.front().t;
		q.pop();
		if (c < n-1 && !grid[r][c+1]) {q.push({r, c+1, t+1}); grid[r][c+1] = t+1;}
		if (c > 0 && !grid[r][c-1]) {q.push({r, c-1, t+1}); grid[r][c-1] = t+1;}
		if (r < n-1 && !grid[r+1][c]) {q.push({r+1, c, t+1}); grid[r+1][c] = t+1;}
		if (r > 0 && !grid[r-1][c]) {q.push({r-1, c, t+1}); grid[r-1][c] = t+1;}
	}
	
	int l = -1, r = n*n/2;
	while (l < r) {
		int mid = l + (r - l + 1) / 2;
		if (ok(n, s, mid)) l = mid;
		else r = mid-1;
	}

	cout << l << "\n";

	Sharky orz
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 62 ms 4160 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 448 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 588 KB Output is correct
31 Correct 1 ms 580 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 6 ms 1740 KB Output is correct
34 Correct 6 ms 1740 KB Output is correct
35 Correct 17 ms 1816 KB Output is correct
36 Correct 6 ms 1984 KB Output is correct
37 Correct 5 ms 1992 KB Output is correct
38 Correct 18 ms 2056 KB Output is correct
39 Correct 8 ms 2240 KB Output is correct
40 Correct 6 ms 2268 KB Output is correct
41 Correct 27 ms 2272 KB Output is correct
42 Correct 10 ms 2508 KB Output is correct
43 Correct 8 ms 2388 KB Output is correct
44 Correct 30 ms 2508 KB Output is correct
45 Correct 8 ms 2716 KB Output is correct
46 Correct 9 ms 2720 KB Output is correct
47 Correct 33 ms 2760 KB Output is correct
48 Correct 10 ms 3020 KB Output is correct
49 Correct 10 ms 2880 KB Output is correct
50 Correct 41 ms 3028 KB Output is correct
51 Correct 16 ms 3144 KB Output is correct
52 Correct 14 ms 3276 KB Output is correct
53 Correct 52 ms 3276 KB Output is correct
54 Correct 13 ms 3496 KB Output is correct
55 Correct 14 ms 3540 KB Output is correct
56 Correct 69 ms 3532 KB Output is correct
57 Correct 14 ms 3784 KB Output is correct
58 Correct 16 ms 3788 KB Output is correct
59 Correct 72 ms 3804 KB Output is correct
60 Correct 16 ms 4040 KB Output is correct
61 Correct 17 ms 4084 KB Output is correct
62 Correct 78 ms 3972 KB Output is correct
63 Correct 78 ms 4064 KB Output is correct
64 Correct 146 ms 4072 KB Output is correct
65 Correct 127 ms 4072 KB Output is correct
66 Correct 88 ms 4036 KB Output is correct
67 Correct 87 ms 4036 KB Output is correct
68 Correct 36 ms 4068 KB Output is correct
69 Correct 36 ms 4040 KB Output is correct
70 Correct 31 ms 4048 KB Output is correct
71 Correct 42 ms 4168 KB Output is correct
72 Correct 26 ms 4020 KB Output is correct
73 Correct 25 ms 4408 KB Output is correct
74 Correct 39 ms 4424 KB Output is correct
75 Correct 48 ms 4444 KB Output is correct
76 Correct 52 ms 4420 KB Output is correct
77 Correct 44 ms 4384 KB Output is correct
78 Correct 67 ms 4440 KB Output is correct
79 Correct 35 ms 4432 KB Output is correct
80 Correct 49 ms 4436 KB Output is correct
81 Correct 49 ms 4436 KB Output is correct
82 Correct 46 ms 4324 KB Output is correct
83 Correct 54 ms 4292 KB Output is correct
84 Correct 47 ms 4360 KB Output is correct
85 Correct 55 ms 4376 KB Output is correct
86 Correct 50 ms 4320 KB Output is correct
87 Correct 50 ms 4296 KB Output is correct
88 Correct 67 ms 4304 KB Output is correct
89 Correct 53 ms 4276 KB Output is correct
90 Correct 53 ms 4208 KB Output is correct
91 Correct 56 ms 4416 KB Output is correct
92 Correct 73 ms 4304 KB Output is correct