Submission #138749

# Submission time Handle Problem Language Result Execution time Memory
138749 2019-07-30T09:42:34 Z Boxworld Mecho (IOI09_mecho) C++14
56 / 100
1000 ms 6968 KB
#include <bits/stdc++.h>
using namespace std;
const int N=810;
typedef pair<int,int> pii;
char G[N][N];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
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));
//	printf("X=%d Y=%d dis=%d\n",sx,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));
	//		printf("X=%d Y=%d dis=%d\n",X,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;
//	}
	for (int i=T[sx][sy]/s-1;i>=0;i--)
	if (bfs(i)){
		printf("%d\n",i);
		return 0;
	}
	printf("%d\n",l);
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:60:11: warning: unused variable 'r' [-Wunused-variable]
  int l=-1,r=n*n*2;
           ^
mecho.cpp:36: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:37: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);
                        ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5496 KB Output is correct
2 Correct 7 ms 5484 KB Output is correct
3 Correct 6 ms 5496 KB Output is correct
4 Correct 7 ms 5496 KB Output is correct
5 Correct 6 ms 5496 KB Output is correct
6 Correct 8 ms 5496 KB Output is correct
7 Execution timed out 1076 ms 6804 KB Time limit exceeded
8 Correct 7 ms 5496 KB Output is correct
9 Correct 8 ms 5496 KB Output is correct
10 Correct 7 ms 5496 KB Output is correct
11 Incorrect 7 ms 5496 KB Output isn't correct
12 Correct 6 ms 5496 KB Output is correct
13 Correct 8 ms 5496 KB Output is correct
14 Correct 11 ms 5496 KB Output is correct
15 Correct 6 ms 5496 KB Output is correct
16 Correct 6 ms 5496 KB Output is correct
17 Correct 7 ms 5496 KB Output is correct
18 Correct 6 ms 5496 KB Output is correct
19 Correct 7 ms 5496 KB Output is correct
20 Correct 6 ms 5496 KB Output is correct
21 Correct 7 ms 5516 KB Output is correct
22 Correct 6 ms 5496 KB Output is correct
23 Correct 7 ms 5496 KB Output is correct
24 Correct 6 ms 5496 KB Output is correct
25 Correct 6 ms 5496 KB Output is correct
26 Correct 8 ms 5496 KB Output is correct
27 Correct 8 ms 5496 KB Output is correct
28 Correct 7 ms 5496 KB Output is correct
29 Correct 7 ms 5496 KB Output is correct
30 Correct 6 ms 5496 KB Output is correct
31 Correct 7 ms 5496 KB Output is correct
32 Correct 6 ms 5496 KB Output is correct
33 Correct 9 ms 5888 KB Output is correct
34 Correct 9 ms 5880 KB Output is correct
35 Correct 367 ms 6008 KB Output is correct
36 Correct 9 ms 5880 KB Output is correct
37 Correct 9 ms 6008 KB Output is correct
38 Correct 542 ms 6008 KB Output is correct
39 Correct 10 ms 6008 KB Output is correct
40 Correct 10 ms 6008 KB Output is correct
41 Correct 865 ms 6076 KB Output is correct
42 Correct 11 ms 6264 KB Output is correct
43 Correct 11 ms 6140 KB Output is correct
44 Execution timed out 1060 ms 6100 KB Time limit exceeded
45 Correct 12 ms 6136 KB Output is correct
46 Correct 12 ms 6136 KB Output is correct
47 Execution timed out 1061 ms 6268 KB Time limit exceeded
48 Correct 13 ms 6268 KB Output is correct
49 Correct 15 ms 6264 KB Output is correct
50 Execution timed out 1072 ms 6264 KB Time limit exceeded
51 Correct 14 ms 6392 KB Output is correct
52 Correct 16 ms 6392 KB Output is correct
53 Execution timed out 1067 ms 6392 KB Time limit exceeded
54 Correct 15 ms 6524 KB Output is correct
55 Correct 16 ms 6520 KB Output is correct
56 Execution timed out 1075 ms 6520 KB Time limit exceeded
57 Correct 16 ms 6648 KB Output is correct
58 Correct 16 ms 6648 KB Output is correct
59 Execution timed out 1063 ms 6660 KB Time limit exceeded
60 Correct 17 ms 6648 KB Output is correct
61 Correct 21 ms 6648 KB Output is correct
62 Execution timed out 1069 ms 6876 KB Time limit exceeded
63 Execution timed out 1080 ms 6776 KB Time limit exceeded
64 Execution timed out 1062 ms 6776 KB Time limit exceeded
65 Execution timed out 1078 ms 6776 KB Time limit exceeded
66 Execution timed out 1065 ms 6648 KB Time limit exceeded
67 Execution timed out 1066 ms 6648 KB Time limit exceeded
68 Correct 170 ms 6776 KB Output is correct
69 Correct 82 ms 6780 KB Output is correct
70 Correct 82 ms 6780 KB Output is correct
71 Correct 85 ms 6780 KB Output is correct
72 Correct 31 ms 6776 KB Output is correct
73 Correct 38 ms 6896 KB Output is correct
74 Correct 379 ms 6900 KB Output is correct
75 Correct 765 ms 6904 KB Output is correct
76 Correct 693 ms 6908 KB Output is correct
77 Correct 662 ms 6904 KB Output is correct
78 Execution timed out 1075 ms 6904 KB Time limit exceeded
79 Correct 197 ms 6916 KB Output is correct
80 Correct 422 ms 6896 KB Output is correct
81 Correct 972 ms 6904 KB Output is correct
82 Correct 506 ms 6908 KB Output is correct
83 Execution timed out 1075 ms 6776 KB Time limit exceeded
84 Correct 713 ms 6904 KB Output is correct
85 Correct 403 ms 6780 KB Output is correct
86 Execution timed out 1058 ms 6776 KB Time limit exceeded
87 Correct 981 ms 6968 KB Output is correct
88 Execution timed out 1090 ms 6776 KB Time limit exceeded
89 Correct 931 ms 6904 KB Output is correct
90 Execution timed out 1082 ms 6776 KB Time limit exceeded
91 Execution timed out 1086 ms 6776 KB Time limit exceeded
92 Execution timed out 1084 ms 6776 KB Time limit exceeded