답안 #74397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74397 2018-08-31T15:33:52 Z vvv3334 Mecho (IOI09_mecho) C
22 / 100
211 ms 14456 KB
//baekjoon_5465
#pragma warning(disable : 4996)
#include <stdio.h>
#include <stdlib.h>

int N, S;
int MAP[1000][1000];
char str[810];
int CHANGE['Z'+1];
int sr, sc, er, ec;

int VISIT[1000][1000];

typedef struct st
{
	int r;
	int c;
	int time;
}QUEUE;

QUEUE Que[810 * 810];
int WP, RP;

void input()
{
	int i, k, tmp;

	CHANGE['T'] = -1;
	CHANGE['G'] = 0;
	CHANGE['H'] = 1;
	CHANGE['M'] = 0;
	CHANGE['D'] = 0x7fff0000;

	scanf("%d %d", &N, &S);

	for (i = 1; i <= N;i++)
	{
		scanf("%s", str + 1);
		for (k = 1; k <= N;k++)
		{
			if (str[k] == 'M')
			{
				sr = i;
				sc = k;
			}
			else if(str[k] == 'D')
			{
				er = i;
				ec = k;
			}

			MAP[i][k] = CHANGE[str[k]];
		}
	}

	//printf("%d %d %d %d\n", sr, sc, er, ec);
}

void output()
{
	int i, k;

	for (i = 1; i <= N;i++)
	{
		for (k = 1; k <= N;k++)
			printf("%2d ", MAP[i][k]);
		putchar('\n');
	}
	putchar('\n');
}


void outputVISIT()
{
	int i, k;

	for (i = 1; i <= N;i++)
	{
		for (k = 1; k <= N;k++)
			printf("%2d ", VISIT[i][k]);
		putchar('\n');
	}
	putchar('\n');
}

int dr[] = { 0,1,0,-1 };
int dc[] = { 1,0,-1,0 };

void BFS()
{
	int i, nr, nc;
	QUEUE out;

	while (WP > RP)
	{
		out = Que[RP++];

		for (i = 0; i < 4;i++)
		{
			nr = out.r + dr[i];
			nc = out.c + dc[i];

			if (nr < 1 || nc < 1 || nr > N || nc > N) continue;
			
			if (MAP[nr][nc] == 0)
			{
				Que[WP].r = nr;
				Que[WP++].c = nc;
				MAP[nr][nc] = MAP[out.r][out.c] + 1;
			}

		}
	}
}

int BFS2(int mid)
{
	
	int i, k, nr, nc;
	QUEUE out;
	
	if (mid == MAP[sr][sc]-1  ) return 0;

	WP = RP = 0;

	for (i = 1; i <= N;i++)
		for (k = 1; k <= N;k++)
			VISIT[i][k] = 0;

	Que[WP].r = sr;
	Que[WP].c = sc;
	Que[WP++].time = mid;
	
	VISIT[sr][sc] = 1;

	while (WP > RP)
	{
		out = Que[RP++];

		if (out.r == er && out.c == ec) return 1;

		for (i = 0; i < 4;i++)
		{
			nr = out.r + dr[i];
			nc = out.c + dc[i];
			
			if (nr < 1 || nc < 1 || nr > N || nc > N) continue;
			if (MAP[nr][nc] == -1 || VISIT[nr][nc] != 0) continue;
			if ((mid + (out.time-mid) / S) >= (MAP[nr][nc] - 2)) continue;

			Que[WP].r = nr;
			Que[WP].c = nc;
			Que[WP++].time = out.time + 1;
			VISIT[nr][nc] = (out.time - mid) / S + 1;
		}
		//outputVISIT();
	}
	
	return 0;
}

int main()
{
	int i, k;
	int right, left, mid;
	int tmp, ans;

	input();
	//output();

	for (i = 1; i <= N;i++)
	{
		for (k = 1; k <= N;k++)
		{
			if (MAP[i][k] == 1)
			{
				Que[WP].r = i;
				Que[WP++].c = k;
			}
		}
	}

	BFS();

	/*output();
	
	printf("%d\n",BFS2(2));
	outputVISIT();*/

	//return;

	left = 0;
	right = 2 * N * N;

	ans = -1;

	while (left <= right)
	{
		mid = (left + right) / 2;
		
		tmp = BFS2(mid);
		//printf("%d %d\n", tmp, mid);
		if (tmp)
		{
			ans = mid;
			left = mid + 1;
		}
		else
			right = mid - 1;
		
	}

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


	return 0;
}

Compilation message

mecho.c:2:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
 
mecho.c: In function 'input':
mecho.c:52:22: warning: array subscript has type 'char' [-Wchar-subscripts]
    MAP[i][k] = CHANGE[str[k]];
                      ^
mecho.c:26:12: warning: unused variable 'tmp' [-Wunused-variable]
  int i, k, tmp;
            ^~~
mecho.c:34:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &S);
  ^~~~~~~~~~~~~~~~~~~~~~
mecho.c:38:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", str + 1);
   ^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Incorrect 2 ms 536 KB Output isn't correct
6 Incorrect 2 ms 600 KB Output isn't correct
7 Incorrect 97 ms 14316 KB Output isn't correct
8 Correct 2 ms 14316 KB Output is correct
9 Incorrect 2 ms 14316 KB Output isn't correct
10 Incorrect 2 ms 14316 KB Output isn't correct
11 Incorrect 2 ms 14316 KB Output isn't correct
12 Incorrect 2 ms 14316 KB Output isn't correct
13 Correct 2 ms 14316 KB Output is correct
14 Correct 3 ms 14316 KB Output is correct
15 Correct 2 ms 14316 KB Output is correct
16 Incorrect 2 ms 14316 KB Output isn't correct
17 Correct 2 ms 14316 KB Output is correct
18 Incorrect 2 ms 14316 KB Output isn't correct
19 Correct 2 ms 14316 KB Output is correct
20 Incorrect 2 ms 14316 KB Output isn't correct
21 Correct 3 ms 14316 KB Output is correct
22 Incorrect 3 ms 14316 KB Output isn't correct
23 Correct 3 ms 14316 KB Output is correct
24 Incorrect 2 ms 14316 KB Output isn't correct
25 Correct 2 ms 14316 KB Output is correct
26 Incorrect 2 ms 14316 KB Output isn't correct
27 Correct 2 ms 14316 KB Output is correct
28 Incorrect 2 ms 14316 KB Output isn't correct
29 Correct 2 ms 14316 KB Output is correct
30 Incorrect 2 ms 14316 KB Output isn't correct
31 Correct 2 ms 14316 KB Output is correct
32 Incorrect 3 ms 14316 KB Output isn't correct
33 Correct 7 ms 14316 KB Output is correct
34 Incorrect 7 ms 14316 KB Output isn't correct
35 Incorrect 23 ms 14316 KB Output isn't correct
36 Correct 8 ms 14316 KB Output is correct
37 Incorrect 9 ms 14316 KB Output isn't correct
38 Incorrect 32 ms 14316 KB Output isn't correct
39 Correct 13 ms 14316 KB Output is correct
40 Incorrect 11 ms 14316 KB Output isn't correct
41 Incorrect 39 ms 14316 KB Output isn't correct
42 Correct 11 ms 14316 KB Output is correct
43 Incorrect 12 ms 14316 KB Output isn't correct
44 Incorrect 50 ms 14316 KB Output isn't correct
45 Correct 13 ms 14316 KB Output is correct
46 Incorrect 15 ms 14316 KB Output isn't correct
47 Incorrect 59 ms 14316 KB Output isn't correct
48 Correct 16 ms 14316 KB Output is correct
49 Incorrect 15 ms 14316 KB Output isn't correct
50 Incorrect 77 ms 14316 KB Output isn't correct
51 Correct 20 ms 14316 KB Output is correct
52 Incorrect 18 ms 14316 KB Output isn't correct
53 Incorrect 86 ms 14316 KB Output isn't correct
54 Correct 19 ms 14316 KB Output is correct
55 Incorrect 20 ms 14316 KB Output isn't correct
56 Incorrect 110 ms 14316 KB Output isn't correct
57 Correct 22 ms 14316 KB Output is correct
58 Incorrect 22 ms 14316 KB Output isn't correct
59 Incorrect 126 ms 14316 KB Output isn't correct
60 Correct 23 ms 14316 KB Output is correct
61 Incorrect 26 ms 14316 KB Output isn't correct
62 Incorrect 158 ms 14316 KB Output isn't correct
63 Incorrect 106 ms 14316 KB Output isn't correct
64 Incorrect 211 ms 14316 KB Output isn't correct
65 Incorrect 170 ms 14316 KB Output isn't correct
66 Correct 152 ms 14316 KB Output is correct
67 Correct 136 ms 14316 KB Output is correct
68 Incorrect 57 ms 14316 KB Output isn't correct
69 Incorrect 49 ms 14316 KB Output isn't correct
70 Incorrect 49 ms 14316 KB Output isn't correct
71 Incorrect 45 ms 14316 KB Output isn't correct
72 Correct 41 ms 14316 KB Output is correct
73 Correct 44 ms 14316 KB Output is correct
74 Incorrect 95 ms 14328 KB Output isn't correct
75 Incorrect 94 ms 14332 KB Output isn't correct
76 Incorrect 90 ms 14332 KB Output isn't correct
77 Incorrect 98 ms 14332 KB Output isn't correct
78 Correct 91 ms 14332 KB Output is correct
79 Incorrect 59 ms 14332 KB Output isn't correct
80 Incorrect 70 ms 14332 KB Output isn't correct
81 Incorrect 79 ms 14456 KB Output isn't correct
82 Incorrect 66 ms 14456 KB Output isn't correct
83 Incorrect 90 ms 14456 KB Output isn't correct
84 Incorrect 94 ms 14456 KB Output isn't correct
85 Incorrect 88 ms 14456 KB Output isn't correct
86 Incorrect 92 ms 14456 KB Output isn't correct
87 Incorrect 90 ms 14456 KB Output isn't correct
88 Incorrect 97 ms 14456 KB Output isn't correct
89 Incorrect 104 ms 14456 KB Output isn't correct
90 Incorrect 104 ms 14456 KB Output isn't correct
91 Incorrect 99 ms 14456 KB Output isn't correct
92 Incorrect 94 ms 14456 KB Output isn't correct