Submission #958003

# Submission time Handle Problem Language Result Execution time Memory
958003 2024-04-04T16:02:57 Z theehann Mecho (IOI09_mecho) C++17
14 / 100
144 ms 36396 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define ft first
#define se second
#define NAME "A"
#define file freopen(NAME".INP","r",stdin); freopen(NAME".OUT","w",stdout);
#define sdf ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1e9 + 7;
const int N = 800 + 5, INF = 1e15;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
char a[N][N];
int dis[N][N];
bool f = false, vis[N][N] = {false};
int n, step, homex, homey, mx, my;

bool dfs(int len, int x, int y){
	if(x == homex && y == homey){
		return true;
	}
	vis[x][y] = true;
	int dist = ceil(double(len + 1) / double(step));
	for(int i = 0;i < 4;++i){
		int u = dx[i] + x;
		int v = dy[i] + y;
		if(u < 1 || v < 1 || u > n || v > n) continue;
		// cout << vis[u][v] << ' ' << dist << ' ' << dis[u][v] << "  " << u << ' ' << v << "\n";
		if((a[u][v] == 'G' || a[u][v] == 'D')&& !vis[u][v] && ((len + 1 % step == 0) ? (dist < dis[u][v]) : (dist <= dis[u][v]))){
			if(dfs(len + 1, u, v)){
				return true;
			}
		}
	}
	return false;
}

int32_t main(){
	sdf

	cin >> n >> step;
	queue<pair<int, int>> q;
	for(int i = 1;i <= n;++i){
		for(int j = 1;j <= n;++j){
			cin >> a[i][j];
			dis[i][j] = INF;
			if(a[i][j] == 'H'){
				q.push({i, j});
				dis[i][j] = 0;
			}
			else if(a[i][j] == 'D'){
				homex = i; homey = j;
			}
			else if(a[i][j] == 'M'){
				mx = i; my = j;
			}
		}
	}

	while(!q.empty()){
		const auto [x, y] = q.front(); q.pop();

		for(int i  = 0;i < 4;++i){
			int u = x + dx[i];
			int v = y + dy[i];
			if(u < 1 || v < 1 || u > n || v > n) continue;
			if(dis[u][v] == INF && a[u][v] == 'G'){
				dis[u][v] = dis[x][y] + 1;
				q.push({u, v});
			}
		}
	}

	int l = 1, r = INF;
	int ans =0;
	while(l <= r){
		int mid = (l + r) / 2;
		memset(vis, false, sizeof(vis));
		if(dfs(mid * step, mx, my)){
			l = mid + 1;
			ans = mid;
		}
		else{
			r = mid - 1;
		}
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4700 KB Output isn't correct
2 Incorrect 2 ms 4700 KB Output isn't correct
3 Incorrect 1 ms 4700 KB Output isn't correct
4 Incorrect 1 ms 4700 KB Output isn't correct
5 Correct 1 ms 4556 KB Output is correct
6 Incorrect 1 ms 4700 KB Output isn't correct
7 Incorrect 23 ms 8416 KB Output isn't correct
8 Incorrect 1 ms 4696 KB Output isn't correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Incorrect 1 ms 4700 KB Output isn't correct
13 Correct 1 ms 4700 KB Output is correct
14 Incorrect 1 ms 4700 KB Output isn't correct
15 Incorrect 1 ms 4700 KB Output isn't correct
16 Correct 1 ms 4700 KB Output is correct
17 Incorrect 1 ms 4700 KB Output isn't correct
18 Correct 4 ms 4700 KB Output is correct
19 Incorrect 1 ms 4700 KB Output isn't correct
20 Correct 1 ms 4696 KB Output is correct
21 Incorrect 2 ms 4700 KB Output isn't correct
22 Correct 1 ms 4740 KB Output is correct
23 Incorrect 2 ms 4700 KB Output isn't correct
24 Correct 2 ms 4700 KB Output is correct
25 Incorrect 2 ms 4700 KB Output isn't correct
26 Correct 1 ms 4700 KB Output is correct
27 Incorrect 1 ms 4700 KB Output isn't correct
28 Correct 1 ms 4700 KB Output is correct
29 Incorrect 2 ms 4700 KB Output isn't correct
30 Correct 1 ms 4700 KB Output is correct
31 Incorrect 1 ms 4700 KB Output isn't correct
32 Correct 2 ms 4700 KB Output is correct
33 Incorrect 4 ms 6748 KB Output isn't correct
34 Correct 4 ms 6744 KB Output is correct
35 Incorrect 18 ms 12376 KB Output isn't correct
36 Incorrect 4 ms 6748 KB Output isn't correct
37 Correct 4 ms 6748 KB Output is correct
38 Incorrect 23 ms 14168 KB Output isn't correct
39 Incorrect 5 ms 6748 KB Output isn't correct
40 Correct 6 ms 6748 KB Output is correct
41 Incorrect 31 ms 15964 KB Output isn't correct
42 Incorrect 6 ms 6748 KB Output isn't correct
43 Correct 6 ms 6748 KB Output is correct
44 Incorrect 42 ms 18336 KB Output isn't correct
45 Incorrect 7 ms 6748 KB Output isn't correct
46 Correct 6 ms 6612 KB Output is correct
47 Incorrect 57 ms 20668 KB Output isn't correct
48 Incorrect 8 ms 6744 KB Output isn't correct
49 Correct 8 ms 6748 KB Output is correct
50 Incorrect 71 ms 23468 KB Output isn't correct
51 Incorrect 9 ms 6748 KB Output isn't correct
52 Correct 8 ms 6748 KB Output is correct
53 Incorrect 93 ms 26376 KB Output isn't correct
54 Incorrect 10 ms 6748 KB Output isn't correct
55 Correct 9 ms 6748 KB Output is correct
56 Incorrect 106 ms 29300 KB Output isn't correct
57 Incorrect 11 ms 6748 KB Output isn't correct
58 Correct 11 ms 6744 KB Output is correct
59 Incorrect 143 ms 32932 KB Output isn't correct
60 Incorrect 12 ms 6744 KB Output isn't correct
61 Correct 11 ms 6748 KB Output is correct
62 Incorrect 144 ms 36396 KB Output isn't correct
63 Correct 55 ms 6992 KB Output is correct
64 Correct 87 ms 6992 KB Output is correct
65 Correct 84 ms 7092 KB Output is correct
66 Incorrect 66 ms 6992 KB Output isn't correct
67 Incorrect 76 ms 6996 KB Output isn't correct
68 Correct 30 ms 7000 KB Output is correct
69 Correct 26 ms 7004 KB Output is correct
70 Correct 25 ms 6944 KB Output is correct
71 Correct 24 ms 7004 KB Output is correct
72 Incorrect 26 ms 6688 KB Output isn't correct
73 Incorrect 43 ms 7692 KB Output isn't correct
74 Incorrect 45 ms 16000 KB Output isn't correct
75 Incorrect 52 ms 7760 KB Output isn't correct
76 Incorrect 32 ms 7516 KB Output isn't correct
77 Incorrect 56 ms 7976 KB Output isn't correct
78 Incorrect 23 ms 7772 KB Output isn't correct
79 Incorrect 36 ms 15192 KB Output isn't correct
80 Incorrect 32 ms 7764 KB Output isn't correct
81 Incorrect 26 ms 7516 KB Output isn't correct
82 Incorrect 37 ms 7896 KB Output isn't correct
83 Correct 22 ms 7512 KB Output is correct
84 Incorrect 43 ms 15056 KB Output isn't correct
85 Incorrect 37 ms 8024 KB Output isn't correct
86 Incorrect 39 ms 7516 KB Output isn't correct
87 Incorrect 39 ms 8836 KB Output isn't correct
88 Correct 38 ms 8028 KB Output is correct
89 Incorrect 45 ms 16260 KB Output isn't correct
90 Incorrect 26 ms 8540 KB Output isn't correct
91 Incorrect 41 ms 9764 KB Output isn't correct
92 Incorrect 32 ms 8028 KB Output isn't correct