답안 #958013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958013 2024-04-04T16:25:05 Z theehann Mecho (IOI09_mecho) C++17
0 / 100
6 ms 5476 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
	file
	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;
}

Compilation message

mecho.cpp: In function 'int32_t main()':
mecho.cpp:8:21: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | #define file freopen(NAME".INP","r",stdin); freopen(NAME".OUT","w",stdout);
      |              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:42:2: note: in expansion of macro 'file'
   42 |  file
      |  ^~~~
mecho.cpp:8:52: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 | #define file freopen(NAME".INP","r",stdin); freopen(NAME".OUT","w",stdout);
      |                                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:42:2: note: in expansion of macro 'file'
   42 |  file
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 5208 KB Execution killed with signal 8
2 Runtime error 4 ms 5212 KB Execution killed with signal 8
3 Runtime error 4 ms 5212 KB Execution killed with signal 8
4 Runtime error 4 ms 5212 KB Execution killed with signal 8
5 Runtime error 6 ms 5208 KB Execution killed with signal 8
6 Runtime error 4 ms 5196 KB Execution killed with signal 8
7 Runtime error 4 ms 5212 KB Execution killed with signal 8
8 Runtime error 4 ms 5212 KB Execution killed with signal 8
9 Runtime error 4 ms 5212 KB Execution killed with signal 8
10 Runtime error 4 ms 5208 KB Execution killed with signal 8
11 Runtime error 5 ms 5212 KB Execution killed with signal 8
12 Runtime error 4 ms 5212 KB Execution killed with signal 8
13 Runtime error 5 ms 5212 KB Execution killed with signal 8
14 Runtime error 5 ms 5212 KB Execution killed with signal 8
15 Runtime error 4 ms 5208 KB Execution killed with signal 8
16 Runtime error 5 ms 5208 KB Execution killed with signal 8
17 Runtime error 5 ms 5212 KB Execution killed with signal 8
18 Runtime error 4 ms 5208 KB Execution killed with signal 8
19 Runtime error 4 ms 5136 KB Execution killed with signal 8
20 Runtime error 5 ms 5212 KB Execution killed with signal 8
21 Runtime error 4 ms 5164 KB Execution killed with signal 8
22 Runtime error 4 ms 5212 KB Execution killed with signal 8
23 Runtime error 6 ms 5208 KB Execution killed with signal 8
24 Runtime error 4 ms 5208 KB Execution killed with signal 8
25 Runtime error 6 ms 5212 KB Execution killed with signal 8
26 Runtime error 4 ms 5212 KB Execution killed with signal 8
27 Runtime error 5 ms 5200 KB Execution killed with signal 8
28 Runtime error 5 ms 5132 KB Execution killed with signal 8
29 Runtime error 4 ms 5212 KB Execution killed with signal 8
30 Runtime error 4 ms 5212 KB Execution killed with signal 8
31 Runtime error 4 ms 5212 KB Execution killed with signal 8
32 Runtime error 5 ms 5212 KB Execution killed with signal 8
33 Runtime error 4 ms 5188 KB Execution killed with signal 8
34 Runtime error 4 ms 5212 KB Execution killed with signal 8
35 Runtime error 4 ms 5212 KB Execution killed with signal 8
36 Runtime error 4 ms 5464 KB Execution killed with signal 8
37 Runtime error 4 ms 5212 KB Execution killed with signal 8
38 Runtime error 4 ms 5212 KB Execution killed with signal 8
39 Runtime error 4 ms 5212 KB Execution killed with signal 8
40 Runtime error 4 ms 5212 KB Execution killed with signal 8
41 Runtime error 4 ms 5128 KB Execution killed with signal 8
42 Runtime error 4 ms 5212 KB Execution killed with signal 8
43 Runtime error 4 ms 5212 KB Execution killed with signal 8
44 Runtime error 4 ms 5212 KB Execution killed with signal 8
45 Runtime error 5 ms 5212 KB Execution killed with signal 8
46 Runtime error 4 ms 5212 KB Execution killed with signal 8
47 Runtime error 4 ms 5212 KB Execution killed with signal 8
48 Runtime error 4 ms 5212 KB Execution killed with signal 8
49 Runtime error 4 ms 5212 KB Execution killed with signal 8
50 Runtime error 4 ms 5208 KB Execution killed with signal 8
51 Runtime error 4 ms 5208 KB Execution killed with signal 8
52 Runtime error 5 ms 5212 KB Execution killed with signal 8
53 Runtime error 6 ms 5212 KB Execution killed with signal 8
54 Runtime error 4 ms 5212 KB Execution killed with signal 8
55 Runtime error 6 ms 5212 KB Execution killed with signal 8
56 Runtime error 4 ms 5212 KB Execution killed with signal 8
57 Runtime error 4 ms 5212 KB Execution killed with signal 8
58 Runtime error 4 ms 5212 KB Execution killed with signal 8
59 Runtime error 5 ms 5212 KB Execution killed with signal 8
60 Runtime error 5 ms 5212 KB Execution killed with signal 8
61 Runtime error 4 ms 5212 KB Execution killed with signal 8
62 Runtime error 4 ms 5212 KB Execution killed with signal 8
63 Runtime error 4 ms 5208 KB Execution killed with signal 8
64 Runtime error 4 ms 5212 KB Execution killed with signal 8
65 Runtime error 4 ms 5212 KB Execution killed with signal 8
66 Runtime error 4 ms 5212 KB Execution killed with signal 8
67 Runtime error 5 ms 5208 KB Execution killed with signal 8
68 Runtime error 4 ms 5212 KB Execution killed with signal 8
69 Runtime error 4 ms 5212 KB Execution killed with signal 8
70 Runtime error 4 ms 5212 KB Execution killed with signal 8
71 Runtime error 4 ms 5212 KB Execution killed with signal 8
72 Runtime error 4 ms 5372 KB Execution killed with signal 8
73 Runtime error 4 ms 5212 KB Execution killed with signal 8
74 Runtime error 4 ms 5212 KB Execution killed with signal 8
75 Runtime error 4 ms 5212 KB Execution killed with signal 8
76 Runtime error 4 ms 5260 KB Execution killed with signal 8
77 Runtime error 4 ms 5212 KB Execution killed with signal 8
78 Runtime error 4 ms 5212 KB Execution killed with signal 8
79 Runtime error 4 ms 5212 KB Execution killed with signal 8
80 Runtime error 4 ms 5212 KB Execution killed with signal 8
81 Runtime error 4 ms 5212 KB Execution killed with signal 8
82 Runtime error 4 ms 5212 KB Execution killed with signal 8
83 Runtime error 6 ms 5208 KB Execution killed with signal 8
84 Runtime error 5 ms 5464 KB Execution killed with signal 8
85 Runtime error 6 ms 5212 KB Execution killed with signal 8
86 Runtime error 4 ms 5212 KB Execution killed with signal 8
87 Runtime error 4 ms 5208 KB Execution killed with signal 8
88 Runtime error 5 ms 5476 KB Execution killed with signal 8
89 Runtime error 4 ms 5208 KB Execution killed with signal 8
90 Runtime error 5 ms 5212 KB Execution killed with signal 8
91 Runtime error 4 ms 5212 KB Execution killed with signal 8
92 Runtime error 4 ms 5212 KB Execution killed with signal 8