답안 #522413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522413 2022-02-04T22:57:24 Z AndresTL Mecho (IOI09_mecho) C++11
100 / 100
216 ms 6212 KB
// Problem: 10599. IOI 2009 - Mecho
// Contest: omegaUp
// URL: https://omegaup.com/arena/problem/IOI-2009-Mecho/?fromLogin=
// Memory Limit: 64 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<utility>
#include<queue>
#include<string>
#define fi first
#define se second
using namespace std;
int n,s;
char mapa[802][802];
int colmena[802][802];
int mecho[802][802];
int mov[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
bool abeja(int i, int j){
	if(i<0 || i>n || j<0 || j>n) return 0;
	if(colmena[i][j]!=-1) return 0;
	if(mapa[i][j]=='T' || mapa[i][j]=='D') return 0;
	return 1;
}
void BFScolmena(){
	queue<pair<int,int>> q;
	pair<int,int> dad, son;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(mapa[i][j]=='H'){
				q.push(make_pair(i,j));
				colmena[i][j]=0;
			}	
		}
	}
	while(!q.empty()){
		dad=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			son=make_pair(dad.fi+mov[i][0],dad.se+mov[i][1]);
			if(!abeja(son.first,son.second))continue;
			colmena[son.fi][son.se]=colmena[dad.fi][dad.se]+1;
			q.push(son);
		}
	}
}
int i1,i2,j1,j2;
bool paso(int i,int j,int time){
	if(i<0 || i>n || j<0 || j>n) return 0;
	if(mecho[i][j]!=-1) return 0;
	if(mapa[i][j]=='T') return 0;
	if(mapa[i][j]=='D') return 1;
	if(time>=colmena[i][j]) return 0;
	return 1;
}
bool BFSmecho(int t){
	queue<pair<int,int>> q;
	pair<int,int>dad,son;
	int time;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			mecho[i][j]=-1;
		}
	}
	mecho[i1][j1]=0;
	if(t>=colmena[i1][j1]) return 0;
	q.push(make_pair(i1,j1));
	while(!q.empty()){
		dad=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			son=make_pair(dad.fi+mov[i][0],dad.se+mov[i][1]);
			time=t+(mecho[dad.fi][dad.se]+1)/s;
			if(!paso(son.fi,son.se,time)) continue;
			mecho[son.fi][son.se]=mecho[dad.fi][dad.se]+1;
			q.push(son);
		}
	}
	return mecho[i2][j2]!=-1;
}
int main(){
	cin>>n>>s;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			colmena[i][j]=-1;
			cin>>mapa[i][j];
			if(mapa[i][j]=='M'){i1=i;j1=j;}
			if(mapa[i][j]=='D'){i2=i;j2=j;}			
		}
	}
	BFScolmena();
	int l=0,r=n*n,m;
	int res=-1;
	while(l<=r){
		m =(l+r)/2;
		if(BFSmecho(m)){
			res=m;
			l=m+1;
		}else{
			r=m-1;
		}
	}
	cout<<res<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 103 ms 6052 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 1 ms 716 KB Output is correct
26 Correct 1 ms 716 KB Output is correct
27 Correct 1 ms 716 KB Output is correct
28 Correct 1 ms 716 KB Output is correct
29 Correct 1 ms 716 KB Output is correct
30 Correct 1 ms 716 KB Output is correct
31 Correct 1 ms 844 KB Output is correct
32 Correct 1 ms 844 KB Output is correct
33 Correct 11 ms 2740 KB Output is correct
34 Correct 12 ms 2672 KB Output is correct
35 Correct 26 ms 2780 KB Output is correct
36 Correct 14 ms 3100 KB Output is correct
37 Correct 15 ms 3132 KB Output is correct
38 Correct 32 ms 3020 KB Output is correct
39 Correct 16 ms 3488 KB Output is correct
40 Correct 18 ms 3372 KB Output is correct
41 Correct 44 ms 3396 KB Output is correct
42 Correct 20 ms 3788 KB Output is correct
43 Correct 21 ms 3788 KB Output is correct
44 Correct 54 ms 3860 KB Output is correct
45 Correct 24 ms 4112 KB Output is correct
46 Correct 25 ms 4172 KB Output is correct
47 Correct 59 ms 4120 KB Output is correct
48 Correct 32 ms 4528 KB Output is correct
49 Correct 37 ms 4436 KB Output is correct
50 Correct 74 ms 4428 KB Output is correct
51 Correct 32 ms 4860 KB Output is correct
52 Correct 38 ms 4956 KB Output is correct
53 Correct 94 ms 4896 KB Output is correct
54 Correct 38 ms 5208 KB Output is correct
55 Correct 41 ms 5160 KB Output is correct
56 Correct 154 ms 5240 KB Output is correct
57 Correct 43 ms 5488 KB Output is correct
58 Correct 46 ms 5532 KB Output is correct
59 Correct 123 ms 5660 KB Output is correct
60 Correct 49 ms 5932 KB Output is correct
61 Correct 53 ms 5892 KB Output is correct
62 Correct 154 ms 5936 KB Output is correct
63 Correct 123 ms 5856 KB Output is correct
64 Correct 216 ms 5956 KB Output is correct
65 Correct 186 ms 5928 KB Output is correct
66 Correct 144 ms 5940 KB Output is correct
67 Correct 134 ms 5828 KB Output is correct
68 Correct 72 ms 5932 KB Output is correct
69 Correct 73 ms 5884 KB Output is correct
70 Correct 71 ms 5956 KB Output is correct
71 Correct 80 ms 5900 KB Output is correct
72 Correct 59 ms 5884 KB Output is correct
73 Correct 62 ms 6168 KB Output is correct
74 Correct 80 ms 6212 KB Output is correct
75 Correct 97 ms 6128 KB Output is correct
76 Correct 105 ms 6212 KB Output is correct
77 Correct 88 ms 6112 KB Output is correct
78 Correct 100 ms 6192 KB Output is correct
79 Correct 74 ms 6140 KB Output is correct
80 Correct 89 ms 6108 KB Output is correct
81 Correct 92 ms 6160 KB Output is correct
82 Correct 84 ms 6084 KB Output is correct
83 Correct 102 ms 6052 KB Output is correct
84 Correct 96 ms 6208 KB Output is correct
85 Correct 98 ms 6064 KB Output is correct
86 Correct 106 ms 6080 KB Output is correct
87 Correct 126 ms 6128 KB Output is correct
88 Correct 103 ms 6100 KB Output is correct
89 Correct 97 ms 6084 KB Output is correct
90 Correct 108 ms 6096 KB Output is correct
91 Correct 132 ms 6076 KB Output is correct
92 Correct 112 ms 6096 KB Output is correct