답안 #138754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138754 2019-07-30T09:49:45 Z Boxworld Mecho (IOI09_mecho) C++14
96 / 100
229 ms 9340 KB
#include <bits/stdc++.h>
using namespace std;
const int N=1010;
typedef pair<int,int> pii;
char G[N][N];
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int T[N][N],d[N][N],vis[N][N];
int n,s,sx,sy;
int bfs(int time){
	if (time*s>=T[sx][sy])return 0;
	memset(vis,0,sizeof(vis));
	queue<pii> Q;
	vis[sx][sy]=1;
	Q.push(make_pair(sx*N+sy,time*s));
	while(!Q.empty()){
		int dis=Q.front().second;
		int x=Q.front().first/N;
		int y=Q.front().first%N;
		Q.pop();
		if (G[x][y]=='D')return 1;
		
		for (int k=0;k<4;k++){
			int X=x+dx[k],Y=y+dy[k];
			if (X<1||X>N||Y<1||Y>N)continue;
			if (G[X][Y]=='T')continue;
			if (dis+1>=T[X][Y]||vis[X][Y])continue;
			vis[X][Y]=1;
			Q.push(make_pair(X*N+Y,dis+1));
		}
	}
	return 0;
}
int main(){
	scanf("%d%d",&n,&s);
	for (int i=1;i<=n;i++)scanf("%s",G[i]+1);
	memset(T,-1,sizeof(T));
	queue<int> bq;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++){
		if (G[i][j]=='M')sx=i,sy=j;
		if (G[i][j]=='D')T[i][j]=n*n*s;
		if (G[i][j]=='H'){
			T[i][j]=0;
			bq.push(i*N+j);
		}
	}
	while(!bq.empty()){
		int x=bq.front()/N,y=bq.front()%N;
		bq.pop();
		for (int i=0;i<4;i++){
			int X=x+dx[i],Y=y+dy[i];
			if (x<1||x>n||y<1||y>n||T[X][Y]!=-1)continue;
			if (G[X][Y]=='T'||G[X][Y]=='D')continue;
			T[X][Y]=T[x][y]+s;
			bq.push(X*N+Y);
		}
	}
	int l=-1,r=n*n*2;
	while(l+1<r){
		int m=(l+r)/2;
		if (bfs(m))l=m;
		else r=m;
	}
	printf("%d\n",l);
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&s);
  ~~~~~^~~~~~~~~~~~~~
mecho.cpp:35:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=1;i<=n;i++)scanf("%s",G[i]+1);
                        ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 8312 KB Output is correct
2 Correct 9 ms 8312 KB Output is correct
3 Correct 9 ms 8312 KB Output is correct
4 Correct 9 ms 8312 KB Output is correct
5 Correct 9 ms 8312 KB Output is correct
6 Correct 9 ms 8312 KB Output is correct
7 Correct 115 ms 9336 KB Output is correct
8 Correct 9 ms 8312 KB Output is correct
9 Correct 9 ms 8312 KB Output is correct
10 Correct 9 ms 8312 KB Output is correct
11 Incorrect 9 ms 8312 KB Output isn't correct
12 Correct 9 ms 8312 KB Output is correct
13 Correct 10 ms 8312 KB Output is correct
14 Correct 10 ms 8312 KB Output is correct
15 Correct 10 ms 8312 KB Output is correct
16 Correct 10 ms 8416 KB Output is correct
17 Correct 12 ms 8312 KB Output is correct
18 Correct 12 ms 8312 KB Output is correct
19 Correct 12 ms 8312 KB Output is correct
20 Correct 9 ms 8312 KB Output is correct
21 Correct 11 ms 8436 KB Output is correct
22 Correct 12 ms 8312 KB Output is correct
23 Correct 10 ms 8316 KB Output is correct
24 Correct 11 ms 8440 KB Output is correct
25 Correct 11 ms 8312 KB Output is correct
26 Correct 11 ms 8440 KB Output is correct
27 Correct 10 ms 8312 KB Output is correct
28 Correct 11 ms 8440 KB Output is correct
29 Correct 11 ms 8440 KB Output is correct
30 Correct 11 ms 8440 KB Output is correct
31 Correct 12 ms 8312 KB Output is correct
32 Correct 11 ms 8440 KB Output is correct
33 Correct 13 ms 8824 KB Output is correct
34 Correct 16 ms 8824 KB Output is correct
35 Correct 31 ms 8696 KB Output is correct
36 Correct 14 ms 8824 KB Output is correct
37 Correct 15 ms 8824 KB Output is correct
38 Correct 37 ms 8824 KB Output is correct
39 Correct 15 ms 8824 KB Output is correct
40 Correct 15 ms 8952 KB Output is correct
41 Correct 46 ms 8952 KB Output is correct
42 Correct 16 ms 8952 KB Output is correct
43 Correct 16 ms 8952 KB Output is correct
44 Correct 57 ms 8952 KB Output is correct
45 Correct 17 ms 9052 KB Output is correct
46 Correct 16 ms 8824 KB Output is correct
47 Correct 64 ms 8824 KB Output is correct
48 Correct 18 ms 8952 KB Output is correct
49 Correct 18 ms 8952 KB Output is correct
50 Correct 78 ms 9080 KB Output is correct
51 Correct 19 ms 8952 KB Output is correct
52 Correct 19 ms 8956 KB Output is correct
53 Correct 107 ms 9004 KB Output is correct
54 Correct 20 ms 9080 KB Output is correct
55 Correct 20 ms 8952 KB Output is correct
56 Correct 113 ms 9080 KB Output is correct
57 Correct 22 ms 8980 KB Output is correct
58 Correct 22 ms 9080 KB Output is correct
59 Correct 136 ms 9104 KB Output is correct
60 Correct 22 ms 9052 KB Output is correct
61 Correct 23 ms 9080 KB Output is correct
62 Correct 152 ms 9180 KB Output is correct
63 Correct 115 ms 9080 KB Output is correct
64 Correct 229 ms 9080 KB Output is correct
65 Correct 182 ms 9080 KB Output is correct
66 Correct 166 ms 9080 KB Output is correct
67 Correct 139 ms 9236 KB Output is correct
68 Correct 65 ms 9208 KB Output is correct
69 Correct 63 ms 9080 KB Output is correct
70 Correct 44 ms 9080 KB Output is correct
71 Correct 55 ms 9080 KB Output is correct
72 Correct 42 ms 9080 KB Output is correct
73 Correct 39 ms 9208 KB Output is correct
74 Correct 66 ms 9208 KB Output is correct
75 Correct 85 ms 9208 KB Output is correct
76 Correct 71 ms 9336 KB Output is correct
77 Correct 73 ms 9208 KB Output is correct
78 Correct 93 ms 9336 KB Output is correct
79 Correct 56 ms 9208 KB Output is correct
80 Correct 77 ms 9208 KB Output is correct
81 Correct 81 ms 9208 KB Output is correct
82 Correct 72 ms 9208 KB Output is correct
83 Correct 104 ms 9260 KB Output is correct
84 Correct 81 ms 9208 KB Output is correct
85 Correct 93 ms 9208 KB Output is correct
86 Correct 87 ms 9292 KB Output is correct
87 Correct 88 ms 9208 KB Output is correct
88 Correct 122 ms 9212 KB Output is correct
89 Correct 104 ms 9336 KB Output is correct
90 Correct 99 ms 9208 KB Output is correct
91 Correct 126 ms 9228 KB Output is correct
92 Correct 105 ms 9340 KB Output is correct