답안 #958014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958014 2024-04-04T16:26:01 Z theehann Mecho (IOI09_mecho) C++17
3 / 100
156 ms 31824 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){
	vis[x][y] = true;
	int dist = (len + 1) / step;
	for(int i = 0;i < 4;++i){
		int u = dx[i] + x;
		int v = dy[i] + y;
 
		if(u == homex && v == homey){
			return true;
		}
 
		if(u < 1 || v < 1 || u > n || v > n) continue;
		if((a[u][v] == 'G') && !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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4564 KB Output isn't correct
2 Incorrect 3 ms 4700 KB Output isn't correct
3 Incorrect 2 ms 4564 KB Output isn't correct
4 Incorrect 2 ms 4700 KB Output isn't correct
5 Incorrect 2 ms 4700 KB Output isn't correct
6 Incorrect 1 ms 4700 KB Output isn't correct
7 Incorrect 25 ms 8284 KB Output isn't correct
8 Incorrect 2 ms 4700 KB Output isn't correct
9 Incorrect 2 ms 4696 KB Output isn't correct
10 Incorrect 1 ms 4700 KB Output isn't correct
11 Incorrect 1 ms 4700 KB Output isn't correct
12 Incorrect 1 ms 4700 KB Output isn't correct
13 Correct 2 ms 4700 KB Output is correct
14 Incorrect 2 ms 4700 KB Output isn't correct
15 Incorrect 1 ms 4700 KB Output isn't correct
16 Incorrect 2 ms 4700 KB Output isn't correct
17 Incorrect 1 ms 4560 KB Output isn't correct
18 Incorrect 2 ms 4556 KB Output isn't correct
19 Incorrect 2 ms 4696 KB Output isn't correct
20 Incorrect 2 ms 4556 KB Output isn't correct
21 Incorrect 1 ms 4696 KB Output isn't correct
22 Incorrect 2 ms 4700 KB Output isn't correct
23 Incorrect 2 ms 4700 KB Output isn't correct
24 Incorrect 2 ms 4700 KB Output isn't correct
25 Incorrect 2 ms 4868 KB Output isn't correct
26 Incorrect 2 ms 4696 KB Output isn't correct
27 Incorrect 2 ms 4700 KB Output isn't correct
28 Incorrect 2 ms 4696 KB Output isn't correct
29 Incorrect 2 ms 4568 KB Output isn't correct
30 Incorrect 2 ms 4700 KB Output isn't correct
31 Incorrect 2 ms 4700 KB Output isn't correct
32 Incorrect 2 ms 4696 KB Output isn't correct
33 Incorrect 5 ms 6748 KB Output isn't correct
34 Incorrect 4 ms 6724 KB Output isn't correct
35 Correct 19 ms 11356 KB Output is correct
36 Incorrect 4 ms 6748 KB Output isn't correct
37 Incorrect 5 ms 6748 KB Output isn't correct
38 Correct 29 ms 12796 KB Output is correct
39 Incorrect 7 ms 6744 KB Output isn't correct
40 Incorrect 5 ms 6748 KB Output isn't correct
41 Correct 38 ms 14512 KB Output is correct
42 Incorrect 9 ms 6956 KB Output isn't correct
43 Incorrect 7 ms 6988 KB Output isn't correct
44 Correct 52 ms 16600 KB Output is correct
45 Incorrect 7 ms 7004 KB Output isn't correct
46 Incorrect 6 ms 6948 KB Output isn't correct
47 Correct 67 ms 18592 KB Output is correct
48 Incorrect 9 ms 6876 KB Output isn't correct
49 Incorrect 8 ms 6944 KB Output isn't correct
50 Correct 100 ms 20884 KB Output is correct
51 Incorrect 9 ms 7004 KB Output isn't correct
52 Incorrect 10 ms 7004 KB Output isn't correct
53 Correct 79 ms 23324 KB Output is correct
54 Incorrect 16 ms 7080 KB Output isn't correct
55 Incorrect 12 ms 7424 KB Output isn't correct
56 Correct 106 ms 25992 KB Output is correct
57 Incorrect 12 ms 7036 KB Output isn't correct
58 Incorrect 12 ms 7120 KB Output isn't correct
59 Correct 156 ms 28752 KB Output is correct
60 Incorrect 13 ms 7052 KB Output isn't correct
61 Incorrect 16 ms 7024 KB Output isn't correct
62 Correct 145 ms 31824 KB Output is correct
63 Incorrect 62 ms 7252 KB Output isn't correct
64 Incorrect 105 ms 7240 KB Output isn't correct
65 Incorrect 90 ms 7472 KB Output isn't correct
66 Incorrect 75 ms 7424 KB Output isn't correct
67 Incorrect 69 ms 7276 KB Output isn't correct
68 Incorrect 32 ms 7296 KB Output isn't correct
69 Incorrect 29 ms 7320 KB Output isn't correct
70 Incorrect 27 ms 7456 KB Output isn't correct
71 Incorrect 26 ms 7532 KB Output isn't correct
72 Incorrect 36 ms 7248 KB Output isn't correct
73 Incorrect 67 ms 8016 KB Output isn't correct
74 Incorrect 64 ms 15112 KB Output isn't correct
75 Incorrect 66 ms 7920 KB Output isn't correct
76 Incorrect 45 ms 7712 KB Output isn't correct
77 Incorrect 82 ms 8272 KB Output isn't correct
78 Incorrect 27 ms 8016 KB Output isn't correct
79 Incorrect 40 ms 14160 KB Output isn't correct
80 Incorrect 35 ms 8016 KB Output isn't correct
81 Incorrect 28 ms 7772 KB Output isn't correct
82 Incorrect 39 ms 8268 KB Output isn't correct
83 Correct 27 ms 7804 KB Output is correct
84 Incorrect 48 ms 13996 KB Output isn't correct
85 Incorrect 51 ms 8152 KB Output isn't correct
86 Incorrect 59 ms 8160 KB Output isn't correct
87 Incorrect 58 ms 8756 KB Output isn't correct
88 Correct 40 ms 8120 KB Output is correct
89 Incorrect 50 ms 15172 KB Output isn't correct
90 Incorrect 26 ms 8788 KB Output isn't correct
91 Incorrect 49 ms 9568 KB Output isn't correct
92 Incorrect 41 ms 8532 KB Output isn't correct