Submission #366943

# Submission time Handle Problem Language Result Execution time Memory
366943 2021-02-15T19:01:02 Z kostia244 Mecho (IOI09_mecho) C++17
4 / 100
76 ms 6508 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
const int maxn = 808, C = 1;
using ll = long long;
int n, s;
char c[maxn][maxn];
array<int, 2> st, en;
int bdi[maxn][maxn];
vector<array<int, 2>> d {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};
bool good(int x, int y) {
	return !(min(x, y) < 1 || max(x, y) > n) && c[x][y] != 'T'; 
}
void bees() {
	memset(bdi, -1, sizeof bdi);
	queue<array<int, 2>> q;
	auto add = [&](int x, int y, int d) {
		if(bdi[x][y] >= 0) return;
		if(c[x][y] == 'D') return;
		bdi[x][y] = d;
		q.push({x, y});
	};
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(c[i][j] == 'H') add(i, j, 0);
	while(!q.empty()) {
		auto [x, y] = q.front(); q.pop();
		for(auto [dx, dy] : d) {
			int tx = x+dx, ty = y+dy;
			if(good(tx, ty)) add(tx, ty, bdi[x][y]+1);
		}
	}
}
int dist[maxn][maxn];
bool check(int ti) {
	queue<array<int, 2>> q;
	memset(dist, -1, sizeof dist);
	auto add = [&](int x, int y, int d) {
		if(dist[x][y] >= 0) return;
		if(ti + (d/s) >= bdi[x][y]) return;
		//cout << x << " " << y << " " << d << " | " << bdi[x][y] << endl;
		dist[x][y] = d;
		q.push({x, y});
	};
	add(st[0], st[1], 0);
	while(!q.empty()) {
		auto [x, y] = q.front(); q.pop();
		for(auto [dx, dy] : d) {
			int tx = x+dx, ty = y+dy;
			if(good(tx, ty)) add(tx, ty, dist[x][y]+1);
		}
	}
	return dist[en[0]][en[1]] >= 0;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> s;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) {
			cin >> c[i][j];
			if(c[i][j] == 'M') st = {i, j};
			if(c[i][j] == 'D') en = {i, j};
		}
	bees();
	
	if(!check(0)) return cout << -1, 0;
	int ans = 0;
	for(int i = 1<<20; i>>=1;) ans += i*check(ans+i);
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5632 KB Output isn't correct
2 Incorrect 3 ms 5484 KB Output isn't correct
3 Incorrect 3 ms 5484 KB Output isn't correct
4 Incorrect 3 ms 5484 KB Output isn't correct
5 Incorrect 3 ms 5484 KB Output isn't correct
6 Incorrect 3 ms 5484 KB Output isn't correct
7 Incorrect 53 ms 6252 KB Output isn't correct
8 Correct 3 ms 5484 KB Output is correct
9 Incorrect 3 ms 5484 KB Output isn't correct
10 Incorrect 3 ms 5484 KB Output isn't correct
11 Incorrect 3 ms 5484 KB Output isn't correct
12 Incorrect 3 ms 5484 KB Output isn't correct
13 Incorrect 3 ms 5484 KB Output isn't correct
14 Correct 4 ms 5484 KB Output is correct
15 Incorrect 3 ms 5484 KB Output isn't correct
16 Incorrect 4 ms 5484 KB Output isn't correct
17 Incorrect 3 ms 5484 KB Output isn't correct
18 Incorrect 3 ms 5484 KB Output isn't correct
19 Incorrect 3 ms 5484 KB Output isn't correct
20 Incorrect 3 ms 5484 KB Output isn't correct
21 Incorrect 3 ms 5484 KB Output isn't correct
22 Incorrect 4 ms 5484 KB Output isn't correct
23 Incorrect 4 ms 5484 KB Output isn't correct
24 Incorrect 3 ms 5484 KB Output isn't correct
25 Incorrect 4 ms 5484 KB Output isn't correct
26 Incorrect 3 ms 5484 KB Output isn't correct
27 Incorrect 4 ms 5484 KB Output isn't correct
28 Incorrect 3 ms 5484 KB Output isn't correct
29 Incorrect 3 ms 5484 KB Output isn't correct
30 Incorrect 3 ms 5484 KB Output isn't correct
31 Incorrect 3 ms 5484 KB Output isn't correct
32 Incorrect 3 ms 5484 KB Output isn't correct
33 Incorrect 10 ms 5888 KB Output isn't correct
34 Incorrect 9 ms 5740 KB Output isn't correct
35 Incorrect 12 ms 5740 KB Output isn't correct
36 Incorrect 11 ms 5740 KB Output isn't correct
37 Incorrect 10 ms 5740 KB Output isn't correct
38 Incorrect 14 ms 5740 KB Output isn't correct
39 Incorrect 11 ms 5868 KB Output isn't correct
40 Incorrect 12 ms 5868 KB Output isn't correct
41 Incorrect 17 ms 5868 KB Output isn't correct
42 Incorrect 17 ms 5868 KB Output isn't correct
43 Incorrect 14 ms 5868 KB Output isn't correct
44 Incorrect 21 ms 5868 KB Output isn't correct
45 Incorrect 17 ms 5868 KB Output isn't correct
46 Incorrect 17 ms 5868 KB Output isn't correct
47 Incorrect 24 ms 5868 KB Output isn't correct
48 Incorrect 17 ms 5868 KB Output isn't correct
49 Incorrect 22 ms 5996 KB Output isn't correct
50 Incorrect 34 ms 5996 KB Output isn't correct
51 Incorrect 23 ms 5996 KB Output isn't correct
52 Incorrect 22 ms 5996 KB Output isn't correct
53 Incorrect 35 ms 5996 KB Output isn't correct
54 Incorrect 22 ms 5996 KB Output isn't correct
55 Incorrect 25 ms 5996 KB Output isn't correct
56 Incorrect 38 ms 5996 KB Output isn't correct
57 Incorrect 24 ms 5996 KB Output isn't correct
58 Incorrect 30 ms 5992 KB Output isn't correct
59 Incorrect 43 ms 5996 KB Output isn't correct
60 Incorrect 33 ms 6144 KB Output isn't correct
61 Incorrect 31 ms 6124 KB Output isn't correct
62 Incorrect 47 ms 6124 KB Output isn't correct
63 Incorrect 48 ms 6124 KB Output isn't correct
64 Incorrect 54 ms 6124 KB Output isn't correct
65 Incorrect 52 ms 6124 KB Output isn't correct
66 Incorrect 49 ms 6124 KB Output isn't correct
67 Correct 43 ms 6124 KB Output is correct
68 Incorrect 41 ms 6124 KB Output isn't correct
69 Incorrect 43 ms 6124 KB Output isn't correct
70 Incorrect 38 ms 6252 KB Output isn't correct
71 Incorrect 38 ms 6124 KB Output isn't correct
72 Incorrect 42 ms 6124 KB Output isn't correct
73 Incorrect 48 ms 6380 KB Output isn't correct
74 Incorrect 76 ms 6380 KB Output isn't correct
75 Incorrect 48 ms 6424 KB Output isn't correct
76 Incorrect 47 ms 6312 KB Output isn't correct
77 Incorrect 50 ms 6380 KB Output isn't correct
78 Correct 49 ms 6380 KB Output is correct
79 Incorrect 63 ms 6392 KB Output isn't correct
80 Incorrect 63 ms 6380 KB Output isn't correct
81 Incorrect 51 ms 6508 KB Output isn't correct
82 Incorrect 50 ms 6380 KB Output isn't correct
83 Incorrect 48 ms 6252 KB Output isn't correct
84 Incorrect 75 ms 6252 KB Output isn't correct
85 Incorrect 51 ms 6288 KB Output isn't correct
86 Incorrect 51 ms 6252 KB Output isn't correct
87 Incorrect 50 ms 6252 KB Output isn't correct
88 Incorrect 52 ms 6252 KB Output isn't correct
89 Incorrect 64 ms 6252 KB Output isn't correct
90 Incorrect 60 ms 6192 KB Output isn't correct
91 Incorrect 57 ms 6252 KB Output isn't correct
92 Incorrect 52 ms 6252 KB Output isn't correct