답안 #58189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58189 2018-07-17T06:19:19 Z gnoor Mecho (IOI09_mecho) C++17
26 / 100
336 ms 9720 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

struct cell {
	int r,c;
};

queue<cell> bee;
queue<cell> bear;
bool wall[1010][1010];

int disBear[1010][1010];
int disBee[1010][1010];
cell home;
cell start;

int di[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
int n,s;

bool check(int x) {
	memset(disBear,63,sizeof(disBear));
	disBear[start.r][start.c]=x*s;
	bear.push(start);
	int nowr,nowc,nextr,nextc;
	while (!bear.empty()) {
		nowr=bear.front().r;
		nowc=bear.front().c;
		bear.pop();
		for (int i=0;i<4;i++) {
			nextr=nowr+di[i][0];
			nextc=nowc+di[i][1];
			if (nextc<0||nextc>=n||nextr<0||nextr>=n) continue;
			if (wall[nextr][nextc]) continue;
			if (disBear[nextr][nextc]<=disBear[nowr][nowc]+1) continue;
			if (disBee[nextr][nextc]<=(disBear[nowr][nowc]+1)/s) continue;
			disBear[nextr][nextc]=disBear[nowr][nowc]+1;
			bear.push(cell{nextr,nextc});
		}
	}

	return disBear[home.r][home.c]!=0x3f3f3f3f;
}

int main () {
	scanf("%d%d",&n,&s);
	char x;
	

	memset(disBee,63,sizeof(disBee));
	for (int i=0;i<n;i++) {
		for (int j=0;j<n;j++) {
			scanf(" %c",&x);
			if (x=='T') wall[i][j]=true;
			else if (x=='M'){
				start=cell{i,j};
			}
			else if (x=='D') home=cell{i,j};
			else if (x=='H') {
				bee.push(cell{i,j});
				disBee[i][j]=0;
			}
		}
	}


	int nowr,nowc;
	int nextr,nextc;
	while (!bee.empty()) {
		nowr=bee.front().r;
		nowc=bee.front().c;
		bee.pop();
		for (int i=0;i<4;i++) {
			nextr=nowr+di[i][0];
			nextc=nowc+di[i][1];
			if (nextc<0||nextc>=n||nextr<0||nextr>=n) continue;
			if (wall[nextr][nextc]) continue;
			if (nextr==home.r&&nextc==home.c) continue;
			if (disBee[nextr][nextc]<=disBee[nowr][nowc]+1) continue;
			disBee[nextr][nextc]=disBee[nowr][nowc]+1;
			bee.push(cell{nextr,nextc});
		}
	}

	int lo=0;
	int hi=2*n;
	int mid;	
	while (lo<hi) {
		mid=(lo+hi+1)>>1;
		if (check(mid)) {
			lo=mid;
		} else {
			hi=mid-1;
		}
	}

	printf("%d\n",lo);

	return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:50: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:57:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c",&x);
    ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 8312 KB Output is correct
2 Correct 8 ms 8424 KB Output is correct
3 Correct 8 ms 8424 KB Output is correct
4 Correct 8 ms 8424 KB Output is correct
5 Correct 11 ms 8424 KB Output is correct
6 Correct 12 ms 8424 KB Output is correct
7 Correct 166 ms 9332 KB Output is correct
8 Incorrect 10 ms 9332 KB Output isn't correct
9 Correct 10 ms 9332 KB Output is correct
10 Correct 11 ms 9332 KB Output is correct
11 Correct 9 ms 9332 KB Output is correct
12 Incorrect 9 ms 9332 KB Output isn't correct
13 Incorrect 10 ms 9332 KB Output isn't correct
14 Incorrect 9 ms 9332 KB Output isn't correct
15 Incorrect 10 ms 9332 KB Output isn't correct
16 Incorrect 12 ms 9332 KB Output isn't correct
17 Incorrect 10 ms 9332 KB Output isn't correct
18 Incorrect 11 ms 9332 KB Output isn't correct
19 Incorrect 9 ms 9332 KB Output isn't correct
20 Incorrect 9 ms 9332 KB Output isn't correct
21 Incorrect 10 ms 9332 KB Output isn't correct
22 Incorrect 9 ms 9332 KB Output isn't correct
23 Incorrect 12 ms 9332 KB Output isn't correct
24 Incorrect 12 ms 9332 KB Output isn't correct
25 Incorrect 12 ms 9332 KB Output isn't correct
26 Incorrect 13 ms 9332 KB Output isn't correct
27 Incorrect 10 ms 9332 KB Output isn't correct
28 Incorrect 10 ms 9332 KB Output isn't correct
29 Incorrect 13 ms 9332 KB Output isn't correct
30 Incorrect 10 ms 9332 KB Output isn't correct
31 Incorrect 13 ms 9332 KB Output isn't correct
32 Incorrect 10 ms 9332 KB Output isn't correct
33 Incorrect 26 ms 9332 KB Output isn't correct
34 Incorrect 66 ms 9332 KB Output isn't correct
35 Correct 69 ms 9332 KB Output is correct
36 Incorrect 36 ms 9332 KB Output isn't correct
37 Incorrect 42 ms 9332 KB Output isn't correct
38 Correct 51 ms 9332 KB Output is correct
39 Incorrect 38 ms 9332 KB Output isn't correct
40 Incorrect 49 ms 9332 KB Output isn't correct
41 Correct 65 ms 9332 KB Output is correct
42 Incorrect 44 ms 9332 KB Output isn't correct
43 Incorrect 62 ms 9332 KB Output isn't correct
44 Correct 81 ms 9332 KB Output is correct
45 Incorrect 77 ms 9332 KB Output isn't correct
46 Incorrect 73 ms 9332 KB Output isn't correct
47 Correct 91 ms 9332 KB Output is correct
48 Incorrect 83 ms 9332 KB Output isn't correct
49 Incorrect 85 ms 9332 KB Output isn't correct
50 Correct 145 ms 9332 KB Output is correct
51 Incorrect 91 ms 9332 KB Output isn't correct
52 Incorrect 97 ms 9332 KB Output isn't correct
53 Correct 217 ms 9340 KB Output is correct
54 Incorrect 109 ms 9340 KB Output isn't correct
55 Incorrect 143 ms 9340 KB Output isn't correct
56 Correct 199 ms 9360 KB Output is correct
57 Incorrect 92 ms 9360 KB Output isn't correct
58 Incorrect 135 ms 9360 KB Output isn't correct
59 Correct 197 ms 9360 KB Output is correct
60 Incorrect 102 ms 9360 KB Output isn't correct
61 Incorrect 171 ms 9396 KB Output isn't correct
62 Correct 278 ms 9516 KB Output is correct
63 Correct 175 ms 9516 KB Output is correct
64 Correct 293 ms 9516 KB Output is correct
65 Correct 336 ms 9516 KB Output is correct
66 Correct 276 ms 9516 KB Output is correct
67 Incorrect 271 ms 9640 KB Output isn't correct
68 Correct 116 ms 9640 KB Output is correct
69 Correct 91 ms 9640 KB Output is correct
70 Correct 108 ms 9640 KB Output is correct
71 Correct 96 ms 9640 KB Output is correct
72 Incorrect 91 ms 9640 KB Output isn't correct
73 Incorrect 88 ms 9640 KB Output isn't correct
74 Correct 128 ms 9640 KB Output is correct
75 Correct 125 ms 9720 KB Output is correct
76 Correct 113 ms 9720 KB Output is correct
77 Correct 132 ms 9720 KB Output is correct
78 Incorrect 168 ms 9720 KB Output isn't correct
79 Correct 117 ms 9720 KB Output is correct
80 Correct 161 ms 9720 KB Output is correct
81 Correct 188 ms 9720 KB Output is correct
82 Correct 163 ms 9720 KB Output is correct
83 Correct 151 ms 9720 KB Output is correct
84 Correct 137 ms 9720 KB Output is correct
85 Correct 183 ms 9720 KB Output is correct
86 Correct 223 ms 9720 KB Output is correct
87 Correct 172 ms 9720 KB Output is correct
88 Correct 151 ms 9720 KB Output is correct
89 Correct 170 ms 9720 KB Output is correct
90 Correct 163 ms 9720 KB Output is correct
91 Correct 169 ms 9720 KB Output is correct
92 Correct 187 ms 9720 KB Output is correct