Submission #545000

# Submission time Handle Problem Language Result Execution time Memory
545000 2022-04-03T10:08:11 Z MilosMilutinovic Mecho (IOI09_mecho) C++14
88 / 100
152 ms 6924 KB
#include<bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<typename T> bool chkmin(T&x,T y){return x>y?x=y,1:0;}
template<typename T> bool chkmax(T&x,T y){return x<y?x=y,1:0;}

int n,s,sx,sy,ex,ey,dist[805][805],dis[805][805];
char base[805][805];
const int dir[4][2]={0,1,0,-1,1,0,-1,0};

void bfs(){
	memset(dist,-1,sizeof dist);
	queue<pii> que;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(base[i][j]=='H') que.push(mp(i,j)),dist[i][j]=0;
	while(!que.empty()){
		int i=que.front().fi;
		int j=que.front().se;
		que.pop();
		for(int k=0;k<4;k++){
			int ni=i+dir[k][0];
			int nj=j+dir[k][1];
			if(ni>=1&&ni<=n&&nj>=1&&nj<=n&&(base[ni][nj]=='G'||base[ni][nj]=='M')&dist[ni][nj]==-1){
				que.push(mp(ni,nj)); dist[ni][nj]=dist[i][j]+s;
			}
		}
	}
}

bool check(int t){
	if(dist[sx][sy]<=t*s) return false;
	memset(dis,-1,sizeof dis);
	queue<pii> que;
	que.push(mp(sx,sy)); dis[sx][sy]=t*s;
	while(!que.empty()){
		int i=que.front().fi;
		int j=que.front().se;
		que.pop();
		for(int k=0;k<4;k++){
			int ni=i+dir[k][0];
			int nj=j+dir[k][1];
			if(ni>=1&&ni<=n&&nj>=1&&nj<=n&&dis[ni][nj]==-1&&(base[ni][nj]=='D'||(base[ni][nj]=='G'&&dist[ni][nj]>dis[i][j]+1))){
				que.push(mp(ni,nj)); dis[ni][nj]=dis[i][j]+1;
			}
		}
	}
	return dis[ex][ey]!=-1;
}

int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++){
		scanf("%s",base[i]+1);
		for(int j=1;j<=n;j++){
			if(base[i][j]=='M') sx=i,sy=j;
			if(base[i][j]=='D') ex=i,ey=j;
		}
	}
	bfs();
	int l=-1,r=n*n+5,ans=0;
	while(l<=r){
		int m=(l+r)/2;
		if(check(m)) ans=m,l=m+1; else r=m-1;
	}
	printf("%d",ans);
	return 0;
}

Compilation message

mecho.cpp: In function 'void bfs()':
mecho.cpp:33:86: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   33 |    if(ni>=1&&ni<=n&&nj>=1&&nj<=n&&(base[ni][nj]=='G'||base[ni][nj]=='M')&dist[ni][nj]==-1){
      |                                                                          ~~~~~~~~~~~~^~~~
mecho.cpp: In function 'int main()':
mecho.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%d%d",&n,&s);
      |  ~~~~~^~~~~~~~~~~~~~
mecho.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   scanf("%s",base[i]+1);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5332 KB Output is correct
2 Correct 3 ms 5332 KB Output is correct
3 Correct 3 ms 5300 KB Output is correct
4 Correct 3 ms 5332 KB Output is correct
5 Correct 3 ms 5316 KB Output is correct
6 Correct 3 ms 5332 KB Output is correct
7 Correct 87 ms 6732 KB Output is correct
8 Correct 4 ms 5332 KB Output is correct
9 Correct 3 ms 5332 KB Output is correct
10 Correct 3 ms 5296 KB Output is correct
11 Correct 2 ms 5332 KB Output is correct
12 Correct 3 ms 5332 KB Output is correct
13 Correct 3 ms 5332 KB Output is correct
14 Incorrect 3 ms 5332 KB Output isn't correct
15 Correct 4 ms 5332 KB Output is correct
16 Correct 3 ms 5332 KB Output is correct
17 Correct 3 ms 5332 KB Output is correct
18 Correct 3 ms 5332 KB Output is correct
19 Correct 4 ms 5332 KB Output is correct
20 Correct 4 ms 5332 KB Output is correct
21 Correct 3 ms 5332 KB Output is correct
22 Correct 3 ms 5416 KB Output is correct
23 Correct 3 ms 5332 KB Output is correct
24 Correct 4 ms 5296 KB Output is correct
25 Correct 4 ms 5332 KB Output is correct
26 Correct 3 ms 5332 KB Output is correct
27 Correct 3 ms 5332 KB Output is correct
28 Correct 3 ms 5332 KB Output is correct
29 Correct 3 ms 5332 KB Output is correct
30 Correct 5 ms 5428 KB Output is correct
31 Correct 3 ms 5332 KB Output is correct
32 Correct 4 ms 5332 KB Output is correct
33 Correct 7 ms 5716 KB Output is correct
34 Correct 7 ms 5696 KB Output is correct
35 Correct 22 ms 5696 KB Output is correct
36 Correct 7 ms 5844 KB Output is correct
37 Correct 11 ms 5844 KB Output is correct
38 Correct 37 ms 5844 KB Output is correct
39 Correct 9 ms 5880 KB Output is correct
40 Correct 9 ms 5928 KB Output is correct
41 Correct 33 ms 5832 KB Output is correct
42 Correct 12 ms 5912 KB Output is correct
43 Correct 10 ms 6016 KB Output is correct
44 Correct 64 ms 6004 KB Output is correct
45 Correct 9 ms 6100 KB Output is correct
46 Correct 12 ms 6068 KB Output is correct
47 Correct 56 ms 6008 KB Output is correct
48 Correct 11 ms 6208 KB Output is correct
49 Correct 16 ms 6176 KB Output is correct
50 Correct 66 ms 6196 KB Output is correct
51 Correct 12 ms 6264 KB Output is correct
52 Correct 16 ms 6184 KB Output is correct
53 Correct 83 ms 6212 KB Output is correct
54 Correct 15 ms 6308 KB Output is correct
55 Correct 17 ms 6384 KB Output is correct
56 Correct 110 ms 6400 KB Output is correct
57 Correct 16 ms 6484 KB Output is correct
58 Correct 18 ms 6484 KB Output is correct
59 Correct 121 ms 6500 KB Output is correct
60 Correct 18 ms 6512 KB Output is correct
61 Correct 21 ms 6604 KB Output is correct
62 Correct 133 ms 6620 KB Output is correct
63 Correct 107 ms 6620 KB Output is correct
64 Correct 147 ms 6620 KB Output is correct
65 Correct 152 ms 6624 KB Output is correct
66 Correct 136 ms 6620 KB Output is correct
67 Incorrect 122 ms 6620 KB Output isn't correct
68 Correct 48 ms 6560 KB Output is correct
69 Correct 52 ms 6644 KB Output is correct
70 Correct 37 ms 6540 KB Output is correct
71 Correct 30 ms 6560 KB Output is correct
72 Correct 26 ms 6604 KB Output is correct
73 Correct 43 ms 6924 KB Output is correct
74 Correct 57 ms 6860 KB Output is correct
75 Correct 61 ms 6896 KB Output is correct
76 Correct 74 ms 6800 KB Output is correct
77 Correct 61 ms 6896 KB Output is correct
78 Incorrect 69 ms 6860 KB Output isn't correct
79 Correct 57 ms 6872 KB Output is correct
80 Correct 54 ms 6824 KB Output is correct
81 Correct 62 ms 6860 KB Output is correct
82 Correct 54 ms 6864 KB Output is correct
83 Correct 76 ms 6824 KB Output is correct
84 Correct 70 ms 6832 KB Output is correct
85 Correct 66 ms 6836 KB Output is correct
86 Correct 78 ms 6732 KB Output is correct
87 Correct 77 ms 6716 KB Output is correct
88 Correct 102 ms 6780 KB Output is correct
89 Correct 100 ms 6776 KB Output is correct
90 Correct 90 ms 6780 KB Output is correct
91 Correct 117 ms 6692 KB Output is correct
92 Correct 115 ms 6780 KB Output is correct