답안 #53460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53460 2018-06-30T05:22:51 Z 장홍준(#2017) Mecho (IOI09_mecho) C++11
6 / 100
387 ms 3564 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;
			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 = 0;
	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 * 2;
	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:68: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:69: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;
       ~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Correct 2 ms 540 KB Output is correct
4 Incorrect 2 ms 608 KB Output isn't correct
5 Incorrect 2 ms 608 KB Output isn't correct
6 Incorrect 2 ms 608 KB Output isn't correct
7 Incorrect 220 ms 2744 KB Output isn't correct
8 Incorrect 2 ms 2744 KB Output isn't correct
9 Correct 2 ms 2744 KB Output is correct
10 Correct 2 ms 2744 KB Output is correct
11 Correct 2 ms 2744 KB Output is correct
12 Incorrect 2 ms 2744 KB Output isn't correct
13 Correct 3 ms 2744 KB Output is correct
14 Incorrect 3 ms 2744 KB Output isn't correct
15 Incorrect 2 ms 2744 KB Output isn't correct
16 Incorrect 3 ms 2744 KB Output isn't correct
17 Incorrect 2 ms 2744 KB Output isn't correct
18 Incorrect 3 ms 2744 KB Output isn't correct
19 Incorrect 2 ms 2744 KB Output isn't correct
20 Incorrect 2 ms 2744 KB Output isn't correct
21 Incorrect 2 ms 2744 KB Output isn't correct
22 Incorrect 3 ms 2744 KB Output isn't correct
23 Incorrect 2 ms 2744 KB Output isn't correct
24 Incorrect 3 ms 2744 KB Output isn't correct
25 Incorrect 2 ms 2744 KB Output isn't correct
26 Incorrect 3 ms 2744 KB Output isn't correct
27 Incorrect 3 ms 2744 KB Output isn't correct
28 Incorrect 3 ms 2744 KB Output isn't correct
29 Incorrect 3 ms 2744 KB Output isn't correct
30 Incorrect 5 ms 2744 KB Output isn't correct
31 Incorrect 3 ms 2744 KB Output isn't correct
32 Incorrect 4 ms 2744 KB Output isn't correct
33 Incorrect 14 ms 2744 KB Output isn't correct
34 Incorrect 31 ms 2744 KB Output isn't correct
35 Incorrect 40 ms 2744 KB Output isn't correct
36 Incorrect 17 ms 2744 KB Output isn't correct
37 Incorrect 40 ms 2744 KB Output isn't correct
38 Incorrect 90 ms 2744 KB Output isn't correct
39 Incorrect 23 ms 2744 KB Output isn't correct
40 Incorrect 53 ms 2744 KB Output isn't correct
41 Incorrect 64 ms 2744 KB Output isn't correct
42 Incorrect 27 ms 2744 KB Output isn't correct
43 Incorrect 59 ms 2744 KB Output isn't correct
44 Incorrect 101 ms 2744 KB Output isn't correct
45 Incorrect 35 ms 2744 KB Output isn't correct
46 Incorrect 84 ms 2744 KB Output isn't correct
47 Incorrect 118 ms 2744 KB Output isn't correct
48 Incorrect 41 ms 2744 KB Output isn't correct
49 Incorrect 104 ms 2744 KB Output isn't correct
50 Incorrect 137 ms 2744 KB Output isn't correct
51 Incorrect 49 ms 2744 KB Output isn't correct
52 Incorrect 121 ms 2744 KB Output isn't correct
53 Incorrect 160 ms 2744 KB Output isn't correct
54 Incorrect 54 ms 2744 KB Output isn't correct
55 Incorrect 180 ms 2744 KB Output isn't correct
56 Incorrect 216 ms 2744 KB Output isn't correct
57 Incorrect 60 ms 2744 KB Output isn't correct
58 Incorrect 179 ms 2744 KB Output isn't correct
59 Incorrect 241 ms 2744 KB Output isn't correct
60 Incorrect 68 ms 2744 KB Output isn't correct
61 Incorrect 247 ms 2744 KB Output isn't correct
62 Incorrect 318 ms 2744 KB Output isn't correct
63 Incorrect 196 ms 2744 KB Output isn't correct
64 Incorrect 159 ms 2744 KB Output isn't correct
65 Incorrect 141 ms 2744 KB Output isn't correct
66 Incorrect 210 ms 2744 KB Output isn't correct
67 Incorrect 175 ms 2744 KB Output isn't correct
68 Incorrect 264 ms 2744 KB Output isn't correct
69 Incorrect 269 ms 2744 KB Output isn't correct
70 Incorrect 238 ms 2744 KB Output isn't correct
71 Incorrect 242 ms 2744 KB Output isn't correct
72 Correct 282 ms 2744 KB Output is correct
73 Correct 193 ms 3564 KB Output is correct
74 Incorrect 229 ms 3564 KB Output isn't correct
75 Incorrect 295 ms 3564 KB Output isn't correct
76 Incorrect 387 ms 3564 KB Output isn't correct
77 Incorrect 312 ms 3564 KB Output isn't correct
78 Incorrect 264 ms 3564 KB Output isn't correct
79 Incorrect 242 ms 3564 KB Output isn't correct
80 Incorrect 283 ms 3564 KB Output isn't correct
81 Incorrect 361 ms 3564 KB Output isn't correct
82 Incorrect 287 ms 3564 KB Output isn't correct
83 Incorrect 283 ms 3564 KB Output isn't correct
84 Incorrect 232 ms 3564 KB Output isn't correct
85 Incorrect 259 ms 3564 KB Output isn't correct
86 Incorrect 244 ms 3564 KB Output isn't correct
87 Incorrect 273 ms 3564 KB Output isn't correct
88 Incorrect 274 ms 3564 KB Output isn't correct
89 Incorrect 277 ms 3564 KB Output isn't correct
90 Incorrect 263 ms 3564 KB Output isn't correct
91 Incorrect 318 ms 3564 KB Output isn't correct
92 Incorrect 265 ms 3564 KB Output isn't correct