Submission #53468

# Submission time Handle Problem Language Result Execution time Memory
53468 2018-06-30T05:32:02 Z 장홍준(#2017) Mecho (IOI09_mecho) C++11
84 / 100
843 ms 3656 KB
#include<stdio.h>
#include<deque>
#include<vector>
using namespace std;
int n, S;
char M[818][818], NM[818][818];
int D[818][818];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
vector<int>Qhx, Qhy;
void spread() {
	int i, j;
	vector<int>Qnx, Qny;
	for(i=0;i<Qhx.size();i++){
		int nowx = Qhx[i], nowy = Qhy[i];
		for (int k = 0; k < 4; k++) {
			int nx = nowx + dx[k], ny = nowy + dy[k];
			if (nx <= 0 || ny <= 0 || nx > n || ny > n)continue;
			if (NM[nx][ny] != 'T'&&NM[nx][ny] != 'H') {
				NM[nx][ny] = 'H';
				Qnx.push_back(nx); Qny.push_back(ny);
			}
		}
	}
	Qhx.clear(); Qhy.clear();
	for (i = 0; i < Qnx.size(); i++) {
		Qhx.push_back(Qnx[i]);
		Qhy.push_back(Qny[i]);
	}
}
bool is_gone[818][818];
void printnm() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++)printf("%c", NM[i][j]); printf("\n"); }printf("\n"); }
int f(int x) {
	Qhx.clear(); Qhy.clear();
	int i, j, sx, sy, ex, ey, nxt;
	deque<int>qx, qy, qd;
	for (i = 1; i <= n; i++)for (j = 1; j <= n; j++) {
		if (M[i][j] == 'M')sx = i, sy = j;
		if (M[i][j] == 'D')ex = i, ey = j;
		if (M[i][j] == 'H')Qhx.push_back(i), Qhy.push_back(j);
		NM[i][j] = M[i][j];
		is_gone[i][j] = 0;
	}
	for (i = 0; i < x; i++)spread();
	qx.push_back(sx); qy.push_back(sy); qd.push_back(0);
	nxt = S;
	while (!qx.empty()) {
		int nowx = qx.front(); qx.pop_front();
		int nowy = qy.front(); qy.pop_front();
		int nowd = qd.front(); qd.pop_front();
		if (nowx == ex && nowy == ey)return 1;
		if (nowd == nxt)
			spread(), nxt += S;
		if (NM[nowx][nowy] == 'H')continue;
		for (i = 0; i < 4; i++) {
			int nx = nowx + dx[i], ny = nowy + dy[i];
			if (nx <= 0 || ny <= 0 || nx > n || ny > n)continue;
			if (is_gone[nx][ny])continue;
			if (NM[nx][ny] == 'H')continue;
			if (NM[nx][ny] == 'T')continue;
			qx.push_back(nx); qy.push_back(ny); qd.push_back(nowd + 1);
			is_gone[nx][ny] = 1;
		}
	}
	return 0;
}
int main() {
	int i, j, s, e, ans = -1;
	scanf("%d%d", &n, &S);
	for (i = 1; i <= n; i++)for (j = 1; j <= n; j++)scanf(" %c", &M[i][j]);
	s = 0, e = n * n;
	while (s <= e) {
		int m = (s + e) / 2;
		int k = f(m);
		if (k)s = m + 1, ans = m;
		else e = m - 1;
	}
	printf("%d", ans);
	return 0;
}

Compilation message

mecho.cpp: In function 'void spread()':
mecho.cpp:14:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<Qhx.size();i++){
          ~^~~~~~~~~~~
mecho.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < Qnx.size(); i++) {
              ~~^~~~~~~~~~~~
mecho.cpp:12:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
mecho.cpp: In function 'int main()':
mecho.cpp:69: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:70:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= n; i++)for (j = 1; j <= n; j++)scanf(" %c", &M[i][j]);
                                                  ~~~~~^~~~~~~~~~~~~~~~~
mecho.cpp: In function 'int f(int)':
mecho.cpp:51:26: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (nowx == ex && nowy == ey)return 1;
                     ~~~~~^~~~~
mecho.cpp:51:12: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (nowx == ex && nowy == ey)return 1;
       ~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 2 ms 388 KB Output isn't correct
3 Correct 2 ms 420 KB Output is correct
4 Incorrect 2 ms 464 KB Output isn't correct
5 Correct 2 ms 480 KB Output is correct
6 Incorrect 2 ms 528 KB Output isn't correct
7 Incorrect 380 ms 2732 KB Output isn't correct
8 Correct 2 ms 2732 KB Output is correct
9 Correct 2 ms 2732 KB Output is correct
10 Correct 2 ms 2732 KB Output is correct
11 Correct 2 ms 2732 KB Output is correct
12 Incorrect 3 ms 2732 KB Output isn't correct
13 Correct 4 ms 2732 KB Output is correct
14 Correct 4 ms 2732 KB Output is correct
15 Correct 2 ms 2732 KB Output is correct
16 Correct 3 ms 2732 KB Output is correct
17 Correct 2 ms 2732 KB Output is correct
18 Correct 3 ms 2732 KB Output is correct
19 Correct 2 ms 2732 KB Output is correct
20 Correct 2 ms 2732 KB Output is correct
21 Correct 3 ms 2732 KB Output is correct
22 Correct 3 ms 2732 KB Output is correct
23 Correct 4 ms 2732 KB Output is correct
24 Correct 6 ms 2732 KB Output is correct
25 Correct 5 ms 2732 KB Output is correct
26 Correct 6 ms 2732 KB Output is correct
27 Correct 5 ms 2732 KB Output is correct
28 Correct 5 ms 2732 KB Output is correct
29 Correct 5 ms 2732 KB Output is correct
30 Correct 5 ms 2732 KB Output is correct
31 Correct 6 ms 2732 KB Output is correct
32 Correct 7 ms 2732 KB Output is correct
33 Correct 117 ms 2732 KB Output is correct
34 Correct 130 ms 2732 KB Output is correct
35 Correct 58 ms 2732 KB Output is correct
36 Correct 161 ms 2732 KB Output is correct
37 Correct 161 ms 2732 KB Output is correct
38 Correct 74 ms 2732 KB Output is correct
39 Correct 208 ms 2732 KB Output is correct
40 Correct 216 ms 2732 KB Output is correct
41 Correct 94 ms 2732 KB Output is correct
42 Correct 260 ms 2732 KB Output is correct
43 Correct 361 ms 2732 KB Output is correct
44 Correct 112 ms 2732 KB Output is correct
45 Correct 347 ms 2732 KB Output is correct
46 Correct 333 ms 2732 KB Output is correct
47 Correct 140 ms 2732 KB Output is correct
48 Correct 369 ms 2732 KB Output is correct
49 Correct 373 ms 2732 KB Output is correct
50 Correct 166 ms 2732 KB Output is correct
51 Correct 462 ms 2732 KB Output is correct
52 Correct 530 ms 2732 KB Output is correct
53 Correct 190 ms 2732 KB Output is correct
54 Correct 538 ms 2732 KB Output is correct
55 Correct 634 ms 2732 KB Output is correct
56 Correct 285 ms 2732 KB Output is correct
57 Correct 812 ms 2732 KB Output is correct
58 Correct 697 ms 2732 KB Output is correct
59 Correct 300 ms 2732 KB Output is correct
60 Correct 737 ms 2732 KB Output is correct
61 Correct 843 ms 2732 KB Output is correct
62 Correct 390 ms 2732 KB Output is correct
63 Correct 510 ms 2732 KB Output is correct
64 Correct 537 ms 2732 KB Output is correct
65 Correct 462 ms 2732 KB Output is correct
66 Correct 485 ms 2732 KB Output is correct
67 Correct 486 ms 2732 KB Output is correct
68 Correct 474 ms 2732 KB Output is correct
69 Correct 368 ms 2732 KB Output is correct
70 Correct 394 ms 2732 KB Output is correct
71 Correct 439 ms 2732 KB Output is correct
72 Correct 463 ms 2732 KB Output is correct
73 Correct 369 ms 3536 KB Output is correct
74 Correct 383 ms 3536 KB Output is correct
75 Correct 472 ms 3544 KB Output is correct
76 Correct 503 ms 3656 KB Output is correct
77 Correct 420 ms 3656 KB Output is correct
78 Correct 443 ms 3656 KB Output is correct
79 Correct 488 ms 3656 KB Output is correct
80 Correct 526 ms 3656 KB Output is correct
81 Correct 469 ms 3656 KB Output is correct
82 Correct 416 ms 3656 KB Output is correct
83 Correct 556 ms 3656 KB Output is correct
84 Correct 403 ms 3656 KB Output is correct
85 Correct 414 ms 3656 KB Output is correct
86 Correct 395 ms 3656 KB Output is correct
87 Correct 398 ms 3656 KB Output is correct
88 Correct 419 ms 3656 KB Output is correct
89 Correct 398 ms 3656 KB Output is correct
90 Correct 393 ms 3656 KB Output is correct
91 Correct 403 ms 3656 KB Output is correct
92 Correct 413 ms 3656 KB Output is correct