답안 #1092615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092615 2024-09-24T15:07:05 Z 4QT0R Mecho (IOI09_mecho) C++17
84 / 100
117 ms 7020 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>

char tab[802][802];
int xcor[4]={0,1,0,-1};
int ycor[4]={1,0,-1,0};

int dist[802][802];
int oo=1e9;
int n,s;

void prep(){
	queue<pii> q;
	for (int i = 1; i<=n; i++){
		for (int j = 1; j<=n; j++){
			dist[i][j]=oo;
			if (tab[i][j]=='H'){
				q.push({i,j});
				dist[i][j]=0;
			}
		}
	}
	while(q.size()){
		auto [x,y]=q.front();
		q.pop();
		for (int i = 0; i<4; i++){
			int u=x+xcor[i];
			int v=y+ycor[i];
			if (tab[u][v]=='G' && dist[u][v]>dist[x][y]+1){
				dist[u][v]=dist[x][y]+1;
				q.push({u,v});
			}
		}
	}
}

int vis[802][802];
int iter=0;
pii st,nd;

bool bfs(int waiting){
	queue<pair<pii,int>> q;
	q.push({st,0});
	while(q.size()){
		auto [pol,d]=q.front();
		if (pol==nd)return true;
		q.pop();
		for (int i = 0; i<4; i++){
			int u=pol.first+xcor[i];
			int v=pol.second+ycor[i];
			if ((tab[u][v]=='G'||tab[u][v]=='D') && vis[u][v]!=iter && (dist[u][v]>waiting+(d+1)/s)){
				vis[u][v]=iter;
				q.push({{u,v},d+1});
			}
		}
	}
	return false;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> s;
	for (int i = 1; i<=n; i++){
		for (int j = 1; j<=n; j++){
			cin >> tab[i][j];
			if (tab[i][j]=='M')st={i,j};
			if (tab[i][j]=='D')nd={i,j};
		}
	}
	prep();
	int l=-1,p=1e9,md;
	while(l<p){
		md=(l+p+1)/2;
		iter++;
		if (bfs(md))l=md;
		else p=md-1;
	}
	cout << l << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 53 ms 5716 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 600 KB Output isn't correct
13 Incorrect 1 ms 604 KB Output isn't correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 0 ms 612 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 3 ms 1896 KB Output is correct
34 Correct 3 ms 1896 KB Output is correct
35 Correct 12 ms 3088 KB Output is correct
36 Correct 3 ms 2152 KB Output is correct
37 Correct 4 ms 2152 KB Output is correct
38 Correct 16 ms 3484 KB Output is correct
39 Correct 5 ms 2408 KB Output is correct
40 Correct 4 ms 2408 KB Output is correct
41 Correct 21 ms 3688 KB Output is correct
42 Correct 5 ms 2664 KB Output is correct
43 Correct 5 ms 2664 KB Output is correct
44 Correct 32 ms 4456 KB Output is correct
45 Correct 6 ms 2904 KB Output is correct
46 Correct 6 ms 2972 KB Output is correct
47 Correct 32 ms 4444 KB Output is correct
48 Correct 6 ms 3032 KB Output is correct
49 Correct 7 ms 3164 KB Output is correct
50 Correct 55 ms 5080 KB Output is correct
51 Correct 8 ms 3416 KB Output is correct
52 Correct 8 ms 3376 KB Output is correct
53 Correct 46 ms 5484 KB Output is correct
54 Correct 8 ms 3676 KB Output is correct
55 Correct 8 ms 3728 KB Output is correct
56 Correct 60 ms 5720 KB Output is correct
57 Correct 16 ms 3928 KB Output is correct
58 Correct 9 ms 3932 KB Output is correct
59 Correct 59 ms 6284 KB Output is correct
60 Correct 18 ms 4184 KB Output is correct
61 Correct 11 ms 4188 KB Output is correct
62 Correct 66 ms 6492 KB Output is correct
63 Correct 72 ms 6736 KB Output is correct
64 Correct 117 ms 6548 KB Output is correct
65 Correct 117 ms 6736 KB Output is correct
66 Correct 108 ms 6736 KB Output is correct
67 Correct 98 ms 6736 KB Output is correct
68 Correct 34 ms 6736 KB Output is correct
69 Correct 33 ms 6748 KB Output is correct
70 Correct 34 ms 6632 KB Output is correct
71 Correct 24 ms 6740 KB Output is correct
72 Incorrect 24 ms 4716 KB Output isn't correct
73 Incorrect 42 ms 7020 KB Output isn't correct
74 Correct 40 ms 7004 KB Output is correct
75 Correct 47 ms 6992 KB Output is correct
76 Correct 50 ms 7016 KB Output is correct
77 Correct 53 ms 6864 KB Output is correct
78 Correct 45 ms 5688 KB Output is correct
79 Correct 35 ms 5468 KB Output is correct
80 Correct 38 ms 5456 KB Output is correct
81 Correct 56 ms 5444 KB Output is correct
82 Correct 61 ms 5392 KB Output is correct
83 Correct 80 ms 5636 KB Output is correct
84 Correct 48 ms 5456 KB Output is correct
85 Correct 43 ms 5456 KB Output is correct
86 Correct 54 ms 5724 KB Output is correct
87 Correct 48 ms 5456 KB Output is correct
88 Correct 48 ms 5748 KB Output is correct
89 Correct 51 ms 5716 KB Output is correct
90 Correct 55 ms 5716 KB Output is correct
91 Correct 49 ms 5468 KB Output is correct
92 Correct 60 ms 5768 KB Output is correct