답안 #74396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74396 2018-08-31T15:28:17 Z vvv3334 Mecho (IOI09_mecho) C
49 / 100
230 ms 14452 KB
//baekjoon_10216
#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] - 1)) 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(5));
	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 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 508 KB Output isn't correct
3 Incorrect 2 ms 508 KB Output isn't correct
4 Incorrect 2 ms 508 KB Output isn't correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 104 ms 14228 KB Output is correct
8 Incorrect 2 ms 14228 KB Output isn't correct
9 Correct 2 ms 14228 KB Output is correct
10 Correct 2 ms 14228 KB Output is correct
11 Correct 3 ms 14228 KB Output is correct
12 Incorrect 2 ms 14228 KB Output isn't correct
13 Correct 3 ms 14228 KB Output is correct
14 Correct 2 ms 14228 KB Output is correct
15 Incorrect 2 ms 14228 KB Output isn't correct
16 Correct 2 ms 14228 KB Output is correct
17 Incorrect 2 ms 14228 KB Output isn't correct
18 Correct 2 ms 14228 KB Output is correct
19 Incorrect 2 ms 14228 KB Output isn't correct
20 Correct 2 ms 14228 KB Output is correct
21 Incorrect 2 ms 14228 KB Output isn't correct
22 Correct 2 ms 14228 KB Output is correct
23 Incorrect 2 ms 14228 KB Output isn't correct
24 Correct 2 ms 14228 KB Output is correct
25 Incorrect 2 ms 14228 KB Output isn't correct
26 Correct 2 ms 14228 KB Output is correct
27 Incorrect 2 ms 14228 KB Output isn't correct
28 Correct 3 ms 14228 KB Output is correct
29 Incorrect 3 ms 14228 KB Output isn't correct
30 Correct 2 ms 14228 KB Output is correct
31 Incorrect 2 ms 14228 KB Output isn't correct
32 Correct 2 ms 14228 KB Output is correct
33 Incorrect 7 ms 14228 KB Output isn't correct
34 Correct 8 ms 14228 KB Output is correct
35 Correct 22 ms 14228 KB Output is correct
36 Incorrect 8 ms 14228 KB Output isn't correct
37 Correct 8 ms 14228 KB Output is correct
38 Correct 30 ms 14228 KB Output is correct
39 Incorrect 10 ms 14228 KB Output isn't correct
40 Correct 10 ms 14228 KB Output is correct
41 Correct 38 ms 14228 KB Output is correct
42 Incorrect 11 ms 14228 KB Output isn't correct
43 Correct 11 ms 14228 KB Output is correct
44 Correct 50 ms 14228 KB Output is correct
45 Incorrect 13 ms 14228 KB Output isn't correct
46 Correct 13 ms 14228 KB Output is correct
47 Correct 59 ms 14228 KB Output is correct
48 Incorrect 15 ms 14228 KB Output isn't correct
49 Correct 17 ms 14228 KB Output is correct
50 Correct 70 ms 14228 KB Output is correct
51 Incorrect 17 ms 14228 KB Output isn't correct
52 Correct 27 ms 14228 KB Output is correct
53 Correct 97 ms 14228 KB Output is correct
54 Incorrect 19 ms 14228 KB Output isn't correct
55 Correct 20 ms 14228 KB Output is correct
56 Correct 122 ms 14228 KB Output is correct
57 Incorrect 22 ms 14228 KB Output isn't correct
58 Correct 23 ms 14228 KB Output is correct
59 Correct 174 ms 14228 KB Output is correct
60 Incorrect 30 ms 14228 KB Output isn't correct
61 Correct 31 ms 14228 KB Output is correct
62 Correct 150 ms 14228 KB Output is correct
63 Correct 123 ms 14228 KB Output is correct
64 Correct 230 ms 14228 KB Output is correct
65 Correct 173 ms 14228 KB Output is correct
66 Incorrect 150 ms 14228 KB Output isn't correct
67 Correct 123 ms 14228 KB Output is correct
68 Correct 54 ms 14228 KB Output is correct
69 Correct 53 ms 14228 KB Output is correct
70 Correct 40 ms 14228 KB Output is correct
71 Correct 48 ms 14228 KB Output is correct
72 Correct 35 ms 14228 KB Output is correct
73 Correct 60 ms 14332 KB Output is correct
74 Correct 67 ms 14332 KB Output is correct
75 Correct 81 ms 14332 KB Output is correct
76 Correct 79 ms 14332 KB Output is correct
77 Correct 69 ms 14332 KB Output is correct
78 Correct 90 ms 14332 KB Output is correct
79 Correct 60 ms 14332 KB Output is correct
80 Correct 64 ms 14332 KB Output is correct
81 Correct 72 ms 14336 KB Output is correct
82 Correct 72 ms 14452 KB Output is correct
83 Correct 100 ms 14452 KB Output is correct
84 Correct 76 ms 14452 KB Output is correct
85 Correct 91 ms 14452 KB Output is correct
86 Correct 87 ms 14452 KB Output is correct
87 Correct 92 ms 14452 KB Output is correct
88 Correct 94 ms 14452 KB Output is correct
89 Correct 97 ms 14452 KB Output is correct
90 Correct 100 ms 14452 KB Output is correct
91 Correct 100 ms 14452 KB Output is correct
92 Correct 102 ms 14452 KB Output is correct