Submission #366939

# Submission time Handle Problem Language Result Execution time Memory
366939 2021-02-15T18:57:00 Z kostia244 Mecho (IOI09_mecho) C++17
4 / 100
82 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) && bdi[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<<10; i>>=1;) ans += i*check(ans+i);
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5484 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 4 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 47 ms 6380 KB Output isn't correct
8 Correct 4 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 6 ms 5484 KB Output isn't correct
16 Incorrect 4 ms 5484 KB Output isn't correct
17 Incorrect 5 ms 5484 KB Output isn't correct
18 Incorrect 4 ms 5484 KB Output isn't correct
19 Incorrect 3 ms 5484 KB Output isn't correct
20 Incorrect 4 ms 5484 KB Output isn't correct
21 Incorrect 4 ms 5484 KB Output isn't correct
22 Incorrect 4 ms 5484 KB Output isn't correct
23 Incorrect 3 ms 5484 KB Output isn't correct
24 Incorrect 3 ms 5484 KB Output isn't correct
25 Incorrect 3 ms 5484 KB Output isn't correct
26 Incorrect 3 ms 5484 KB Output isn't correct
27 Incorrect 3 ms 5484 KB Output isn't correct
28 Incorrect 4 ms 5484 KB Output isn't correct
29 Incorrect 3 ms 5484 KB Output isn't correct
30 Incorrect 4 ms 5484 KB Output isn't correct
31 Incorrect 3 ms 5484 KB Output isn't correct
32 Incorrect 4 ms 5484 KB Output isn't correct
33 Incorrect 16 ms 5868 KB Output isn't correct
34 Incorrect 17 ms 5868 KB Output isn't correct
35 Incorrect 14 ms 5868 KB Output isn't correct
36 Incorrect 15 ms 5868 KB Output isn't correct
37 Incorrect 18 ms 5868 KB Output isn't correct
38 Incorrect 17 ms 5868 KB Output isn't correct
39 Incorrect 18 ms 5996 KB Output isn't correct
40 Incorrect 21 ms 5964 KB Output isn't correct
41 Incorrect 22 ms 5996 KB Output isn't correct
42 Incorrect 23 ms 5996 KB Output isn't correct
43 Incorrect 25 ms 5996 KB Output isn't correct
44 Incorrect 32 ms 5996 KB Output isn't correct
45 Incorrect 25 ms 5996 KB Output isn't correct
46 Incorrect 33 ms 5964 KB Output isn't correct
47 Incorrect 30 ms 5996 KB Output isn't correct
48 Incorrect 28 ms 6124 KB Output isn't correct
49 Incorrect 35 ms 6124 KB Output isn't correct
50 Incorrect 36 ms 6124 KB Output isn't correct
51 Incorrect 34 ms 6124 KB Output isn't correct
52 Incorrect 41 ms 6124 KB Output isn't correct
53 Incorrect 44 ms 6124 KB Output isn't correct
54 Incorrect 38 ms 6124 KB Output isn't correct
55 Incorrect 45 ms 6124 KB Output isn't correct
56 Incorrect 49 ms 6124 KB Output isn't correct
57 Incorrect 43 ms 6124 KB Output isn't correct
58 Incorrect 53 ms 6124 KB Output isn't correct
59 Incorrect 63 ms 6244 KB Output isn't correct
60 Incorrect 51 ms 6260 KB Output isn't correct
61 Incorrect 60 ms 6252 KB Output isn't correct
62 Incorrect 63 ms 6252 KB Output isn't correct
63 Incorrect 52 ms 6252 KB Output isn't correct
64 Incorrect 77 ms 6252 KB Output isn't correct
65 Incorrect 68 ms 6252 KB Output isn't correct
66 Incorrect 67 ms 6252 KB Output isn't correct
67 Correct 53 ms 6252 KB Output is correct
68 Incorrect 55 ms 6380 KB Output isn't correct
69 Incorrect 82 ms 6380 KB Output isn't correct
70 Incorrect 47 ms 6380 KB Output isn't correct
71 Incorrect 45 ms 6380 KB Output isn't correct
72 Incorrect 64 ms 6380 KB Output isn't correct
73 Incorrect 39 ms 6508 KB Output isn't correct
74 Incorrect 48 ms 6508 KB Output isn't correct
75 Incorrect 48 ms 6508 KB Output isn't correct
76 Incorrect 51 ms 6508 KB Output isn't correct
77 Incorrect 54 ms 6508 KB Output isn't correct
78 Correct 48 ms 6508 KB Output is correct
79 Incorrect 48 ms 6508 KB Output isn't correct
80 Incorrect 47 ms 6508 KB Output isn't correct
81 Incorrect 47 ms 6508 KB Output isn't correct
82 Incorrect 48 ms 6508 KB Output isn't correct
83 Incorrect 51 ms 6380 KB Output isn't correct
84 Incorrect 47 ms 6412 KB Output isn't correct
85 Incorrect 47 ms 6380 KB Output isn't correct
86 Incorrect 48 ms 6380 KB Output isn't correct
87 Incorrect 51 ms 6380 KB Output isn't correct
88 Incorrect 56 ms 6380 KB Output isn't correct
89 Incorrect 60 ms 6380 KB Output isn't correct
90 Incorrect 48 ms 6336 KB Output isn't correct
91 Incorrect 46 ms 6380 KB Output isn't correct
92 Incorrect 49 ms 6380 KB Output isn't correct