<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>틀렸습니다! Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%ed%8b%80%eb%a0%b8%ec%8a%b5%eb%8b%88%eb%8b%a4-2/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Thu, 28 Mar 2024 11:44:31 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>틀렸습니다! Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 14500번 (테트로미노, C++) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 16 Feb 2023 01:53:01 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[14500]]></category>
		<category><![CDATA[14500번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 14500]]></category>
		<category><![CDATA[백준 14500번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[테트로미노]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33194</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 14500번 '테트로미노' 문제에 대한 글입니다. 'brute force' 알고리즘과 'DFS 탐색'을 이용하여 해결하였습니다. (This is BAEKJOON's 14500 article on the 'Tetromino' problem. It was solved using the 'brute force' algorithm and 'DFS search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/">백준 14500번 (테트로미노, C++) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-6eabfa96      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#테트로미노" class="uagb-toc-link__trigger">테트로미노</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a><li class="uagb-toc__list"><a href="#추가-반례" class="uagb-toc-link__trigger">추가 반례</a></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">테트로미노</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/14500" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/14500</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">69583</td><td class="has-text-align-left" data-align="left">26178</td><td class="has-text-align-left" data-align="left">17011</td><td class="has-text-align-left" data-align="left">35.673%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">정사각형은 서로 겹치면 안 된다.</p>



<p class="has-medium-font-size">도형은 모두 연결되어 있어야 한다.</p>



<p class="has-medium-font-size">정사각형의 변끼리 연결되어 있어야 한다. 즉, 꼭짓점과 꼭짓점만 맞닿아 있으면 안 된다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">정사각형 4개를 이어 붙인 폴리오미노는 테트로미노라고 하며, 다음과 같은 5가지가 있다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="488" height="308" src="https://lycos7560.com/wp-content/uploads/2023/02/image-73.png" alt="" class="wp-image-33195" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-73.png 488w, https://lycos7560.com/wp-content/uploads/2023/02/image-73-300x189.png 300w" sizes="(max-width: 488px) 100vw, 488px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">아름이는 크기가 N×M인 종이 위에 테트로미노 하나를 놓으려고 한다. </p>



<p class="has-medium-font-size">종이는 1×1 크기의 칸으로 나누어져 있으며, 각각의 칸에는 정수가 하나 쓰여 있다.</p>



<p class="has-medium-font-size">테트로미노 하나를 적절히 놓아서 테트로미노가 놓인 칸에 쓰여 있는 수들의 합을 최대로 하는 프로그램을 작성하시오.</p>



<p class="has-medium-font-size">테트로미노는 반드시 한 정사각형이 정확히 하나의 칸을 포함하도록 놓아야 하며, 회전이나 대칭을 시켜도 된다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 종이의 세로 크기 N과 가로 크기 M이 주어진다. (4&nbsp;≤ N, M ≤ 500)</p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에 종이에 쓰여 있는 수가 주어진다. </p>



<p class="has-medium-font-size">i번째 줄의 j번째 수는 위에서부터 i번째 칸, 왼쪽에서부터 j번째 칸에 쓰여 있는 수이다. </p>



<p class="has-medium-font-size">입력으로 주어지는 수는 1,000을 넘지 않는 자연수이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">첫째 줄에 테트로미노가 놓인 칸에 쓰인 수들의 합의 최댓값을 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 5
1 2 3 4 5
5 4 3 2 1
2 3 4 5 6
6 5 4 3 2
1 2 1 2 1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">19</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">20</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 10
1 2 1 2 1 2 1 2 1 2
2 1 2 1 2 1 2 1 2 1
1 2 1 2 1 2 1 2 1 2
2 1 2 1 2 1 2 1 2 1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">7</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/appie701" target="_blank" rel="noreferrer noopener">appie701</a>, <a href="https://www.acmicpc.net/user/crookid" target="_blank" rel="noreferrer noopener">crookid</a>, <a href="https://www.acmicpc.net/user/esuperstar" target="_blank" rel="noreferrer noopener">esuperstar</a>, <a href="https://www.acmicpc.net/user/raboribus" target="_blank" rel="noreferrer noopener">raboribus</a>, <a href="https://www.acmicpc.net/user/rlatpwlsdlek" target="_blank" rel="noreferrer noopener">rlatpwlsdlek</a>, <a href="https://www.acmicpc.net/user/stack" target="_blank" rel="noreferrer noopener">stack</a>, <a href="https://www.acmicpc.net/user/vjerksen" target="_blank" rel="noreferrer noopener">vjerksen</a></li>



<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/baekjoon">baek</a><a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">j</a><a href="https://www.acmicpc.net/user/baekjoon">oon</a></li>



<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/bluebrown" target="_blank" rel="noreferrer noopener">bluebrown</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-image size-full"><img decoding="async" width="389" height="284" src="https://lycos7560.com/wp-content/uploads/2023/02/image-75.png" alt="" class="wp-image-33204" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-75.png 389w, https://lycos7560.com/wp-content/uploads/2023/02/image-75-300x219.png 300w" sizes="(max-width: 389px) 100vw, 389px" /></figure>



<p class="has-medium-font-size">DFS 탐색</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="283" height="161" src="https://lycos7560.com/wp-content/uploads/2023/02/image-77.png" alt="" class="wp-image-33206"/></figure>



<p class="has-medium-font-size">BFS 탐색 (나는 예외 처리로 해결)</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">통과된 코드</h1>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>

using namespace std;

constexpr int MAX = 500;

int map[MAX][MAX];

bool checkMap[MAX][MAX];

int N, M, result = 0;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

void DFS_Search(int nowX, int nowY, int cnt, int val)
{
	if (cnt == 4) {
		result = max(result, val);
		return;
	}

	for (int i = 0; i &lt; 4; i++) {

		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];

		// 범위를 벗어나면 넘어간다.
		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) continue;
		// 방문했다면 넘어간다.
		if (checkMap[dx][dy] == true) continue;

		cnt++;
		val += map[dx][dy];
		checkMap[dx][dy] = true;
		DFS_Search(dx, dy, cnt, val);
		checkMap[dx][dy] = false;
		cnt--;
		val -= map[dx][dy];

	}
}

// 'ㅗ' 탐색을 위한 함수
void Exception_Search(int nowX, int nowY, int val)
{
	for (int i = 0; i &lt; 4; i++) {
		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];
		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) continue;
		val += map[dx][dy];
	}

	for (int i = 0; i &lt; 4; i++) {
		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];

		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) {
			result = max(result, val);
			continue;
		}

		val -= map[dx][dy];
		result = max(result, val);
		val += map[dx][dy];
	}

}


int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	std::cout.tie(NULL);

	cin >> N >> M;

	for (int i = 0; i &lt; N; i++) {
		for (int j = 0; j &lt; M; j++) {
			cin >> map[i][j];
		}
	}

	for (int i = 0; i &lt; N; i++) {
		for (int j = 0; j &lt; M; j++) {
			checkMap[i][j] = true;
			DFS_Search(i, j, 1, map[i][j]);
			checkMap[i][j] = false;
			Exception_Search(i, j, map[i][j]);
		}
	}

	cout &lt;&lt; result;

	return 0;
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/02/image-74.png" alt="" class="wp-image-33198" width="877" height="150" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-74.png 746w, https://lycos7560.com/wp-content/uploads/2023/02/image-74-300x51.png 300w" sizes="(max-width: 877px) 100vw, 877px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1292" height="646" src="https://lycos7560.com/wp-content/uploads/2023/02/image-79.png" alt="" class="wp-image-33209" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-79.png 1292w, https://lycos7560.com/wp-content/uploads/2023/02/image-79-300x150.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-79-768x384.png 768w" sizes="(max-width: 1292px) 100vw, 1292px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">추가 반례</h1>



<p><a href="https://www.acmicpc.net/board/view/61597" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/view/61597</a></p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6 10
3 3 6 4 1 4 8 5 3 2
9 5 1 2 4 1 9 9 5 5
2 5 1 2 3 3 3 7 6 4
1 6 5 6 4 7 4 7 7 4
3 8 5 9 6 4 2 6 1 1
6 3 3 7 1 2 2 2 8 4</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">33</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 4
1 1 1 1
2 1000 1 1
1 1000 2 1
1 1 1 1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2004</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 4
0 0 0 0
0 0 0 0
0 0 0 0
1 2 3 4

4 4
0 0 0 1
0 0 0 2
0 0 0 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 0 1 2
0 0 3 4

4 4
0 0 0 0
0 0 1 0
0 0 2 0
0 0 3 4

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 4 0 0

4 4
0 0 0 0
0 0 1 2
0 0 0 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 0 0 1
0 4 3 2

4 4
0 0 0 0
0 0 0 1
0 0 0 2
0 0 4 3

4 4
0 0 0 0
0 0 0 0
0 1 0 0
0 2 3 4

4 4
0 0 0 0
0 0 2 1
0 0 3 0
0 0 4 0

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 0 0 4

4 4
0 0 0 0
0 0 0 1
0 0 2 3
0 0 4 0

4 4
0 0 0 0
0 0 1 0
0 0 2 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 1 2 0
0 0 3 4

4 4
0 0 0 0
0 0 0 0
0 0 3 4
0 1 2 0

4 4
0 0 0 0
0 0 0 1
0 0 2 3
0 0 0 4

4 4
0 0 0 0
0 0 1 0
0 0 2 3
0 0 4 0

4 4
0 0 0 0
0 0 0 0
0 0 1 0
0 2 3 4

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 0 4 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/">백준 14500번 (테트로미노, C++) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1219번 (오민식의 고민, C++, Bellman–Ford) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1219%eb%b2%88-%ec%98%a4%eb%af%bc%ec%8b%9d%ec%9d%98-%ea%b3%a0%eb%af%bc-c-bellman-ford-baekjoon/33149/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1219%eb%b2%88-%ec%98%a4%eb%af%bc%ec%8b%9d%ec%9d%98-%ea%b3%a0%eb%af%bc-c-bellman-ford-baekjoon/33149/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 12 Feb 2023 18:38:37 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1219]]></category>
		<category><![CDATA[1219번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[Bellman–Ford]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[길찾기]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1219]]></category>
		<category><![CDATA[백준 1219번]]></category>
		<category><![CDATA[벨만-포드]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[오민식의 고민]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33149</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1219번 '오민식의 고민' 문제에 대한 글입니다. Bellman–Ford 알고리즘을 이용하여 해결하였습니다. (This is BAEKJOON's 1219, "오민식의 고민" Solved using Bellman–Ford algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1219%eb%b2%88-%ec%98%a4%eb%af%bc%ec%8b%9d%ec%9d%98-%ea%b3%a0%eb%af%bc-c-bellman-ford-baekjoon/33149/">백준 1219번 (오민식의 고민, C++, Bellman–Ford) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-00285461      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#오민식의-고민" class="uagb-toc-link__trigger">오민식의 고민</a><li class="uagb-toc__list"><a href="#주의-사항" class="uagb-toc-link__trigger">주의 사항</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a><li class="uagb-toc__list"><a href="#추가-반례" class="uagb-toc-link__trigger">추가 반례</a></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">오민식의 고민</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1219" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1219</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">10997</td><td class="has-text-align-left" data-align="left">2142</td><td class="has-text-align-left" data-align="left">1250</td><td class="has-text-align-left" data-align="left">16.718%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">오민식은 세일즈맨이다. </p>



<p class="has-medium-font-size">오민식의 회사 사장님은 오민식에게 물건을 최대한 많이 팔아서 최대 이윤을 남기라고 했다.</p>



<p class="has-medium-font-size">오민식은 고민에 빠졌다. 어떻게 하면 최대 이윤을 낼 수 있을까?</p>



<p class="has-medium-font-size">이 나라에는 N개의 도시가 있다. 도시는 0번부터 N-1번까지 번호 매겨져 있다. </p>



<p class="has-medium-font-size">오민식의 여행은&nbsp;A도시에서 시작해서 B도시에서 끝난다.</p>



<p class="has-medium-font-size">오민식이 이용할 수 있는 교통수단은 여러 가지가 있다. </p>



<p class="has-medium-font-size">오민식은 모든 교통수단의 출발 도시와 도착 도시를 알고 있고, 비용도 알고 있다. </p>



<p class="has-medium-font-size">게다가, 오민식은 각각의 도시를 방문할 때마다 벌 수 있는 돈을 알고있다. </p>



<p class="has-medium-font-size">이 값은 도시마다 다르며, 액수는 고정되어있다. 또, 도시를 방문할 때마다 그 돈을 벌게 된다.</p>



<p class="has-medium-font-size">오민식은 도착 도시에 도착할 때, 가지고 있는 돈의 액수를 최대로 하려고 한다. </p>



<p class="has-medium-font-size">이 최댓값을 구하는 프로그램을 작성하시오.</p>



<p class="has-medium-font-size">오민식이 버는 돈보다 쓰는 돈이 많다면, 도착 도시에 도착할 때 가지고 있는 돈의 액수가 음수가 될 수도 있다. </p>



<p class="has-medium-font-size">또, 같은 도시를 여러 번 방문할 수 있으며, 그 도시를 방문할 때마다 돈을 벌게 된다. </p>



<p class="has-medium-font-size">모든 교통 수단은 입력으로 주어진 방향으로만 이용할 수 있으며, 여러 번 이용할 수도 있다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 도시의 수 N과 시작 도시, 도착 도시 그리고 교통 수단의 개수 M이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄부터 M개의 줄에는 교통 수단의 정보가 주어진다. </p>



<p class="has-medium-font-size">교통 수단의 정보는 “시작 끝 가격”과 같은 형식이다. </p>



<p class="has-medium-font-size">마지막 줄에는 오민식이 각 도시에서 벌 수 있는 돈의 최댓값이 0번 도시부터 차례대로 주어진다.</p>



<p class="has-medium-font-size">N과 M은 50보다 작거나 같고, 돈의 최댓값과 교통 수단의 가격은 1,000,000보다 작거나 같은 음이 아닌 정수이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">첫째 줄에 도착 도시에 도착할 때, 가지고 있는 돈의 액수의 최댓값을 출력한다. </p>



<p class="has-medium-font-size">만약 오민식이 도착 도시에 도착하는 것이 불가능할 때는 &#8220;gg&#8221;를 출력한다.&nbsp;</p>



<p class="has-medium-font-size">그리고, 오민식이 도착 도시에 도착했을 때 돈을 무한히 많이 가지고 있을 수 있다면 &#8220;Gee&#8221;를 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 0 4 7
0 1 13
1 2 17
2 4 20
0 3 22
1 3 4747
2 0 10
3 4 10
0 0 0 0 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">-32</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 0 4 5
0 1 10
1 2 10
2 3 10
3 1 10
2 4 10
0 10 10 110 10</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Gee</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3 0 2 3
0 1 10
1 0 10
2 1 10
1000 1000 47000</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gg</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 4</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2 0 1 2
0 1 1000
1 1 10
11 11</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 4</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Gee</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 5</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1 0 0 1
0 0 10
7</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 5</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">7</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 6</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 0 4 7
0 1 13
1 2 17
2 4 20
0 3 22
1 3 4747
2 0 10
3 4 10
8 10 20 1 100000</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 6</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">99988</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>잘못된 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/gkgg123" target="_blank" rel="noreferrer noopener">gkgg123</a>,&nbsp;<a href="https://www.acmicpc.net/user/sait2000" target="_blank" rel="noreferrer noopener">sait2000</a></li>



<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a>,&nbsp;<a href="https://www.acmicpc.net/user/typhoon" target="_blank" rel="noreferrer noopener">typhoon</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/10" target="_blank" rel="noreferrer noopener">벨만–포드</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h1 class="wp-block-heading">주의 사항</h1>



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="1408" src="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230213_032410192.jpg" alt="" class="wp-image-33158" srcset="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230213_032410192.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230213_032410192-300x264.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230213_032410192-768x676.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230213_032410192-1536x1352.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">순환이 도착 지점에 영향을 줄 수 있도록 많은 시도가 필요하다. </p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1009" height="384" src="https://lycos7560.com/wp-content/uploads/2023/02/image-68.png" alt="" class="wp-image-33159" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-68.png 1009w, https://lycos7560.com/wp-content/uploads/2023/02/image-68-300x114.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-68-768x292.png 768w" sizes="(max-width: 1009px) 100vw, 1009px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">통과된 코드</h1>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;vector>

using namespace std;

constexpr int MAXN = 50;

constexpr long long int INF = -INT64_MAX;

long long int disArr[MAXN];

int N, S, D, M, V, U, W, G[MAXN];

bool check = false;

vector&lt;pair&lt;int, int>> graph[MAXN];

int main()
{
    ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
    // cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
    cin.tie(NULL);
    std::cout.tie(NULL);

    cin >> N >> S >> D >> M;

    // 교통 수단을 입력받는다.
    for (int i = 0; i &lt; M; i++) {
        cin >> V >> U >> W;
        // 단방향 교통수단 출발, 도착, 비용
        graph[V].push_back(make_pair(U, -W));
    }

    // 도시에서 버는 비용입력
    for (int i = 0; i &lt; N; i++) cin >> G[i];

    fill(disArr, disArr + MAXN, INF);

    disArr[S] = G[S];

    // N번 이후부터는 순환 체크
    // 순환이 있는지 충분히 확인
    for (int k = 1; k &lt;= N * 2; k++) { 
        for (int i = 0; i &lt; N; i++) { // 시작 정점
            for (int j = 0; j &lt; graph[i].size(); j++) {
                int v = graph[i][j].first; // 도착점
                int weight = graph[i][j].second; // 가중치

                if (disArr[i] == -INF) disArr[v] = -INF; // 출발지가 순환이라면 도착지도 순환
                else if (disArr[i] != INF &amp;&amp; disArr[i] + weight + G[v] > disArr[v]) {
                    disArr[v] = disArr[i] + weight + G[v]; // 업데이트

                    if (k >= N) disArr[v] = -INF; // 순환찾기
                }
            }
        }
    }

    if (disArr[D] == -INF) cout &lt;&lt; "Gee"; // 순환에 포함
    else if (disArr[D] == INF) cout &lt;&lt; "gg"; // 도착 불가능 
    else cout &lt;&lt; disArr[D];

    return 0;

}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1202" height="268" src="https://lycos7560.com/wp-content/uploads/2023/02/image-67.png" alt="" class="wp-image-33151" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-67.png 1202w, https://lycos7560.com/wp-content/uploads/2023/02/image-67-300x67.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-67-768x171.png 768w" sizes="(max-width: 1202px) 100vw, 1202px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">추가 반례</h1>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 0 4 6
0 1 10000
1 2 0
2 1 0
1 3 0
0 3 0
3 4 0
0 0 1 0 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Gee</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 0 0 0
1 2 3 4 5</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">50 0 49 50
0 1 0
1 2 0
2 3 0
3 4 0
4 5 0
5 6 0
6 7 0
7 8 0
8 9 0
9 10 0
10 11 0
11 12 0
12 13 0
13 14 0
14 15 0
15 16 0
16 17 0
17 18 0
18 19 0
19 20 0
20 21 0
21 22 0
22 23 0
23 24 0
24 25 0
25 26 0
26 27 0
27 28 0
28 29 0
29 30 0
30 31 0
31 32 0
32 33 0
33 34 0
34 35 0
35 36 0
36 37 0
37 38 0
38 39 0
39 40 0
40 41 0
41 42 0
42 43 0
43 44 0
44 45 0
45 46 0
46 47 0
47 48 0
48 49 0
49 0 0
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Gee</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 0 4 5
0 1 0
1 2 0
2 3 0
3 1 0
0 4 0
1 1 1 1 1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 0 3 4
0 1 0
0 3 5
1 2 0
2 1 0
0 5 5 10</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 F</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 0 4 5
0 1 10
1 2 10
2 3 10
3 1 10
2 4 10
0 10 10 110 10</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 F</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Gee</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1219%eb%b2%88-%ec%98%a4%eb%af%bc%ec%8b%9d%ec%9d%98-%ea%b3%a0%eb%af%bc-c-bellman-ford-baekjoon/33149/">백준 1219번 (오민식의 고민, C++, Bellman–Ford) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1219%eb%b2%88-%ec%98%a4%eb%af%bc%ec%8b%9d%ec%9d%98-%ea%b3%a0%eb%af%bc-c-bellman-ford-baekjoon/33149/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1865번 (웜홀, C++, Bellman–Ford) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1865%eb%b2%88-%ec%9b%9c%ed%99%80-c-bellman-ford-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33135/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1865%eb%b2%88-%ec%9b%9c%ed%99%80-c-bellman-ford-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33135/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 12 Feb 2023 14:53:28 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1865]]></category>
		<category><![CDATA[1865번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[Bellman–Ford]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[길찾기]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1865]]></category>
		<category><![CDATA[백준 1865번]]></category>
		<category><![CDATA[벨만-포드]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[웜홀]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33135</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1865번 '웜홀' 문제에 대한 글입니다. Bellman–Ford 알고리즘을 이용하여 해결하였습니다. (This is an article about the 'Warmhole' problem in BAEKJOON 1865. Solved using Bellman–Ford algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1865%eb%b2%88-%ec%9b%9c%ed%99%80-c-bellman-ford-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33135/">백준 1865번 (웜홀, C++, Bellman–Ford) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-f9b53ff3      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#웜홀" class="uagb-toc-link__trigger">웜홀</a><li class="uagb-toc__list"><a href="#풀이-방법" class="uagb-toc-link__trigger">풀이 방법</a><li class="uagb-toc__list"><a href="#풀이에-도움되는-글" class="uagb-toc-link__trigger">풀이에 도움되는 글</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">웜홀</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1865" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1865</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table><thead><tr><th>시간 제한</th><th>메모리 제한</th><th>제출</th><th>정답</th><th>맞힌 사람</th><th>정답 비율</th></tr></thead><tbody><tr><td>2 초</td><td>128 MB</td><td>36111</td><td>8293</td><td>5117</td><td>21.896%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">때는 2020년, 백준이는 월드나라의 한 국민이다. </p>



<p class="has-medium-font-size">월드나라에는 N개의 지점이 있고 N개의 지점 사이에는 M개의 도로와 W개의 웜홀이 있다. </p>



<p class="has-medium-font-size">(단 도로는 방향이 없으며 웜홀은 방향이 있다.) </p>



<p class="has-medium-font-size">웜홀은 시작 위치에서 도착 위치로 가는 하나의 경로인데, </p>



<p class="has-medium-font-size">특이하게도 도착을 하게 되면 시작을 하였을 때보다 시간이 뒤로 가게 된다.</p>



<p class="has-medium-font-size">웜홀 내에서는 시계가 거꾸로 간다고 생각하여도 좋다.</p>



<p class="has-medium-font-size">시간 여행을 매우 좋아하는 백준이는 한 가지 궁금증에 빠졌다.&nbsp;</p>



<p class="has-medium-font-size">한&nbsp;지점에서 출발을 하여서 시간여행을 하기 시작하여 다시 출발을 하였던 위치로 돌아왔을 때, </p>



<p class="has-medium-font-size">출발을 하였을 때보다 시간이 되돌아가 있는 경우가 있는지 없는지 궁금해졌다. </p>



<p class="has-medium-font-size">여러분은 백준이를 도와 이런 일이 가능한지 불가능한지 구하는 프로그램을 작성하여라.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫 번째 줄에는 테스트케이스의 개수 TC(1 ≤ TC ≤ 5)가 주어진다.</p>



<p class="has-medium-font-size">그리고 두 번째 줄부터 TC개의 테스트케이스가 차례로 주어지는데 각 테스트케이스의 첫 번째 줄에는 </p>



<p class="has-medium-font-size">지점의 수 N(1 ≤ N ≤ 500), 도로의 개수 M(1 ≤ M ≤ 2500), 웜홀의 개수 W(1 ≤ W ≤ 200)이 주어진다. </p>



<p class="has-medium-font-size">그리고 두 번째 줄부터 M+1번째 줄에 도로의 정보가 주어지는데 각 도로의 정보는 S, E, T 세 정수로 주어진다. </p>



<p class="has-medium-font-size">S와 E는 연결된 지점의 번호, T는 이 도로를 통해 이동하는데 걸리는 시간을 의미한다. </p>



<p class="has-medium-font-size">그리고 M+2번째 줄부터 M+W+1번째 줄까지 웜홀의 정보가 S, E, T 세 정수로 주어지는데 </p>



<p class="has-medium-font-size">S는 시작 지점, E는 도착 지점, T는 줄어드는 시간을 의미한다. </p>



<p class="has-medium-font-size">T는 10,000보다 작거나 같은 자연수 또는 0이다.</p>



<p class="has-medium-font-size">두 지점을 연결하는 도로가 한 개보다 많을 수도 있다. </p>



<p class="has-medium-font-size">지점의 번호는 1부터 N까지 자연수로 중복 없이 매겨져 있다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">TC개의 줄에 걸쳐서 만약에 시간이 줄어들면서 출발 위치로 돌아오는 것이 가능하면 YES, 불가능하면 NO를 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2
3 3 1
1 2 2
1 3 4
2 3 1
3 1 3
3 2 1
1 2 3
2 3 4
3 1 8</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">NO
YES</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/106" target="_blank" rel="noreferrer noopener">USA Computing Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/155" target="_blank" rel="noreferrer noopener">2006-2007 Season</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/158" target="_blank" rel="noreferrer noopener">USACO December 2006 Contest</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/697" target="_blank" rel="noreferrer noopener">Gold</a>&nbsp;1번</p>



<ul class="wp-block-list">
<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/artichoke42" target="_blank" rel="noreferrer noopener">artichoke42</a>,&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/10" target="_blank" rel="noreferrer noopener">벨만–포드</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<h1 class="wp-block-heading">풀이 방법</h1>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1430" height="1920" src="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230212_233800523.jpg" alt="" class="wp-image-33140" srcset="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230212_233800523.jpg 1430w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230212_233800523-223x300.jpg 223w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230212_233800523-768x1031.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230212_233800523-1144x1536.jpg 1144w" sizes="(max-width: 1430px) 100vw, 1430px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">풀이에 도움되는 글</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/board/view/72995" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/view/72995</a>   &lt;-  jh05013의 설명</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이 문제에는 여러 우여곡절의 역사가 있습니다. </p>



<p class="has-medium-font-size">그래서인지 시작점이 어디라는 언급이 전혀 없는데도 인터넷에 있는 거의 모든 풀이가 1을 시작 정점으로 잡고, </p>



<p class="has-medium-font-size">원래 dist[v] != INF이 들어가야 최단거리가 제대로 구해지는데 이걸 오히려 빼버리는 데다가, </p>



<p class="has-medium-font-size">왜 이걸 빼야 정답을 받는지는 설명을 안 하고 있습니다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading"><strong>1. 백준이가 출발을 어디서 하는가?</strong></h2>



<p class="has-medium-font-size">아무데서나 출발할 수 있습니다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading"><strong>2. 왜 시작 정점을 1로 정해도 풀리는가?</strong></h2>



<p class="has-medium-font-size">방금도 언급했듯이 인터넷에 있는 거의 모든 풀이는&nbsp;아래의 &#8220;코드 1&#8243;처럼 구현하고 있습니다. </p>



<p class="has-medium-font-size">그런데도 맞았습니다!!를 받는데,&nbsp;그건&nbsp;<strong>잘못된 구현이 오히려 이 문제에서는&nbsp;올바른 풀이가 되어서</strong>&nbsp;그렇습니다. </p>



<p class="has-medium-font-size">바로 dist[v] != INF를 검사하지 않는 것입니다. &#8220;코드 2&#8243;와 비교해 보세요.</p>



<p class="has-medium-font-size">코드 1은&nbsp;&#8220;dist[v] == INF&#8221;를 &#8220;v를 방문하지 않았다&#8221;가 아니라 &#8220;v를 방문했고,&nbsp;</p>



<p class="has-medium-font-size">v까지의 최단거리가 INF다&#8221;로 인식하고 있습니다. </p>



<p class="has-medium-font-size">그래서 이 코드는 이미 처음부터 모든 정점을 방문한 걸로&nbsp;착각을 하게 되는데, </p>



<p class="has-medium-font-size">덕분에 음수 사이클이 어디에 있든 항상 도달이 가능하기 때문에 정답을 받습니다.</p>



<p class="has-medium-font-size">어차피 모든 정점을 처음부터 방문하니까,&nbsp;dist[1] = 0은 이 코드에서는&nbsp;아무 의미가 없습니다.</p>



<p class="has-medium-font-size">dist[3] = 0을 하거나, 아예 이 줄을 빼도 맞습니다.</p>



<p class="has-medium-font-size">그렇다면 코드 1이 항상 코드 2보다 좋은 코드이냐? 그렇지 않습니다. </p>



<p class="has-medium-font-size">코드 1에서는 어떤 정점이 실제로 도달 가능한 정점인지 알 수 없기 때문에,&nbsp;<strong><u>코드 1은&nbsp;올바른 벨만 포드 구현이 아닙니다.</u></strong>&nbsp;</p>



<p class="has-medium-font-size">(즉 v가 실제로 도달 불가능한 정점이더라도 dist[v] != INF일 수 있습니다.)&nbsp;</p>



<p class="has-medium-font-size">단지 그 정보가 이 문제에서는 필요 없기 때문에 맞는 것뿐이고, </p>



<p class="has-medium-font-size">만약 문제가 &#8220;각 점까지의 최단거리를 구해라&#8221;였다면 코드 2처럼 하는 것이 좋습니다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-medium-font-size wp-block-heading"><strong>2-1. 코드 2는 왜 틀리는가?</strong></h3>



<p class="has-medium-font-size">아래의 &#8220;코드 2&#8243;처럼 구현했다면 오답 처리가 될 것입니다. </p>



<p class="has-medium-font-size">틀려야 되는 이유는 시작 정점으로부터 도달할 수 없는 음수 사이클을 못 찾기 때문입니다. </p>



<p class="has-medium-font-size">다시 말하면, 이렇게 구현했을 경우 한 점에서만 출발하면 안 됩니다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-medium-font-size wp-block-heading"><strong>2-2. 파이썬 float(&#8216;inf&#8217;)</strong></h3>



<p class="has-medium-font-size">float(&#8216;inf&#8217;)에 음수를 더해도 여전히 float(&#8216;inf&#8217;)이기 때문에, 이 경우에는 거리 갱신이 이루어지지 않습니다. </p>



<p class="has-medium-font-size">그래서 이 경우는 코드 2와 똑같이 동작합니다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-medium-font-size wp-block-heading"><strong>2-3. 그럼 제 강의 자료가 틀린 건가요?</strong></h3>



<p class="has-medium-font-size">당장&nbsp;<a href="https://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm" target="_blank" rel="noreferrer noopener">위키피디아만 봐도</a>&nbsp;dist[v] != INF 같은 게 안 보이지만, 그렇다고 그 자료가 틀린 건 아닙니다.</p>



<p class="has-medium-font-size">일반적으로, 알고리즘 설명이나 수도코드에서 ∞ 같은 게 나오면 &#8220;아주 큰 수&#8221;가 아니라 진짜로 무한대입니다. </p>



<p class="has-medium-font-size">파이썬으로 치면 float(&#8216;inf&#8217;)와 같습니다. </p>



<p class="has-medium-font-size">진짜로 무한대면 dist[v]가&nbsp;∞인지 여부와 관계없이&nbsp;거리 갱신을 다 해도 상관없습니다.</p>



<p class="has-medium-font-size">실제로 구현할 때는&nbsp;&#8220;무한히 큰 int&#8221;같은 건 없으니까, </p>



<p class="has-medium-font-size">도달을 아직 못 한 점에서는&nbsp;거리 갱신을 안 하는 식으로 우회하는 것일 뿐입니다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="has-medium-font-size wp-block-heading"><strong>3. 두 번째 방법으로 구현했으면&nbsp;어떻게 풀어야 하는가?</strong></h3>



<p class="has-medium-font-size">두 가지 방법이&nbsp;있습니다.</p>



<ul class="wp-block-list">
<li>시작 정점이 한 개일 필요는 없습니다. 모든 정점에서 &#8220;동시에&#8221; 시작할 수 있습니다. <br>그러려면&nbsp;거리 배열 전체를&nbsp;INF가 아닌 0으로 초기화하고 벨만 포드를 돌리면 됩니다.</li>



<li>그래도 꼭 시작 정점이 단 하나였으면 좋겠다고 생각하신다면, N+1번째 &#8220;가짜 정점&#8221;을 만들어서 <br>나머지 모든 정점으로 가중치 0의 간선을 긋고, 시작 정점을 N+1로 잡으면 됩니다. <br>그러면 모든 정점이 도달 가능하므로 음수 사이클이 어디에 있든 항상 찾을 수 있습니다.</li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">코드 1
INF = 2000000000
모든 dist[v] = INF
dist[1] = 0
N-1번 반복:
  모든 v에 대해:
    모든 간선에 대해 최단거리 갱신
모든 v에 대해:
  모든 간선에 대해 최단거리 갱신
  갱신이 한 번이라도 일어났으면 true

===

코드 2
INF = 2000000000
모든 dist[v] = INF
dist[1] = 0
N-1번 반복:
  dist[v] != INF인 모든 v에 대해:
    모든 간선에 대해 최단거리 갱신
dist[v] != INF인 모든 v에 대해:
  모든 간선에 대해 최단거리 갱신
  갱신이 한 번이라도 일어났으면 true
</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">통과된 코드</h1>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;vector>

using namespace std;

constexpr int MAXN = 501;

int disArr[MAXN];

int TC, N, M, W, S, E, T;

vector&lt;pair&lt;int, int>> graph[MAXN];

bool BellmanFord()
{
	cin >> N >> M >> W;

	vector&lt;pair&lt;int, int>> graph[MAXN];

	// 도로의 정보를 입력받는다.
	for (int i = 0; i &lt; M; i++) {
		cin >> S >> E >> T;
		// 양방향
		graph[S].push_back(make_pair(E, T));
		graph[E].push_back(make_pair(S, T));
	}

	// 웜홀의 정보를 입력받는다.
	for (int i = 0; i &lt; W; i++) {
		cin >> S >> E >> T;
		// 단방향
		graph[S].push_back(make_pair(E, -T));
	}

	// 출발은 어디에새 해도 상관이 없다.
	fill(disArr, disArr + MAXN, 0);

	// (모든 정점의 수 - 1) 번 확인한다.
	// N 번은 순환 체크
	for (int k = 1; k &lt;= N; k++) {
		for (int i = 1; i &lt;= N; i++) { // 시작 정점
			for (int j = 0; j &lt; graph[i].size(); j++) {
				int v = graph[i][j].first; // 도착점
				int weight = graph[i][j].second; // 가중치
	
				// 시작 임시 배열의 가중치가 도착지의 가중치보다 크다면
				if (disArr[i] + weight &lt; disArr[v]) {
					disArr[v] = disArr[i] + weight;

					// K == N 일때 새로 업데이트 된다는 의미
					if (k == N) return true; // 순환이 있음
					
				}
			}
		}
	}

	return false;
	// 순환이 없음
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	std::cout.tie(NULL);

	cin >> TC;

	for (int i = 0; i &lt; TC; i++) {

		if (BellmanFord()) cout &lt;&lt; "YES\n";
		else cout &lt;&lt; "NO\n";

	}

	return 0;
}</pre>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1037" height="138" src="https://lycos7560.com/wp-content/uploads/2023/02/image-66.png" alt="" class="wp-image-33138" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-66.png 1037w, https://lycos7560.com/wp-content/uploads/2023/02/image-66-300x40.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-66-768x102.png 768w" sizes="(max-width: 1037px) 100vw, 1037px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1865%eb%b2%88-%ec%9b%9c%ed%99%80-c-bellman-ford-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33135/">백준 1865번 (웜홀, C++, Bellman–Ford) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1865%eb%b2%88-%ec%9b%9c%ed%99%80-c-bellman-ford-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33135/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 27 Jan 2023 17:25:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1107]]></category>
		<category><![CDATA[1107번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[리모컨]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1107]]></category>
		<category><![CDATA[백준 1107번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<category><![CDATA[해결]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5678</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1107번 '리모컨' 문제에 대한 글입니다. 'Brute Force' 알고리즘을 이용하여 해결하였습니다.<br />
(This is an article about the 'remote control' problem in BAEKJOON 1107. Solved using the 'Brute Force' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/">백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">리모컨</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1107" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1107</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">82926</td><td class="has-text-align-left" data-align="left">20011</td><td class="has-text-align-left" data-align="left">13910</td><td class="has-text-align-left" data-align="left">22.624%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">수빈이는 TV를 보고 있다. 수빈이는 채널을 돌리려고 했지만, 버튼을 너무 세게 누르는&nbsp;바람에, 일부 숫자 버튼이 고장났다.</p>



<p class="has-medium-font-size">리모컨에는 버튼이 0부터 9까지 숫자, +와 -가 있다. +를 누르면 현재 보고있는 채널에서 +1된 채널로 이동하고, </p>



<p class="has-medium-font-size">-를 누르면 -1된 채널로 이동한다. 채널 0에서 -를 누른 경우에는 채널이 변하지 않고, 채널은 무한대 만큼 있다.</p>



<p class="has-medium-font-size">수빈이가 지금 이동하려고 하는 채널은 N이다. 어떤 버튼이 고장났는지 주어졌을 때, </p>



<p class="has-medium-font-size">채널 N으로 이동하기 위해서 버튼을 최소 몇 번 눌러야하는지 구하는 프로그램을 작성하시오. </p>



<p class="has-medium-font-size">수빈이가 지금 보고 있는 채널은 100번이다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 수빈이가 이동하려고 하는 채널 N (0 ≤ N ≤ 500,000)이 주어진다.  </p>



<p class="has-medium-font-size">둘째 줄에는 고장난 버튼의 개수 M (0 ≤ M ≤ 10)이 주어진다. </p>



<p class="has-medium-font-size">고장난 버튼이 있는 경우에는 셋째 줄에는 고장난 버튼이 주어지며, 같은 버튼이 여러 번 주어지는 경우는 없다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">첫째 줄에 채널 N으로 이동하기 위해 버튼을 최소 몇 번 눌러야 하는지를 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5457
3
6 7 8</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">100
5
0 1 2 3 4</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">500000
8
0 2 3 4 6 7 8 9</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">11117</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 4</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">100
3
1 0 5</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 4</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 5</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">14124
0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 5</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 6</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1
9
1 2 3 4 5 6 7 8 9</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 6</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 7</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">80000
2
8 9</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 7</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2228</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0
9
1 2 3 4 5 6 7 8 9</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">140200
3
4 5 6</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">207</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1555
3
0 1 9</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">670</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">99999
9
0 2 3 4 5 6 7 8 9</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">11118</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">50000
9
0 1 2 3 4 5 6 7 8</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">40005</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 F</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">139133
7
9 6 8 2 1 5 7</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 F</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">94694</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 G</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0
0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 G</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">힌트</h2>



<p class="has-medium-font-size">예제 1의 경우 5455++ 또는 5459&#8211;</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/applyoo" target="_blank" rel="noreferrer noopener">applyoo</a></li>



<li>문제를 번역한 사람: <a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>잘못된 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size">아래에서 위로 올라가는 방법도 있지만 위에서 아래로 내려가는 방법도 같이 생각해야한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;cmath>

using namespace std;

bool arr[10];

string str, strTemp;

int N, M, temp, cnt, target, result = INT32_MAX;

void dfs(string st, char ch)
{
	if (st.length() == str.length() + 1) return;
	st.push_back(ch);
	cnt = abs(target - atoi(st.c_str())) + st.length();
	result = min(cnt, result);

	for (int i = 0; i &lt; 10; i++) {
		if (arr[i] == true) continue;
		dfs(st, i + '0');
	}
}

int main()
{
	cin >> str >> M;

	target = atoi(str.c_str());

	for (int i = 0; i &lt; M; i++) {
		cin >> temp;
		arr[temp] = true;
	}
	
	for (int i = 0; i &lt; 10; i++) {
		if (arr[i] == true) continue;
		dfs(strTemp, i + '0');
	}

	result = min(abs(target - 100), result);

	cout &lt;&lt; result;

	return 0;
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">문자열로 접근하니까 속도가 너무 느리다&#8230;.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1245" height="160" src="https://lycos7560.com/wp-content/uploads/2023/01/image-30.png" alt="" class="wp-image-5679" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-30.png 1245w, https://lycos7560.com/wp-content/uploads/2023/01/image-30-300x39.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-30-768x99.png 768w" sizes="(max-width: 1245px) 100vw, 1245px" /></figure>



<div style="height:38px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/">백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1620번 (나는야 포켓몬 마스터 이다솜, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1620%eb%b2%88-%eb%82%98%eb%8a%94%ec%95%bc-%ed%8f%ac%ec%bc%93%eb%aa%ac-%eb%a7%88%ec%8a%a4%ed%84%b0-%ec%9d%b4%eb%8b%a4%ec%86%9c-c-baekjoon/5586/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1620%eb%b2%88-%eb%82%98%eb%8a%94%ec%95%bc-%ed%8f%ac%ec%bc%93%eb%aa%ac-%eb%a7%88%ec%8a%a4%ed%84%b0-%ec%9d%b4%eb%8b%a4%ec%86%9c-c-baekjoon/5586/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 26 Jan 2023 12:15:26 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1620]]></category>
		<category><![CDATA[1620번]]></category>
		<category><![CDATA[atoi]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[unordered_map]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[나는야 포켓몬 마스터 이다솜]]></category>
		<category><![CDATA[문자]]></category>
		<category><![CDATA[문자열]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1620]]></category>
		<category><![CDATA[백준 1620번]]></category>
		<category><![CDATA[숫자의 합]]></category>
		<category><![CDATA[시간]]></category>
		<category><![CDATA[시간 초과]]></category>
		<category><![CDATA[시간초과]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[자료 구조]]></category>
		<category><![CDATA[자료구조]]></category>
		<category><![CDATA[집합]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<category><![CDATA[해시]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5586</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1620번 '나는야 포켓몬 마스터 이다솜' 문제에 대한 글입니다. 'array'과 'unordered_map' 자료 구조를 이용하여 해결하였습니다. (This is an article about the issue of BAEKJOON No. 1620 I am Pokemon Master Lee Da-som. We solved it using the data structure of 'array' and 'unordered_map'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1620%eb%b2%88-%eb%82%98%eb%8a%94%ec%95%bc-%ed%8f%ac%ec%bc%93%eb%aa%ac-%eb%a7%88%ec%8a%a4%ed%84%b0-%ec%9d%b4%eb%8b%a4%ec%86%9c-c-baekjoon/5586/">백준 1620번 (나는야 포켓몬 마스터 이다솜, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">나는야 포켓몬 마스터 이다솜</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1620" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1620</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">64247</td><td class="has-text-align-left" data-align="left">22477</td><td class="has-text-align-left" data-align="left">16798</td><td class="has-text-align-left" data-align="left">33.746%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="489" height="333" src="https://lycos7560.com/wp-content/uploads/2023/01/image.png" alt="" class="wp-image-5588" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image.png 489w, https://lycos7560.com/wp-content/uploads/2023/01/image-300x204.png 300w" sizes="(max-width: 489px) 100vw, 489px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">안녕? 내 이름은 이다솜. 나의 꿈은 포켓몬 마스터야. </p>



<p class="has-medium-font-size">일단 포켓몬 마스터가 되기 위해선 포켓몬을 한 마리 잡아야겠지? 근처 숲으로 가야겠어.</p>



<p class="has-medium-font-size">(뚜벅 뚜벅)</p>



<p class="has-medium-font-size">얏! 꼬렛이다. 꼬렛? 귀여운데, 나의 첫 포켓몬으로 딱 어울린데? 내가 잡고 말겠어. 가라! 몬스터볼~</p>



<p class="has-medium-font-size">(펑!) 헐랭&#8230; 왜 안 잡히지?ㅜㅜ 몬스터 볼만 던지면 되는 게 아닌가&#8230;ㅜㅠ</p>



<p class="has-medium-font-size">(터벅터벅)</p>



<p class="has-medium-font-size">어? 누구지?</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="492" height="331" src="https://lycos7560.com/wp-content/uploads/2023/01/image-1.png" alt="" class="wp-image-5589" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-1.png 492w, https://lycos7560.com/wp-content/uploads/2023/01/image-1-300x202.png 300w" sizes="(max-width: 492px) 100vw, 492px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">오박사 : 나는 태초마을의 포켓몬 박사 오민식 박사라네. </p>



<p class="has-medium-font-size">다솜아, 포켓몬을 잡을 때는, 일단 상대 포켓몬의 체력을 적당히 바닥으로 만들어놓고 몬스터 볼을 던져야 한단다. </p>



<p class="has-medium-font-size">자, 내 포켓몬 이상해꽃으로 한번 잡아보렴. 포켓몬의 기술을 쓰는 것을 보고 </p>



<p class="has-medium-font-size">포켓몬을 줄지 안줄지 결정을 하겠네. 자 한번 해보아라. 다솜아.</p>



<p class="has-medium-font-size">이다솜 : 이상해꽃이라&#8230;음.. 꽃이니깐 왠지 햇빛을 받아서 공격을 할 것 같은데&#8230; 음&#8230; 이상해꽃! 햇빛공격!!!</p>



<p class="has-medium-font-size">(꼬렛이 이상해꽃에게 공격을 받아 체력이 25 감소했다.)    </p>



<p class="has-medium-font-size">가라! 몬스터 볼!!!    (꼬렛을 잡았습니다.)    야호! 신난다. 꼬렛을 잡았다.</p>



<p class="has-medium-font-size">오박사 : 오우!! 방금 쓴 공격은 솔라빔이라고 하네.. 어떻게 공격을 한 건가? </p>



<p class="has-medium-font-size">솔라빔이란 공격에 대해서 공부를 한 건가?</p>



<p class="has-medium-font-size">이다솜 : 꽃이니깐 왠지 햇빛을 제대로 받으면 광합성을 해서 음.. 그냥 그럴 것 같아서요 ☞☜</p>



<p class="has-medium-font-size">오박사 : 다른 아이들은 넝쿨채찍이나, 나뭇잎 공격을 하는데, 다솜이는 역시 뭔가 다르구나. </p>



<p class="has-medium-font-size">그럼 나와 함께 연구소로 가자꾸나. 내가 포켓몬을 한 마리 줄 테니, 너의 꿈을 펼쳐보아라. 꿈은 이루어진단다.</p>



<p class="has-medium-font-size">이다솜 : 네! 오박사님, 고마워요.ㅜㅜ</p>



<p class="has-medium-font-size">오박사 : 가자. 나의 연구소는 너의 옆집의 아랫집이란다. 같이 가도록하자. 지금 포켓몬을 주마.</p>



<p class="has-medium-font-size">이다솜 : 네. 야호!!</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="492" height="330" src="https://lycos7560.com/wp-content/uploads/2023/01/image-2.png" alt="" class="wp-image-5590" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-2.png 492w, https://lycos7560.com/wp-content/uploads/2023/01/image-2-300x201.png 300w" sizes="(max-width: 492px) 100vw, 492px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">오영식 : 어? 오박사님 얘는 누구인가요?</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="490" height="328" src="https://lycos7560.com/wp-content/uploads/2023/01/image-3.png" alt="" class="wp-image-5591" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-3.png 490w, https://lycos7560.com/wp-content/uploads/2023/01/image-3-300x201.png 300w" sizes="(max-width: 490px) 100vw, 490px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">오박사 : 얘는 너의 라이벌이 될 친구 이다솜이라고 하네. </p>



<p class="has-medium-font-size">자, 포켓몬을 한 마리 골라보도록 해봐라 다솜아. 레이디퍼스트 네가 먼저 골라봐라.</p>



<p class="has-medium-font-size">이다솜 : 저는 생각해둔 포켓몬이 있어요. 피카츄 골라도 될까요?</p>



<p class="has-medium-font-size">오박사 : 그래 여기 피카츄가 한 마리 있단다. 피카츄를 가져가거라.</p>



<p class="has-medium-font-size">오영식 : 그럼 저는 이브이를 가져가겠어요. 그럼 나중에 보자 이다솜.</p>



<p class="has-medium-font-size">이다솜 : 그럼 꼬렛을 다시 잡으러 가야겠다. 영식아, 그리고 민식박사님 빠잉!</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="484" height="319" src="https://lycos7560.com/wp-content/uploads/2023/01/image-4.png" alt="" class="wp-image-5592" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-4.png 484w, https://lycos7560.com/wp-content/uploads/2023/01/image-4-300x198.png 300w" sizes="(max-width: 484px) 100vw, 484px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이다솜 : 피카츄 공격!</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="485" height="324" src="https://lycos7560.com/wp-content/uploads/2023/01/image-5.png" alt="" class="wp-image-5593" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-5.png 485w, https://lycos7560.com/wp-content/uploads/2023/01/image-5-300x200.png 300w" sizes="(max-width: 485px) 100vw, 485px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">가라 몬스터 볼!</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="491" height="328" src="https://lycos7560.com/wp-content/uploads/2023/01/image-6.png" alt="" class="wp-image-5594" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-6.png 491w, https://lycos7560.com/wp-content/uploads/2023/01/image-6-300x200.png 300w" sizes="(max-width: 491px) 100vw, 491px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이다솜 : 야호! 신난다. 꼬렛을 잡았다!!!!!</p>



<p class="has-medium-font-size">이다솜 : 그럼! 일단 사천왕을 이기고 오겠어!</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="485" height="331" src="https://lycos7560.com/wp-content/uploads/2023/01/image-7.png" alt="" class="wp-image-5595" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-7.png 485w, https://lycos7560.com/wp-content/uploads/2023/01/image-7-300x205.png 300w" sizes="(max-width: 485px) 100vw, 485px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이다솜 : 여기가 사천왕과 대결하려면 가야하는 곳인가..</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="489" height="325" src="https://lycos7560.com/wp-content/uploads/2023/01/image-8.png" alt="" class="wp-image-5596" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-8.png 489w, https://lycos7560.com/wp-content/uploads/2023/01/image-8-300x199.png 300w" sizes="(max-width: 489px) 100vw, 489px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">경비원 : 사천왕과 대결을 하려면, 마을의 체육관 리더를 이겨서 배지를 8개를 모아야 한다네&#8230; 배지를 모아서 오도록 하게</p>



<p class="has-medium-font-size">이다솜 : 잉ㅠㅜ&#8230; 그럼 배지부터 모아야 하는구나ㅠㅜㅠㅜ 나쁘당 그냥 좀 봐주지..</p>



<p class="has-medium-font-size">&lt;1 년 후&gt;</p>



<p class="has-medium-font-size">그동안의 줄거리 : 이다솜은 일단 상록 숲의 체육관 리더에게 도전을 했다. </p>



<p class="has-medium-font-size">하지만 상록숲 체육관의 리더는 실종된 상태. 따라서 회색마을부터 도전하기로 했다. </p>



<p class="has-medium-font-size">체육관의 리더를 이기면서, 로켓단을 해체시키기도 하고, 여러 가지 사건도 있었다. </p>



<p class="has-medium-font-size">결국 전설의 포켓몬도 잡고, 이제 사천왕을 이기려고 도전하기로 했다. </p>



<p class="has-medium-font-size">사천왕은 모두 가볍게 이기고, 이제 마지막 라이벌 오!영!식! 이다.</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="492" height="330" src="https://lycos7560.com/wp-content/uploads/2023/01/image-9.png" alt="" class="wp-image-5597" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-9.png 492w, https://lycos7560.com/wp-content/uploads/2023/01/image-9-300x201.png 300w" sizes="(max-width: 492px) 100vw, 492px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">오영식 : 훗. 1년 전의 그 이다솜이 사천왕을 이기고 현재 포켓몬 마스터인 나에게 덤벼? 어디 한번 덤벼보시지.</p>



<p class="has-medium-font-size">이다솜 : 헐랭&#8230; 나를 우습게보네&#8230;. 한번 두고 보시지! 그럼 대결이닷!</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="486" height="323" src="https://lycos7560.com/wp-content/uploads/2023/01/image-10.png" alt="" class="wp-image-5598" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-10.png 486w, https://lycos7560.com/wp-content/uploads/2023/01/image-10-300x199.png 300w" sizes="(max-width: 486px) 100vw, 486px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="487" height="328" src="https://lycos7560.com/wp-content/uploads/2023/01/image-11.png" alt="" class="wp-image-5599" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-11.png 487w, https://lycos7560.com/wp-content/uploads/2023/01/image-11-300x202.png 300w" sizes="(max-width: 487px) 100vw, 487px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="481" height="320" src="https://lycos7560.com/wp-content/uploads/2023/01/image-12.png" alt="" class="wp-image-5600" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-12.png 481w, https://lycos7560.com/wp-content/uploads/2023/01/image-12-300x200.png 300w" sizes="(max-width: 481px) 100vw, 481px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="490" height="997" src="https://lycos7560.com/wp-content/uploads/2023/01/image-13.png" alt="" class="wp-image-5601" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-13.png 490w, https://lycos7560.com/wp-content/uploads/2023/01/image-13-147x300.png 147w" sizes="(max-width: 490px) 100vw, 490px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="487" height="670" src="https://lycos7560.com/wp-content/uploads/2023/01/image-14.png" alt="" class="wp-image-5602" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-14.png 487w, https://lycos7560.com/wp-content/uploads/2023/01/image-14-218x300.png 218w" sizes="(max-width: 487px) 100vw, 487px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이다솜 : 휴&#8230; 이겼다.</p>



<p class="has-medium-font-size">오영식 : 내가 지다니 분하다. ㅜㅜ</p>



<p class="has-medium-font-size">오박사 : 그럼 다솜아 이제 진정한 포켓몬 마스터가 되기 위해 도감을 완성시키도록 하여라. </p>



<p class="has-medium-font-size">일단 네가 현재 가지고 있는 포켓몬 도감에서 포켓몬의 이름을 보면 포켓몬의 번호를 말하거나, </p>



<p class="has-medium-font-size">포켓몬의 번호를 보면 포켓몬의 이름을 말하는 연습을 하도록 하여라. </p>



<p class="has-medium-font-size">나의 시험을 통과하면, 내가 새로 만든 도감을 주도록 하겠네.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. </p>



<p class="has-medium-font-size">N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? </p>



<p class="has-medium-font-size">모르면 물어봐도 괜찮아. 나는 언제든지 질문에 답해줄 준비가 되어있어.</p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에 포켓몬의 번호가 1번인 포켓몬부터 N번에 해당하는 포켓몬까지 한 줄에 하나씩 입력으로 들어와. </p>



<p class="has-medium-font-size">포켓몬의 이름은 모두 영어로만 이루어져있고, 또, 음&#8230; 첫 글자만 대문자이고, 나머지 문자는 소문자로만 이루어져 있어. </p>



<p class="has-medium-font-size">아참! 일부 포켓몬은 마지막 문자만 대문자일 수도 있어. 포켓몬 이름의 최대 길이는 20, 최소 길이는 2야. </p>



<p class="has-medium-font-size">그 다음 줄부터 총 M개의 줄에 내가 맞춰야하는 문제가 입력으로 들어와. 문제가 알파벳으로만 들어오면 포켓몬 번호를 말해야 하고, </p>



<p class="has-medium-font-size">숫자로만 들어오면, 포켓몬 번호에 해당하는 문자를 출력해야해. </p>



<p class="has-medium-font-size">입력으로 들어오는 숫자는 반드시 1보다 크거나 같고, N보다 작거나 같고, </p>



<p class="has-medium-font-size">입력으로 들어오는 문자는 반드시 도감에 있는 포켓몬의 이름만 주어져. 그럼 화이팅!!!</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">첫째 줄부터 차례대로 M개의 줄에 각각의 문제에 대한 답을 말해줬으면 좋겠어!!!. </p>



<p class="has-medium-font-size">입력으로 숫자가 들어왔다면 그 숫자에 해당하는 포켓몬의 이름을, </p>



<p class="has-medium-font-size">문자가 들어왔으면 그 포켓몬의 이름에 해당하는 번호를 출력하면 돼. 그럼 땡큐~</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="263" height="243" src="https://lycos7560.com/wp-content/uploads/2023/01/image-15.png" alt="" class="wp-image-5604"/></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이게 오박사님이 나에게 새로 주시려고 하는 도감이야. </p>



<p class="has-medium-font-size">너무 가지고 싶다ㅠㅜ. 꼭 만점을 받아줬으면 좋겠어!! 파이팅!!!</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">26 5
Bulbasaur
Ivysaur
Venusaur
Charmander
Charmeleon
Charizard
Squirtle
Wartortle
Blastoise
Caterpie
Metapod
Butterfree
Weedle
Kakuna
Beedrill
Pidgey
Pidgeotto
Pidgeot
Rattata
Raticate
Spearow
Fearow
Ekans
Arbok
Pikachu
Raichu
25
Raichu
3
Pidgey
Kakuna</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Pikachu
26
Venusaur
16
14</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/frogyou2330" target="_blank" rel="noreferrer noopener">frogyou2330</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/175" target="_blank" rel="noreferrer noopener">자료 구조</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/136" target="_blank" rel="noreferrer noopener">해시를 사용한 집합과 맵</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size">주의할 점은 들어오는 문자열을 숫자와 문자로 구분하는 방법이다.</p>



<p class="has-medium-font-size">문제의 조건은 문자의 첫 인덱스는 숫자가 아니다. </p>



<p class="has-medium-font-size">그래서 문자열의 첫 인덱스를 숫자인지 문자인지 구분하여 해결하였다.</p>



<p class="has-medium-font-size">추가적으로 atoi() 를 사용하여 문자를 숫자로 변환해주었다. &lt;iostream></p>



<p class="has-medium-font-size">atoi는 해당하는 문자열이 숫자면 숫자를 반환한다</p>



<p class="has-medium-font-size">만약 해당하는 문자열이 숫자로 변환이 불가능하다면 아니라면 0을 반환</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;unordered_map>

using namespace std;

unordered_map&lt;string, int> uSortMap;

int N, M;
string strArr[100001];

int main()
{

	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> N >> M;
	
	for (int i = 1; i &lt;= N; i++) {
		cin >> strArr[0];
		strArr[i] = strArr[0];
		uSortMap.insert({ strArr[0], i });
	}

	for (int i = 0; i &lt; M; i++) {
		cin >> strArr[0];
		if (strArr[0][0] >= '0' &amp;&amp; strArr[0][0] &lt;= '9') {
			cout &lt;&lt; strArr[atoi(strArr[0].c_str())] &lt;&lt; "\n";
			// atoi(string.c_str())
			// atoi는 해당하는 문자열이 숫자면 숫자를 반환한다 
			// 만약 해당하는 문자열이 숫자로 변환이 불가능하다면 아니라면 0을 반환
		}
		else {
			cout &lt;&lt; uSortMap.find(strArr[0])->second &lt;&lt; "\n";
		} 
	}

	return 0;
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/01/image-16.png" alt="" class="wp-image-5606" width="1078" height="186" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-16.png 1437w, https://lycos7560.com/wp-content/uploads/2023/01/image-16-300x52.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-16-768x133.png 768w" sizes="(max-width: 1078px) 100vw, 1078px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1620%eb%b2%88-%eb%82%98%eb%8a%94%ec%95%bc-%ed%8f%ac%ec%bc%93%eb%aa%ac-%eb%a7%88%ec%8a%a4%ed%84%b0-%ec%9d%b4%eb%8b%a4%ec%86%9c-c-baekjoon/5586/">백준 1620번 (나는야 포켓몬 마스터 이다솜, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1620%eb%b2%88-%eb%82%98%eb%8a%94%ec%95%bc-%ed%8f%ac%ec%bc%93%eb%aa%ac-%eb%a7%88%ec%8a%a4%ed%84%b0-%ec%9d%b4%eb%8b%a4%ec%86%9c-c-baekjoon/5586/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 18500번 (미네랄 2, C++, Simulation) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 09:53:37 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[18500]]></category>
		<category><![CDATA[18500번]]></category>
		<category><![CDATA[2933]]></category>
		<category><![CDATA[2933번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[깊이]]></category>
		<category><![CDATA[깊이 우선 탐색]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[리스트]]></category>
		<category><![CDATA[미네랄]]></category>
		<category><![CDATA[미네랄 2]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 18500]]></category>
		<category><![CDATA[백준 18500번]]></category>
		<category><![CDATA[시간]]></category>
		<category><![CDATA[시간 초과]]></category>
		<category><![CDATA[시간초과]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5533</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 18500번 '미네랄 2' 문제에 대한 글입니다. '그래프 Search'을 이용하여 해결하였습니다.<br />
추가적인 테스트 케이스를 제시합니다. (This is BAEKJOON's 18500 article on the 'Mineral 2' problem. I solved it using 'Graph Search'.<br />
Present additional test cases.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/">백준 18500번 (미네랄 2, C++, Simulation) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">미네랄 2</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/18500" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/18500</a></p>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">2109</td><td class="has-text-align-left" data-align="left">713</td><td class="has-text-align-left" data-align="left">549</td><td class="has-text-align-left" data-align="left">34.355%</td></tr></tbody></table></figure>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">창영과 상근은 한 동굴을 놓고 소유권을 주장하고 있다. </p>



<p class="has-medium-font-size">두 사람은 막대기를 서로에게 던지는 방법을 이용해 누구의 소유 인지를 결정하기로 했다. </p>



<p class="has-medium-font-size">싸움은 동굴에서 벌어진다. 동굴에는 미네랄이 저장되어 있으며, 던진 막대기가 미네랄을 파괴할 수도 있다.</p>



<p class="has-medium-font-size">동굴은 R행 C열로 나타낼 수 있으며, R×C칸으로 이루어져 있다. </p>



<p class="has-medium-font-size">각 칸은 비어있거나 미네랄을 포함하고 있으며, 네 방향 중 하나로 인접한 미네랄이 포함된 두 칸은 같은 클러스터이다.</p>



<p class="has-medium-font-size">창영은 동굴의 왼쪽에 서있고, 상근은 오른쪽에 서있다. 두 사람은 턴을 번갈아가며 막대기를 던진다. </p>



<p class="has-medium-font-size">막대를 던지기 전에 던질 높이를 정해야 한다. 막대는 땅과 수평을 이루며 날아간다.</p>



<p class="has-medium-font-size">막대가 날아가다가 미네랄을 만나면, 그 칸에 있는 미네랄은 모두 파괴되고 막대는 그 자리에서 이동을 멈춘다.</p>



<p class="has-medium-font-size">미네랄이 파괴된 이후에 남은 클러스터가 분리될 수도 있다.  </p>



<p class="has-medium-font-size">새롭게 생성된 클러스터가 떠 있는 경우에는 중력에 의해서 바닥으로 떨어지게 된다. </p>



<p class="has-medium-font-size">떨어지는 동안 클러스터의 모양은 변하지 않는다. 클러스터는 다른 클러스터나 땅을 만나기 전까지 계속해서 떨어진다. </p>



<p class="has-medium-font-size">클러스터는 다른 클러스터 위에 떨어질 수 있고, 그 이후에는 합쳐지게 된다.</p>



<p class="has-medium-font-size">동굴에 있는 미네랄의 모양과 두 사람이 던진 막대의 높이가 주어진다. </p>



<p class="has-medium-font-size">모든 막대를 던지고 난 이후에 미네랄 모양을 구하는 프로그램을 작성하시오.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 동굴의 크기 R과 C가 주어진다. (1 ≤ R,C ≤ 100)</p>



<p class="has-medium-font-size">다음 R개 줄에는 C개의 문자가 주어지며, &#8216;.&#8217;는 빈 칸, &#8216;x&#8217;는 미네랄을 나타낸다.</p>



<p class="has-medium-font-size">다음 줄에는 막대를 던진 횟수 N이 주어진다. (1 ≤ N ≤ 100)</p>



<p class="has-medium-font-size">마지막 줄에는 막대를 던진 높이가 주어지며, 공백으로 구분되어져 있다. </p>



<p class="has-medium-font-size">모든 높이는 1과 R사이이며, 높이 1은 행렬의 가장 바닥, R은 가장 위를 의미한다. <br><br>첫 번째 막대는 왼쪽에서 오른쪽으로 던졌으며, 두 번째는 오른쪽에서 왼쪽으로, 이와 같은 식으로 번갈아가며 던진다.</p>



<p class="has-medium-font-size">공중에 떠 있는 미네랄 클러스터는 없으며, 두 개 또는 그 이상의 클러스터가 동시에 떨어지는 경우도 없다. </p>



<p class="has-medium-font-size"><s>클러스터가 떨어질 때,&nbsp;그 클러스터 각 열의 맨 아래 부분 중 하나가 바닥 또는 미네랄 위로 떨어지는 입력만 주어진다.</s></p>



<p>(2933번 문제와 차이)</p>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">입력 형식과 같은 형식으로 미네랄 모양을 출력한다.</p>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 6
......
..xx..
..x...
..xx..
.xxxx.
1
3</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">......
......
..xx..
..xx..
.xxxx.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8 8
........
........
...x.xx.
...xxx..
..xxx...
..x.xxx.
..x...x.
.xxx..x.
5
6 6 4 3 1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">........
........
........
........
.....x..
..xxxx..
..xxx.x.
..xxxxx.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">7 6
......
......
xx....
.xx...
..xx..
...xx.
....x.
2
6 4</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">......
......
......
......
..xx..
xx.xx.
.x..x.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">13 100
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..................................................x................................................x
..................................................x................................................x
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
11 
1 1 1 1 1 1 1 1 1 1 1 </pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..................................................x................................................x
...................................................................................................x</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">9 8
........
...xxx..
.xxx....
.x.x.xxx
.x.x...x
.x.xxx.x
.x.....x
.x.....x
.xxx...x
1
7</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">........
........
...xxx..
.xxx.xxx
.x.x...x
.x.x...x
.x.xxx.x
.x.....x
.xxx...x</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 4
xxxx
xx.x
x..x
...x
1
3</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">xxxx
.x.x
...x
x..x</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">7 5
.....
.xxx.
.x...
xx.xx
x...x
x...x
x...x
1
4</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">.....
.....
.xxx.
.x.xx
xx..x
x...x
x...x</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2 2
..
.x
1
2</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">..
.x</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 F</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 5
xxxxx
x....
xxxxx
x....
x....
10 1 2 3 4 5 1 2 3 4 5</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 F</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">.....
.....
.....
.xxxx
xxxx.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 G</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10 10
xxxxxxxxxx
....x.....
...xxx....
.....x....
....xx....
.....x....
xxxxxx....
..x.......
.xxxx.....
...xxxxxxx
10 9 8 7 6 5 4 3 2 1 1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 G</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">..........
..........
..........
..........
..........
..........
xxxxxxxxxx
....xx....
xxxxxx....
.xxxxxxxx.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 H</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 4
...x
..xx
.xxx
xxxx
10 1 2 3 4 1 2 3 4 3 4</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 H</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">....
....
.xxx
..xx</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 I</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">10 20
..xxxxxxxxxxxxxxx...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..xxxxxx........x...
................x...
x...............x...
2
1 7</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 I</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">....................
..xxxxxxxxxxxxxxx...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..x.............x...
..xxxxxx........x...
................x...</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 J</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">9 8
........
.xxxx...
.x......
.x.xxxx.
.x....x.
.x....x.
.xxxx.x.
....xxx.
......x.
1
2</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 J</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">........
........
.xxxx...
.x.xxxx.
.x....x.
.x....x.
.x....x.
.xxxxxx.
......x.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/25" target="_blank" rel="noreferrer noopener">Croatian Highschool Competitions in Informatics</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/29" target="_blank" rel="noreferrer noopener">2009</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/91" target="_blank" rel="noreferrer noopener">Croatian Regional Competition in Informatics 2009</a>&nbsp;5번</p>



<p><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/25" target="_blank" rel="noreferrer noopener">Croatian Highschool Competitions in Informatics</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/29" target="_blank" rel="noreferrer noopener">2009</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/1069" target="_blank" rel="noreferrer noopener">Regional Competition &#8211; Juniors</a>&nbsp;4번</p>



<ul class="wp-block-list">
<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/heize" target="_blank" rel="noreferrer noopener">heize</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/126" target="_blank" rel="noreferrer noopener">너비 우선 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/141" target="_blank" rel="noreferrer noopener">시뮬레이션</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="EG4OUsUyN9"><a href="https://lycos7560.com/?p=2163">백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/?p=2163&#038;embed=true#?secret=0JeHTukF6L#?secret=EG4OUsUyN9" data-secret="EG4OUsUyN9" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<p class="has-medium-font-size">나는 2933번을 해결할 때 공중에 있는 미네랄 리스트의  하단부를 전부 확인하는 방법으로 구현해서 다른 것이 없다.</p>



<p class="has-medium-font-size">골드 2 문제를 해결하니 골드 1을 같이 주네?? 개꿀 </p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;list>
#include &lt;queue>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// 방문처리 
bool mapCheck[MAX][MAX];

// BFS 사용할 Q
queue&lt;pair&lt;int, int>> myQ;

pair&lt;int, int> tempP;

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int dx, dy, dis;

int temp = 0;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };


list&lt;int> myList;
list&lt;int>::iterator it;

list&lt;pair&lt;int, int>> cList;
list&lt;pair&lt;int, int>>::iterator cit;

// true = left, false = right
bool check = false, leftRight = false;

void BFS(int x, int y)
{
	myQ.push(make_pair(x, y));

	while (!myQ.empty()) {
		tempP = myQ.front();
		myQ.pop();

		for (int i = 0; i &lt; 4; i++) {
			dy = tempP.second + dxdy[i][1];
			dx = tempP.first + dxdy[i][0];
			// 문제의 범위를 벗어나는 경우 => 넘어간다.
			if (dx &lt;= 0 || dy &lt;= 0 || dy > C || dx > R) continue;
			// 방문 처리가 되었거나 빈공간 => 넘어간다.
			if (mapCheck[dx][dy] == true || map[dx][dy] == '.') continue;
			mapCheck[dx][dy] = true;
			myQ.push(make_pair(dx, dy));
		}
	}
}

void CheckFloor() // 바닥을 체크합니다.
{
	for (int y = 1; y &lt;= C; y++) {
		// 바닥에 클러스터가 발견되고 방문처리가 되지 않았다면 
		if (map[1][y] == 'x' &amp;&amp; mapCheck[1][y] == false) {
			BFS(1, y); // BFS로 마킹
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {

		check = false; // 미네랄 부셔짐 체크 해제
		cList.clear(); // 공중의 미네랄 리스트 초기화

		// 해당 위치에 미네랄이 있는지 검색합니다.
		if (leftRight) { // 좌측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}

		if (check) {  // 미네랄이 부셔졌다면
			// 공중에 있는 클러스트들을 리스트에 담는다.
			for (int x = R; x >= 1; x--) {
				for (int y = C; y >= 1; y--) {
					if (map[x][y] == 'x' &amp;&amp; mapCheck[x][y] == false) {
						cList.push_back(make_pair(x, y));
					}
				}
			}

			// 공중에 미네랄이 바닥과 연결될때까지 반복
			dis = 1;
			bool floor = true;
			while (floor) {

				if (cList.size() == 0) break;

				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;

					if (mapCheck[tempP.first - (dis + 1)][tempP.second] == true || tempP.first - (dis + 1) == 0) {
						floor = false;
						break;
					}
				}

				dis++;
			}

			if (!floor) {
				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;
					map[tempP.first][tempP.second] = '.';
				}

				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;
					map[tempP.first - (dis - 1)][tempP.second] = 'x';
				}	
			}

			// 방문 처리를 초기화 
			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					mapCheck[x][y] = false;
				}
			}
		}
	}

	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cout &lt;&lt; map[x][y];
		}
		if (x == 1) break;
		cout &lt;&lt; "\n";
	}

	return 0;

}</pre>



<div style="height:57px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1035" height="104" src="https://lycos7560.com/wp-content/uploads/image-1058.png" alt="" class="wp-image-5539" srcset="https://lycos7560.com/wp-content/uploads/image-1058.png 1035w, https://lycos7560.com/wp-content/uploads/image-1058-300x30.png 300w, https://lycos7560.com/wp-content/uploads/image-1058-768x77.png 768w" sizes="(max-width: 1035px) 100vw, 1035px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/">백준 18500번 (미네랄 2, C++, Simulation) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18500%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-2-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5533/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 06:00:03 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[18500]]></category>
		<category><![CDATA[18500번]]></category>
		<category><![CDATA[2933]]></category>
		<category><![CDATA[2933번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[깊이]]></category>
		<category><![CDATA[깊이 우선 탐색]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[리스트]]></category>
		<category><![CDATA[미네랄]]></category>
		<category><![CDATA[미네랄 2]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 2933]]></category>
		<category><![CDATA[백준 2933번]]></category>
		<category><![CDATA[시간]]></category>
		<category><![CDATA[시간 초과]]></category>
		<category><![CDATA[시간초과]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=2163</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 2933번 '미네랄' 문제에 대한 글입니다. '그래프 Search'을 이용하여 해결하였습니다.<br />
추가적인 테스트 케이스를 제시합니다. (This is BAEKJOON's 2933 article on the 'Mineral' problem. I solved it using 'Graph Search'.<br />
Present additional test cases.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/">백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div style="height:42px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">미네랄</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/2933" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/2933</a></p>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table is-style-regular"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">10752</td><td class="has-text-align-left" data-align="left">2935</td><td class="has-text-align-left" data-align="left">1917</td><td class="has-text-align-left" data-align="left">25.250%</td></tr></tbody></table></figure>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">창영과 상근은 한 동굴을 놓고 소유권을 주장하고 있다. </p>



<p class="has-medium-font-size">두 사람은 막대기를 서로에게 던지는 방법을 이용해 누구의 소유 인지를 결정하기로 했다. <br><br>싸움은 동굴에서 벌어진다. 동굴에는 미네랄이 저장되어 있으며, 던진 막대기가 미네랄을 파괴할 수도 있다.</p>



<p class="has-medium-font-size">동굴은 R행 C열로 나타낼 수 있으며, R×C칸으로 이루어져 있다. </p>



<p class="has-medium-font-size">각 칸은 비어있거나 미네랄을 포함하고 있으며, 네 방향 중 하나로 인접한 미네랄이 포함된 두 칸은 같은 클러스터이다.</p>



<p class="has-medium-font-size">창영은 동굴의 왼쪽에 서있고, 상근은 오른쪽에 서있다. 두 사람은 턴을 번갈아가며 막대기를 던진다. </p>



<p class="has-medium-font-size">막대를 던지기 전에 던질 높이를 정해야 한다. 막대는 땅과 수평을 이루며 날아간다.</p>



<p class="has-medium-font-size">막대가 날아가다가 미네랄을 만나면, 그 칸에 있는 미네랄은 모두 파괴되고 막대는 그 자리에서 이동을 멈춘다.</p>



<p class="has-medium-font-size">미네랄이 파괴된 이후에 남은 클러스터가 분리될 수도 있다.  </p>



<p class="has-medium-font-size">새롭게 생성된 클러스터가 떠 있는 경우에는 중력에 의해서 바닥으로 떨어지게 된다. <br><br>떨어지는 동안 클러스터의 모양은 변하지 않는다. 클러스터는 다른 클러스터나 땅을 만나기 전까지 계속해서 떨어진다. <br><br>클러스터는 다른 클러스터 위에 떨어질 수 있고, 그 이후에는 합쳐지게 된다.</p>



<p class="has-medium-font-size">동굴에 있는 미네랄의 모양과 두 사람이 던진 막대의 높이가 주어진다. </p>



<p class="has-medium-font-size">모든 막대를 던지고 난 이후에 미네랄 모양을 구하는 프로그램을 작성하시오.</p>



<div style="height:34px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 동굴의 크기 R과 C가 주어진다. (1 ≤ R,C ≤ 100)</p>



<p class="has-medium-font-size">다음 R개 줄에는 C개의 문자가 주어지며, &#8216;.&#8217;는 빈 칸, &#8216;x&#8217;는 미네랄을 나타낸다.</p>



<p class="has-medium-font-size">다음 줄에는 막대를 던진 횟수 N이 주어진다. (1 ≤ N ≤ 100)</p>



<p class="has-medium-font-size">마지막 줄에는 막대를 던진 높이가 주어지며, 공백으로 구분되어져 있다. </p>



<p class="has-medium-font-size">모든 높이는 1과 R사이이며, 높이 1은 행렬의 가장 바닥, R은 가장 위를 의미한다. <br><br>첫 번째 막대는 왼쪽에서 오른쪽으로 던졌으며, 두 번째는 오른쪽에서 왼쪽으로, 이와 같은 식으로 번갈아가며 던진다.</p>



<p class="has-medium-font-size">공중에 떠 있는 미네랄 클러스터는 없으며, 두 개 또는 그 이상의 클러스터가 동시에 떨어지는 경우도 없다. </p>



<p class="has-medium-font-size">클러스터가 떨어질 때,&nbsp;그 클러스터 각 열의 맨 아래 부분 중 하나가 바닥 또는 미네랄 위로 떨어지는 입력만 주어진다.</p>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">입력 형식과 같은 형식으로 미네랄 모양을 출력한다.</p>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 6
......
..xx..
..x...
..xx..
.xxxx.
1
3</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">......
......
..xx..
..xx..
.xxxx.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8 8
........
........
...x.xx.
...xxx..
..xxx...
..x.xxx.
..x...x.
.xxx..x.
5
6 6 4 3 1</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">........
........
........
........
.....x..
..xxxx..
..xxx.x.
..xxxxx.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">7 6
......
......
xx....
.xx...
..xx..
...xx.
....x.
2
6 4</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">......
......
......
......
..xx..
xx.xx.
.x..x.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">13 100
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..................................................x................................................x
..................................................x................................................x
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
..................................................x.................................................
11 
1 1 1 1 1 1 1 1 1 1 1 </pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..................................................x................................................x
...................................................................................................x</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 4
xxxx
xx.x
x..x
...x
1
3</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 B</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">xxxx
.x.x
...x
x..x</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2 2
..
.x
1
2</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 C</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">..
.x</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 5
xxxxx
x....
xxxxx
x....
x....
10 1 2 3 4 5 1 2 3 4 5</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 D</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">.....
.....
.....
.xxxx
xxxx.</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 4
...x
..xx
.xxx
xxxx
10 1 2 3 4 1 2 3 4 3 4</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 E</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">....
....
.xxx
..xx</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>잘못된 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>



<li>어색한 표현을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/porrshe">po</a><a href="https://www.acmicpc.net/user/porrshe" target="_blank" rel="noreferrer noopener">rrshe</a></li>
</ul>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/126" target="_blank" rel="noreferrer noopener">너비 우선 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/141" target="_blank" rel="noreferrer noopener">시뮬레이션</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size">첫째 줄에 동굴의 크기 R과 C (1 ≤ R,C ≤ 100)</p>



<p class="has-medium-font-size">다음 R개 줄에는 C개의 문자가 주어지며, &#8216;.&#8217;는 빈 칸, &#8216;x&#8217;는 미네랄을 나타낸다.</p>



<p class="has-medium-font-size">다음 줄에는 막대를 던진 횟수 N이 주어진다. (1 ≤ N ≤ 100)</p>



<p class="has-medium-font-size">모든 높이는 1과 R사이이며, 높이 1은 행렬의 가장 바닥, R은 가장 위를 의미한다.</p>



<p class="has-medium-font-size">공중에 떠 있는 미네랄 클러스터는 없으며, 두 개 또는 그 이상의 클러스터가 동시에 떨어지는 경우도 없다.</p>



<p class="has-medium-font-size"> 클러스터가 떨어질 때,&nbsp;그 클러스터 각 열의 맨 아래 부분 중 하나가 바닥 또는 미네랄 위로 떨어지는 입력만 주어진다.</p>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size">예제 1</p>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="650" height="438" src="https://lycos7560.com/wp-content/uploads/image-30.png" alt="" class="wp-image-2173" srcset="https://lycos7560.com/wp-content/uploads/image-30.png 650w, https://lycos7560.com/wp-content/uploads/image-30-300x202.png 300w" sizes="(max-width: 650px) 100vw, 650px" /></figure>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size">예제 2</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1307" height="813" src="https://lycos7560.com/wp-content/uploads/image-32.png" alt="" class="wp-image-2177" srcset="https://lycos7560.com/wp-content/uploads/image-32.png 1307w, https://lycos7560.com/wp-content/uploads/image-32-300x187.png 300w, https://lycos7560.com/wp-content/uploads/image-32-768x478.png 768w" sizes="(max-width: 1307px) 100vw, 1307px" /></figure>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size">예제 3</p>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="788" height="553" src="https://lycos7560.com/wp-content/uploads/image-35.png" alt="" class="wp-image-2181" srcset="https://lycos7560.com/wp-content/uploads/image-35.png 788w, https://lycos7560.com/wp-content/uploads/image-35-300x211.png 300w, https://lycos7560.com/wp-content/uploads/image-35-768x539.png 768w" sizes="(max-width: 788px) 100vw, 788px" /></figure>



<div style="height:83px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이번에도 문제를 이해하는 것이 오래 걸렸다.. 일단 글을 읽으면 머리 속에서 잘 정리가 되지 않는다. </p>



<p class="has-medium-font-size">한 3~4 번을 다시 글을 읽은 후에야 어느 정도 이해를 하는 듯&#8230;.</p>



<p class="has-medium-font-size">일단 동굴을 코드로 구현해보자</p>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include&lt;iostream>
#include&lt;list>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int temp = 0;


list&lt;int> myList;
list&lt;int>::iterator it;

bool debug = true;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0){
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	if (debug) {
		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
	}
	return 0;
}
</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">다행히 생각대로 잘나온다.</p>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1052.png" alt="" class="wp-image-5501" width="806" height="453" srcset="https://lycos7560.com/wp-content/uploads/image-1052.png 639w, https://lycos7560.com/wp-content/uploads/image-1052-300x169.png 300w" sizes="(max-width: 806px) 100vw, 806px" /></figure>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:46px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 막대기를 던져서 해당 위치의 미네랄을 파괴하는 것까지 구현</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include&lt;iostream>
#include&lt;list>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int temp = 0;


list&lt;int> myList;
list&lt;int>::iterator it;

bool debug = true;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {
		// 해당 위치에 미네랄이 있는지 검색합니다.
		// 일단은 좌->우 검색
		for (int x = 1; x &lt;= C; x++) {
			// 만약 미네랄이 있다면
			if (map[*it][x] == 'x') {
				cout &lt;&lt; "\n찾음\n";
				// 해당 미네랄을 빈 공간
				map[*it][x] = '.';
				break;
			}
		}
	}




	if (debug) {
		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
	}
	return 0;
}
</pre>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="719" height="557" src="https://lycos7560.com/wp-content/uploads/image-1053.png" alt="" class="wp-image-5505" srcset="https://lycos7560.com/wp-content/uploads/image-1053.png 719w, https://lycos7560.com/wp-content/uploads/image-1053-300x232.png 300w" sizes="(max-width: 719px) 100vw, 719px" /></figure>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 좌/우에서 던지는 것을 구현해야 한다.</p>



<p class="has-medium-font-size">2가지 경우 좌/우 이므로 bool 값으로 체크해서 막대기를 던지는 것을 구현하였다.</p>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include&lt;iostream>
#include&lt;list>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int temp = 0;


list&lt;int> myList;
list&lt;int>::iterator it;

// true = left, false = right
bool leftRight = true;

bool debug = true;

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {
		
		// 해당 위치에 미네랄이 있는지 검색합니다.
		// 일단은 좌->우 검색
		if (leftRight) { // 좌측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					cout &lt;&lt; "\n찾음\n";
					// 해당 미네랄을 빈 공간
					map[*it][y] = '.';
					break;
				}
			}
			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					cout &lt;&lt; "\n찾음\n";
					// 해당 미네랄을 빈 공간
					map[*it][y] = '.';
					break;
				}
			}
			leftRight = !leftRight;
		}

	}

	if (debug) {
		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
	}
	return 0;
}
</pre>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="730" height="545" src="https://lycos7560.com/wp-content/uploads/image-1054.png" alt="" class="wp-image-5508" srcset="https://lycos7560.com/wp-content/uploads/image-1054.png 730w, https://lycos7560.com/wp-content/uploads/image-1054-300x224.png 300w" sizes="(max-width: 730px) 100vw, 730px" /></figure>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">생각대로 미네랄이 잘 파괴가 되는 것 같다.</p>



<p class="has-medium-font-size">이제 미네랄이 파괴 되었을 경우 여기서 말하는 클러스터(상하좌우가 연결된 미네랄 덩이)가 </p>



<p class="has-medium-font-size">공중에 떠있지 못하게 하기만 하면 끝일 것 같은데&#8230;. 방법이 문제다.</p>



<p class="has-medium-font-size">미네랄이 파괴되면 바닥과 연결된 미네랄을 모두 마킹해 주었다. </p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;list>
#include &lt;queue>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// 방문처리 
bool mapCheck[MAX][MAX];

// BFS 사용할 Q
queue&lt;pair&lt;int, int>> myQ;

pair&lt;int, int> tempP;

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int dx, dy;

int temp = 0;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };


list&lt;int> myList;
list&lt;int>::iterator it;

// true = left, false = right
bool check = false, leftRight = true;

bool debug = true;

void BFS(int x, int y)
{
	myQ.push(make_pair(x, y));

	while (!myQ.empty()) {
		tempP = myQ.front();
		myQ.pop();

		for (int i = 0; i &lt; 4; i++) {
			dy = tempP.second + dxdy[i][1];
			dx = tempP.first + dxdy[i][0];
			// 문제의 범위를 벗어나는 경우 => 넘어간다.
			if (dx &lt;= 0 || dy &lt;= 0 || dx > C || dy > R) continue;  // &lt;= 범위 틀림 기록용으로 남겨둠
			// 방문 처리가 되었거나 빈공간 => 넘어간다.
			if (mapCheck[dx][dy] == true || map[dx][dy] == '.') continue;
			mapCheck[dx][dy] = true;
			myQ.push(make_pair(dx, dy));
		}
	}

}

void CheckFloor() // 바닥을 체크합니다.
{
	for (int y = 1; y &lt;= C; y++) {
		// 바닥에 클러스터가 발견되고 방문처리가 되지 않았다면 
		if (map[1][y] == 'x' &amp;&amp; mapCheck[1][y] == false) {
			BFS(1, y); // BFS로 마킹
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {
		
		// 해당 위치에 미네랄이 있는지 검색합니다.
		// 일단은 좌->우 검색
		if (leftRight) { // 좌측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;

				}
			}

			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}

		if (check) {  // 미네랄이 부셔졌다면 방문처리 초기화
			// 방문 처리를 초기화 
			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					mapCheck[x][y] = false;
				}
			}
			check = false;
		}

	}

	if (debug) {

		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
	}

	return 0;

}
</pre>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="940" height="478" src="https://lycos7560.com/wp-content/uploads/image-41.png" alt="" class="wp-image-2190" srcset="https://lycos7560.com/wp-content/uploads/image-41.png 940w, https://lycos7560.com/wp-content/uploads/image-41-300x153.png 300w, https://lycos7560.com/wp-content/uploads/image-41-768x391.png 768w" sizes="(max-width: 940px) 100vw, 940px" /></figure>



<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">이제 공중에 있는 클러스터들의 좌표들을 저장하는 리스트를 만들고 확인</p>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;list>
#include &lt;queue>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// 방문처리 
bool mapCheck[MAX][MAX];

// BFS 사용할 Q
queue&lt;pair&lt;int, int>> myQ;

pair&lt;int, int> tempP;

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int dx, dy;

int temp = 0;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };


list&lt;int> myList;
list&lt;int>::iterator it;

list&lt;pair&lt;int, int>> cList;
list&lt;pair&lt;int, int>>::iterator cit;

// true = left, false = right
bool check = false, leftRight = true;

bool debug = true;

void BFS(int x, int y)
{
	myQ.push(make_pair(x, y));

	while (!myQ.empty()) {
		tempP = myQ.front();
		myQ.pop();

		for (int i = 0; i &lt; 4; i++) {
			dy = tempP.second + dxdy[i][1];
			dx = tempP.first + dxdy[i][0];
			// 문제의 범위를 벗어나는 경우 => 넘어간다.
			if (dx &lt;= 0 || dy &lt;= 0 || dx > C || dy > R) continue; // &lt;= 범위 틀림 기록용으로 남겨둠
			// 방문 처리가 되었거나 빈공간 => 넘어간다.
			if (mapCheck[dx][dy] == true || map[dx][dy] == '.') continue;
			mapCheck[dx][dy] = true;
			myQ.push(make_pair(dx, dy));
		}
	}

}

void CheckFloor() // 바닥을 체크합니다.
{
	for (int y = 1; y &lt;= C; y++) {
		// 바닥에 클러스터가 발견되고 방문처리가 되지 않았다면 
		if (map[1][y] == 'x' &amp;&amp; mapCheck[1][y] == false) {
			BFS(1, y); // BFS로 마킹
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {
		cList.clear();
		// 해당 위치에 미네랄이 있는지 검색합니다.
		// 일단은 좌->우 검색
		if (leftRight) { // 좌측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;

				}
			}

			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}

		if (check) {  // 미네랄이 부셔졌다면

			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					if (map[x][y] == 'x' &amp;&amp; mapCheck[x][y] == false) {
						cList.push_back(make_pair(x, y));
					}
				}
			}


			// 방문 처리를 초기화 
			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					mapCheck[x][y] = false;
				}
			}
			check = false;
		}

	}

	if (debug) {

		for (int x = R; x >= 1; x--) {
			for (int y = 1; y &lt;= C; y++) {
				cout &lt;&lt; map[x][y] &lt;&lt; " ";
			}
			cout &lt;&lt; "\n";
		}
		cout &lt;&lt; "\n던진 막대기 높이 리스트\n";
		for (it = myList.begin(); it != myList.end(); it++) cout &lt;&lt; *it &lt;&lt; " ";
		cout &lt;&lt; "\n떠있는 클러스터 리스트 리스트\n";
		for (cit = cList.begin(); cit != cList.end(); cit++) cout &lt;&lt; " x : " &lt;&lt; cit->first &lt;&lt; " y : " &lt;&lt; cit->second &lt;&lt; "\n";
	}

	return 0;

}
</pre>



<div style="height:16px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:67px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/image-1055.png" alt="" class="wp-image-5514" width="859" height="593" srcset="https://lycos7560.com/wp-content/uploads/image-1055.png 786w, https://lycos7560.com/wp-content/uploads/image-1055-300x207.png 300w, https://lycos7560.com/wp-content/uploads/image-1055-768x531.png 768w" sizes="(max-width: 859px) 100vw, 859px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<p class="has-medium-font-size">미네랄이 파괴되면 바닥과 연결된 미네랄을 방문 처리해준다.</p>



<p class="has-medium-font-size">맵 전체에서 방문처리가 되지 않은 미네랄을 리스트에 담아준다</p>



<p class="has-medium-font-size">미네랄 리스트를 순회하면서 아래 부분이 방문 처리가 된 곳인지 확인한다. (내려갈 길이를 찾기 위함)</p>



<p class="has-medium-font-size">하단부가 방문처리가 되었다면 그 거리 -1 만큼 미네랄을 옮겨준다.</p>



<p class="has-medium-font-size">막대기의 수 만큼 위의 로직을 반복</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;list>
#include &lt;queue>

using namespace std;

// RC의 범위 최대값
constexpr int MAX = 101;

// 기본 맵
char map[MAX][MAX];

// 방문처리 
bool mapCheck[MAX][MAX];

// BFS 사용할 Q
queue&lt;pair&lt;int, int>> myQ;

pair&lt;int, int> tempP;

// R 행, C 열, N 막대기를 던진 횟수
int R, C, N;

int dx, dy, dis;

int temp = 0;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };


list&lt;int> myList;
list&lt;int>::iterator it;

list&lt;pair&lt;int, int>> cList;
list&lt;pair&lt;int, int>>::iterator cit;

// true = left, false = right
bool check = false, leftRight = false;

void BFS(int x, int y)
{
	myQ.push(make_pair(x, y));

	while (!myQ.empty()) {
		tempP = myQ.front();
		myQ.pop();

		for (int i = 0; i &lt; 4; i++) {
			dy = tempP.second + dxdy[i][1];
			dx = tempP.first + dxdy[i][0];
			// 문제의 범위를 벗어나는 경우 => 넘어간다.
			if (dx &lt;= 0 || dy &lt;= 0 || dy > C || dx > R) continue;
			// 방문 처리가 되었거나 빈공간 => 넘어간다.
			if (mapCheck[dx][dy] == true || map[dx][dy] == '.') continue;
			mapCheck[dx][dy] = true;
			myQ.push(make_pair(dx, dy));
		}
	}
}

void CheckFloor() // 바닥을 체크합니다.
{
	for (int y = 1; y &lt;= C; y++) {
		// 바닥에 클러스터가 발견되고 방문처리가 되지 않았다면 
		if (map[1][y] == 'x' &amp;&amp; mapCheck[1][y] == false) {
			BFS(1, y); // BFS로 마킹
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	// 처음 맵을 초기화 해준다.
	for (int x = 1; x &lt; MAX; x++) {
		for (int y = 1; y &lt; MAX; y++) {
			map[x][y] = '.';
		}
	}

	cin >> R >> C;

	// 미네랄의 위치를 설정 (아래서 부터 시작)
	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cin >> map[x][y];
		}
	}

	cin >> N;

	/// 던진 횟수와 높이를 설정
	while (N > 0) {
		cin >> temp;
		myList.push_back(temp);
		N--;
	}

	// 던진 막대기 리스트를 순회합니다.
	for (it = myList.begin(); it != myList.end(); it++) {

		check = false; // 미네랄 부셔짐 체크 해제
		cList.clear(); // 공중의 미네랄 리스트 초기화

		// 해당 위치에 미네랄이 있는지 검색합니다.
		if (leftRight) { // 좌측 검색
			for (int y = C; y >= 1; y--) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}
		else { // 우측 검색
			for (int y = 1; y &lt;= C; y++) {
				// 만약 미네랄이 있다면
				if (map[*it][y] == 'x') {
					// 해당 미네랄을 빈 공간으로 만든다.
					map[*it][y] = '.';
					// 바닥과 연결된 모든 클러스터를 방문처리
					CheckFloor();
					check = true;
					break;
				}
			}

			leftRight = !leftRight;
		}

		if (check) {  // 미네랄이 부셔졌다면
			// 공중에 있는 클러스트들을 리스트에 담는다.
			for (int x = R; x >= 1; x--) {
				for (int y = C; y >= 1; y--) {
					if (map[x][y] == 'x' &amp;&amp; mapCheck[x][y] == false) {
						cList.push_back(make_pair(x, y));
					}
				}
			}

			// 공중에 미네랄이 바닥과 연결될때까지 반복
			dis = 1;
			bool floor = true;
			while (floor) {

				if (cList.size() == 0) break;

				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;

					if (mapCheck[tempP.first - (dis + 1)][tempP.second] == true || tempP.first - (dis + 1) == 0) {
						floor = false;
						break;
					}
				}

				dis++;
			}

			if (!floor) {
				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;
					map[tempP.first][tempP.second] = '.';
				}

				for (cit = cList.begin(); cit != cList.end(); cit++) {
					tempP.first = cit->first;
					tempP.second = cit->second;
					map[tempP.first - (dis - 1)][tempP.second] = 'x';
				}	
			}

			// 방문 처리를 초기화 
			for (int x = R; x >= 1; x--) {
				for (int y = 1; y &lt;= C; y++) {
					mapCheck[x][y] = false;
				}
			}
		}
	}

	for (int x = R; x >= 1; x--) {
		for (int y = 1; y &lt;= C; y++) {
			cout &lt;&lt; map[x][y];
		}
		if (x == 1) break;
		cout &lt;&lt; "\n";
	}

	return 0;

}
</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><strong>계속 틀린 원인은 바닥과 연결된 클러스터를 찾는 BFS 탐색에서 R과 C의 범위를 바꾸어 탐색</strong></p>



<p class="has-medium-font-size">이 부분 하나로 엄청난 시간을 낭비</p>



<p class="has-medium-font-size">웃긴 부분은 다른 테스트 케이스는 다 잘돌아감 ㅋㅋ </p>



<p>구현이 조금 빡센 문제&#8230;</p>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1038" height="847" src="https://lycos7560.com/wp-content/uploads/image-1056.png" alt="" class="wp-image-5516" srcset="https://lycos7560.com/wp-content/uploads/image-1056.png 1038w, https://lycos7560.com/wp-content/uploads/image-1056-300x245.png 300w, https://lycos7560.com/wp-content/uploads/image-1056-768x627.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></figure>



<figure class="wp-block-image size-full"><img decoding="async" width="1039" height="453" src="https://lycos7560.com/wp-content/uploads/image-1057.png" alt="" class="wp-image-5517" srcset="https://lycos7560.com/wp-content/uploads/image-1057.png 1039w, https://lycos7560.com/wp-content/uploads/image-1057-300x131.png 300w, https://lycos7560.com/wp-content/uploads/image-1057-768x335.png 768w" sizes="(max-width: 1039px) 100vw, 1039px" /></figure>



<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/">백준 2933번 (미네랄, C++, Simulation) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2933%eb%b2%88-%eb%af%b8%eb%84%a4%eb%9e%84-c-simulation-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/2163/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1261번 (알고스팟, C++, Dijkstra) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1261%eb%b2%88-%ec%95%8c%ea%b3%a0%ec%8a%a4%ed%8c%9f-c-dijkstra-baekjoon/5348/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1261%eb%b2%88-%ec%95%8c%ea%b3%a0%ec%8a%a4%ed%8c%9f-c-dijkstra-baekjoon/5348/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 23 Jan 2023 14:55:28 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1261]]></category>
		<category><![CDATA[1261번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Dijkstra]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[priority_queue]]></category>
		<category><![CDATA[PriorityQueue]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[길찾기]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[다익스트라]]></category>
		<category><![CDATA[데이크스트라]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1261]]></category>
		<category><![CDATA[백준 1261번]]></category>
		<category><![CDATA[시간]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[알고스팟]]></category>
		<category><![CDATA[지름길]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5348</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1261번 '알고스팟' 문제에 대한 글입니다. Dijkstra 알고리즘을 이용하여 해결하였습니다. (This is an article about the 'Algospot' problem in BAEKJOON No. 1261. It was solved using Dijkstra algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1261%eb%b2%88-%ec%95%8c%ea%b3%a0%ec%8a%a4%ed%8c%9f-c-dijkstra-baekjoon/5348/">백준 1261번 (알고스팟, C++, Dijkstra) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">알고스팟</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1261" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1261</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">32215</td><td class="has-text-align-left" data-align="left">13759</td><td class="has-text-align-left" data-align="left">9339</td><td class="has-text-align-left" data-align="left">41.770%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">알고스팟 운영진이 모두 미로에 갇혔다. </p>



<p class="has-medium-font-size">미로는 N*M 크기이며, 총 1*1크기의 방으로 이루어져 있다. </p>



<p class="has-medium-font-size">미로는 빈 방 또는 벽으로 이루어져 있고, 빈 방은 자유롭게 다닐 수 있지만, 벽은 부수지 않으면 이동할 수 없다.</p>



<p class="has-medium-font-size">알고스팟 운영진은 여러명이지만, 항상 모두 같은 방에 있어야 한다. </p>



<p class="has-medium-font-size">즉, 여러 명이 다른 방에 있을 수는 없다. 어떤 방에서 이동할 수 있는 방은 상하좌우로 인접한 빈 방이다. </p>



<p class="has-medium-font-size">즉, 현재 운영진이 (x, y)에 있을 때, 이동할 수 있는 방은 (x+1, y), (x, y+1), (x-1, y), (x, y-1) 이다. </p>



<p class="has-medium-font-size">단, 미로의 밖으로 이동 할 수는 없다.</p>



<p class="has-medium-font-size">벽은 평소에는 이동할 수 없지만, 알고스팟의 무기 AOJ를 이용해 벽을 부수어 버릴 수 있다. </p>



<p class="has-medium-font-size">벽을 부수면, 빈 방과 동일한 방으로 변한다.</p>



<p class="has-medium-font-size">만약 이 문제가 <a href="https://www.algospot.com/" target="_blank" rel="noreferrer noopener">알고스팟</a>에 있다면, 운영진들은 궁극의 무기 sudo를 이용해 벽을 한 번에 다 없애버릴 수 있지만, </p>



<p class="has-medium-font-size">안타깝게도 이 문제는 <a href="https://www.acmicpc.net/" target="_blank" rel="noreferrer noopener">Baekjoon Online Judge</a>에 수록되어 있기 때문에, sudo를 사용할 수 없다.</p>



<p class="has-medium-font-size">현재 (1, 1)에 있는 알고스팟 운영진이 (N, M)으로 이동하려면 벽을 최소 몇 개 부수어야 하는지 구하는 프로그램을 작성하시오.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 미로의 크기를 나타내는 가로 크기 M, 세로 크기 N (1 ≤ N, M ≤ 100)이 주어진다. </p>



<p class="has-medium-font-size">다음 N개의 줄에는 미로의 상태를 나타내는 숫자 0과 1이 주어진다. </p>



<p class="has-medium-font-size">0은 빈 방을 의미하고, 1은 벽을 의미한다.</p>



<p class="has-medium-font-size">(1, 1)과 (N, M)은 항상 뚫려있다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">첫째 줄에 알고스팟 운영진이 (N, M)으로 이동하기 위해 벽을 최소 몇 개 부수어야 하는지 출력한다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3 3
011
111
110</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 2
0001
1000</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6 6
001111
010000
001111
110001
011010
100010</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1 1
0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">0</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">힌트</h2>



<p class="has-medium-font-size">이 문제는 <a href="https://algospot.com/judge/problem/read/BOJ" target="_blank" rel="noreferrer noopener">알고스팟</a>에서도 풀 수 있다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 각색한 사람: <a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/kuman514" target="_blank" rel="noreferrer noopener">kuman514</a></li>



<li>시간 제한을 수정한 사람: <a href="https://www.acmicpc.net/user/orihehe" target="_blank" rel="noreferrer noopener">orihehe</a></li>



<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/xhark" target="_blank" rel="noreferrer noopener">xhark</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/11" target="_blank" rel="noreferrer noopener">그래프 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/22" target="_blank" rel="noreferrer noopener">데이크스트라</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/176" target="_blank" rel="noreferrer noopener">0-1 너비 우선 탐색</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">처음부터 코드를 작성하기 싫어서 전에 해결한 문제의 코드를 가져와 풀었다.</p>



<figure class="wp-block-embed is-type-wp-embed is-provider-어제와-내일의-나-그-사이의-이야기 wp-block-embed-어제와-내일의-나-그-사이의-이야기"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="lVEJeP0HHR"><a href="https://lycos7560.com/?p=5335">백준 4485번 (녹색 옷 입은 애가 젤다지?, C++, Dijkstra) / 추가 반례 [BAEKJOON]</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;백준 4485번 (녹색 옷 입은 애가 젤다지?, C++, Dijkstra) / 추가 반례 [BAEKJOON]&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/?p=5335&#038;embed=true#?secret=krRJCRecIa#?secret=lVEJeP0HHR" data-secret="lVEJeP0HHR" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">위의 문제와 차이점은 </p>



<p class="has-medium-font-size">입력/출력 처리, [1][1]에서 시작하는 배열, 가로와 세로 크기 정도</p>



<p class="has-medium-font-size">최소비용을 구한다는 로직은 같다.</p>



<p class="has-medium-font-size">4485번을 해결하고 난 다음에 접한 문제라서 쉽게 해결하였다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;queue>
#include &lt;tuple>

using namespace std;

constexpr int MAXN = 101;
constexpr int INF = INT32_MAX;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

int M, N, nowX, nowY, dcost;

string str;

int map[MAXN][MAXN], dis[MAXN][MAXN];

tuple&lt;int, int, int> nowTuple;

// 가중치, x,y 좌표
priority_queue&lt;tuple&lt;int, int, int>> myPQ;


int main()
{
    ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
    // cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> M >> N;
    for (int i = 1; i &lt;= N; i++) {
        cin >> str;
        for (int j = 0; j &lt; M; j++) {
            map[i][j + 1] = str[j] - '0';
        }
    }

    // 2차원 배열 초기화
    // 전체 초기화 : 처음에는 [0][0]을 써주고, 
    // 그 다음 칸에는 [최대 행(값) - 1][최대 열], 다음 칸에는 초기 상태의 값
    // 범위내의 임시 노드를 무한대 변경
    fill(&amp;dis[0][0], &amp;dis[MAXN - 1][MAXN], INF);

    // 우선순위 큐를 이용하기 위하여 음수를 넣는 것을 기억하자
    myPQ.push(make_tuple(-map[1][1], 1, 1));
    dis[1][1] = 0; // 초기화

    while (!myPQ.empty()) {

        // 0번 인덱스 가중치, 1번 인덱스 X좌표, 2번 인덱스 Y좌표
        nowTuple = myPQ.top();
        myPQ.pop();

        if (get&lt;1>(nowTuple) == N &amp;&amp; get&lt;2>(nowTuple) == M) break;

        // 상/하/좌/우를 탐색하기 위한 반복문
        for (int i = 0; i &lt; 4; i++) {
            nowX = get&lt;1>(nowTuple) + dxdy[i][0];
            nowY = get&lt;2>(nowTuple) + dxdy[i][1];
            dcost = get&lt;0>(nowTuple) * -1;

            // 문제의 범위를 벗어나는 경우 => 넘어간다.
            if (nowX &lt;= 0 || nowY &lt;= 0 || nowX > M || nowY > N) continue;
            // 현재 위치의 최소 도둑루피 + 다음 칸의 도둑루피의 크기 >= 탐색 위치의 최소 도둑루피
            if (dcost + map[nowY][nowX] >= dis[nowY][nowX]) continue;
            else {
                // 임시 노드 업데이트
                dis[nowY][nowX] = dcost + map[nowY][nowX];
                myPQ.push(make_tuple(-dis[nowY][nowX], nowX, nowY));
            }
        }
    }

    cout &lt;&lt; dis[N][M];
    
    return 0;
}</pre>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1038" height="145" src="https://lycos7560.com/wp-content/uploads/image-1037.png" alt="" class="wp-image-5349" srcset="https://lycos7560.com/wp-content/uploads/image-1037.png 1038w, https://lycos7560.com/wp-content/uploads/image-1037-300x42.png 300w, https://lycos7560.com/wp-content/uploads/image-1037-768x107.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></figure>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">처음 큐에 넣을 때 dis[1][1] 값을 초기화 해주지 못해서 마지막 100% 검사에서 계속 틀렸다.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1 1 
0</pre>



<p class="has-medium-font-size">을 입력하니 MAXN 값이&#8230; 나와버리는 대참사</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1261%eb%b2%88-%ec%95%8c%ea%b3%a0%ec%8a%a4%ed%8c%9f-c-dijkstra-baekjoon/5348/">백준 1261번 (알고스팟, C++, Dijkstra) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1261%eb%b2%88-%ec%95%8c%ea%b3%a0%ec%8a%a4%ed%8c%9f-c-dijkstra-baekjoon/5348/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 4485번 (녹색 옷 입은 애가 젤다지?, C++, Dijkstra) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4485%eb%b2%88-%eb%85%b9%ec%83%89-%ec%98%b7-%ec%9e%85%ec%9d%80-%ec%95%a0%ea%b0%80-%ec%a0%a4%eb%8b%a4%ec%a7%80-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5335/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4485%eb%b2%88-%eb%85%b9%ec%83%89-%ec%98%b7-%ec%9e%85%ec%9d%80-%ec%95%a0%ea%b0%80-%ec%a0%a4%eb%8b%a4%ec%a7%80-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5335/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 23 Jan 2023 13:45:23 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1446]]></category>
		<category><![CDATA[1446번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Dijkstra]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[priority_queue]]></category>
		<category><![CDATA[PriorityQueue]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[길찾기]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[녹색 옷 입은 애가 젤다지?]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[다익스트라]]></category>
		<category><![CDATA[데이크스트라]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 4485]]></category>
		<category><![CDATA[백준 4485번]]></category>
		<category><![CDATA[시간]]></category>
		<category><![CDATA[시간 초과]]></category>
		<category><![CDATA[시간초과]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[지름길]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5335</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 4485번 "녹색 옷 입은 애가 젤다지?" 문제에 대한 글입니다.<br />
Dijkstra 알고리즘을 이용하여 해결하였습니다. (BAEKJOON No. 4485 "The one in green is Zelda, right?" This is an article about the problem.<br />
It was solved using Dijkstra algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4485%eb%b2%88-%eb%85%b9%ec%83%89-%ec%98%b7-%ec%9e%85%ec%9d%80-%ec%95%a0%ea%b0%80-%ec%a0%a4%eb%8b%a4%ec%a7%80-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5335/">백준 4485번 (녹색 옷 입은 애가 젤다지?, C++, Dijkstra) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-70d46d0a      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#녹색-옷-입은-애가-젤다지" class="uagb-toc-link__trigger">녹색 옷 입은 애가 젤다지?</a><li class="uagb-toc__list"><a href="#추가-반례" class="uagb-toc-link__trigger">추가 반례</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">녹색 옷 입은 애가 젤다지?</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/4485" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/4485</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">19015</td><td class="has-text-align-left" data-align="left">10017</td><td class="has-text-align-left" data-align="left">6934</td><td class="has-text-align-left" data-align="left">50.787%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">젤다의 전설 게임에서 화폐의 단위는 루피(rupee)다. </p>



<p class="has-medium-font-size">그런데 간혹 &#8216;도둑루피&#8217;라 불리는 검정색 루피도 존재하는데, 이걸 획득하면 오히려 소지한 루피가 감소하게 된다!</p>



<p class="has-medium-font-size">젤다의 전설 시리즈의 주인공, 링크는 지금 도둑루피만 가득한 N x N 크기의 동굴의 제일 왼쪽 위에 있다. </p>



<p class="has-medium-font-size">[0][0]번 칸이기도 하다. 왜 이런 곳에 들어왔냐고 묻는다면 </p>



<p class="has-medium-font-size">밖에서 사람들이 자꾸 &#8220;젤다의 전설에 나오는 녹색 애가 젤다지?&#8221;라고 물어봤기 때문이다. </p>



<p class="has-medium-font-size">링크가 녹색 옷을 입은 주인공이고 젤다는 그냥 잡혀있는 공주인데, 게임 타이틀에 젤다가 나와있다고 </p>



<p class="has-medium-font-size">자꾸 사람들이 이렇게 착각하니까 정신병에 걸릴 위기에 놓인 것이다.</p>



<p class="has-medium-font-size">하여튼 젤다&#8230;아니 링크는 이 동굴의 반대편 출구, 제일 오른쪽 아래 칸인 [N-1][N-1]까지 이동해야 한다. </p>



<p class="has-medium-font-size">동굴의 각 칸마다 도둑루피가 있는데, 이 칸을 지나면 해당 도둑루피의 크기만큼 소지금을 잃게 된다. </p>



<p class="has-medium-font-size">링크는 잃는 금액을 최소로 하여 동굴 건너편까지 이동해야 하며, 한 번에 상하좌우 인접한 곳으로 1칸씩 이동할 수 있다.</p>



<p class="has-medium-font-size">링크가 잃을 수밖에 없는 최소 금액은 얼마일까?</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">입력은 여러 개의 테스트 케이스로 이루어져 있다.</p>



<p class="has-medium-font-size">각 테스트 케이스의 첫째 줄에는 동굴의 크기를 나타내는 정수 N이 주어진다. </p>



<p class="has-medium-font-size">(2 ≤ N ≤ 125) N = 0인 입력이 주어지면 전체 입력이 종료된다.</p>



<p class="has-medium-font-size">이어서 N개의 줄에 걸쳐 동굴의 각 칸에 있는 도둑루피의 크기가 공백으로 구분되어 차례대로 주어진다. </p>



<p class="has-medium-font-size">도둑루피의 크기가 k면 이 칸을 지나면 k루피를 잃는다는 뜻이다. </p>



<p class="has-medium-font-size">여기서 주어지는 모든 정수는 0 이상 9 이하인 한 자리 수다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">각 테스트 케이스마다 한 줄에 걸쳐 정답을 형식에 맞춰서 출력한다. </p>



<p class="has-medium-font-size">형식은 예제 출력을 참고하시오.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3
5 5 4
3 9 1
3 2 7
5
3 7 2 0 1
2 8 0 9 1
1 2 1 8 1
9 8 9 2 0
3 6 5 1 5
7
9 0 5 1 1 5 3
4 1 2 1 6 5 3
0 7 6 1 6 8 5
1 1 7 8 3 2 3
9 4 0 7 6 4 1
5 8 3 2 4 8 3
7 4 8 4 8 3 4
0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Problem 1: 20
Problem 2: 19
Problem 3: 36</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">추가 반례</h1>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">25
7 8 7 6 0 1 5 3 4 9 0 0 7 2 9 7 0 4 2 7 5 0 5 2 4
0 0 9 6 1 2 2 1 1 2 9 2 0 7 6 6 7 1 6 4 4 0 4 1 1
9 0 3 9 2 5 1 2 9 8 4 6 8 2 3 8 7 9 5 5 2 0 9 5 4
9 8 0 4 0 6 7 1 4 7 7 8 6 7 6 0 5 7 4 6 1 9 4 2 6
0 3 7 5 7 2 9 2 8 7 4 2 8 9 6 9 6 2 4 2 0 9 9 5 2
3 8 4 2 9 8 2 0 2 1 8 2 8 6 5 2 9 2 1 1 9 5 9 0 2
5 6 3 9 4 6 6 7 9 9 1 5 5 7 0 8 4 8 5 9 9 6 7 3 4
4 5 0 6 9 4 5 3 8 4 6 9 6 7 5 8 5 5 5 7 9 7 7 1 4
6 6 6 9 4 2 5 8 8 5 0 3 0 7 7 3 3 7 4 5 0 2 0 4 7
3 3 7 2 5 6 3 3 7 0 2 0 2 6 2 6 7 5 6 8 5 2 8 1 9
5 7 5 8 2 3 5 2 7 9 7 0 2 1 1 4 4 9 2 1 2 1 4 2 3
2 7 8 9 6 9 6 0 8 0 4 0 2 2 3 3 8 1 7 0 2 4 2 2 9
5 4 0 5 6 4 2 3 9 2 0 3 5 6 4 0 3 7 0 9 4 4 7 2 3
8 2 1 1 6 9 8 3 8 4 3 6 5 4 2 3 5 6 1 0 3 2 6 4 3
9 9 5 9 2 6 3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A</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Problem 1: 110
Problem 2: 229
Problem 3: 0</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<p><a href="https://www.acmicpc.net/category/1" target="_blank" rel="noreferrer noopener">ICPC</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/8" target="_blank" rel="noreferrer noopener">North America</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/33" target="_blank" rel="noreferrer noopener">Pacific Northwest Regional</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/129" target="_blank" rel="noreferrer noopener">2008 Pacific Northwest Region Programming Contest</a>&nbsp;D번</p>



<ul class="wp-block-list">
<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/kks227" target="_blank" rel="noreferrer noopener">kks227</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/22" target="_blank" rel="noreferrer noopener">데이크스트라</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<div class="wp-block-file"><a id="wp-block-file--media-371d5215-e61f-4cd9-a6a2-b46634c9f468" href="https://lycos7560.com/wp-content/uploads/d_obstacle_course.7z" target="_blank" rel="noreferrer noopener">d_obstacle_course.z7</a><a href="https://lycos7560.com/wp-content/uploads/d_obstacle_course.7z" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-371d5215-e61f-4cd9-a6a2-b46634c9f468">다운로드</a></div>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size">이 문제는 [0, 0]에서 [n-1, n-1]까지 이동할 때, 가장 적게 잃을 수 있는 금액이 얼마인지에 대하여 구하는 문제입니다.</p>



<p class="has-medium-font-size">도둑 루피의 크기를 노드 사이의 비용으로 생각하면 최소비용을 구하는 문제와 같습니다. </p>



<p class="has-medium-font-size">map[MAXN][MAXN] 2차원 배열에 [i][j]로 이동하는 비용을 저장하고</p>



<p class="has-medium-font-size">dis[MAXN][MAXN] 2차원 배열에 Dijkstra 알고리즘으로 [i][j]의 최소 비용을 업데이트하여 문제를 해결하였습니다.</p>



<p class="has-medium-font-size">또한 우선순위 큐를 사용하여 최솟값 노드를 선택하는 방법을 사용했습니다. </p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">통과된 코드</h1>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;queue>
#include &lt;tuple>

using namespace std;

constexpr int MAXN = 125;
constexpr int INF = INT32_MAX;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

int N, nowX, nowY, dcost;

int map[MAXN][MAXN], dis[MAXN][MAXN];

tuple&lt;int, int, int> nowTuple;

// 가중치, x,y 좌표
priority_queue&lt;tuple&lt;int, int, int>> myPQ;

queue&lt;int> resQ;


int main()
{
	ios_base::sync_with_stdio(false); // scanf와 동기화를 비활성화
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	cin.tie(NULL);
	cout.tie(NULL);

	while (true) {
		cin >> N; // 테스트 케이스가 0이면 break;
		if (N == 0) break;

		// 2차원 배열 초기화
		// 전체 초기화 : 처음에는 [0][0]을 써주고, 
		// 그 다음 칸에는 [최대 행(값) - 1][최대 열], 다음 칸에는 초기 상태의 값
		// 범위내의 임시 노드를 무한대 변경
		fill(&amp;dis[0][0], &amp;dis[N - 1][N], INF);

		// 테스트 케이스의 입력을 받는다.
		for (int i = 0; i &lt; N; i++) {
			for (int j = 0; j &lt; N; j++) {
				cin >> map[i][j];
			}
		}

		// 우선순위 큐를 이용하기 위하여 음수를 넣는 것을 기억하자
		myPQ.push(make_tuple(-map[0][0], 0, 0));

		while (!myPQ.empty()){

			// 0번 인덱스 가중치, 1번 인덱스 X좌표, 2번 인덱스 Y좌표
			nowTuple = myPQ.top();
			myPQ.pop();

			if (get&lt;1>(nowTuple) == N - 1 &amp;&amp; get&lt;1>(nowTuple) == N - 2) break;

			// 상/하/좌/우를 탐색하기 위한 반복문
			for (int i = 0; i &lt; 4; i++) {
				nowX = get&lt;1>(nowTuple) + dxdy[i][0];
				nowY = get&lt;2>(nowTuple) + dxdy[i][1];
				dcost = get&lt;0>(nowTuple) * -1;

				// 문제의 범위를 벗어나는 경우 => 넘어간다.
				if (nowX &lt; 0 || nowY &lt; 0 || nowX >= N || nowY >= N) continue;
				// 현재 위치의 최소 도둑루피 + 다음 칸의 도둑루피의 크기 >= 탐색 위치의 최소 도둑루피
				if (dcost + map[nowX][nowY] >= dis[nowX][nowY]) continue;
				else {
					// 임시 노드 업데이트
					dis[nowX][nowY] = dcost + map[nowX][nowY];
					myPQ.push(make_tuple( -dis[nowX][nowY], nowX, nowY));
				}
			}
		}

		resQ.push(dis[N - 1][N - 1]);
	}

	int cnt = 1;
	while (!resQ.empty()){
		cout &lt;&lt; "Problem " &lt;&lt; cnt &lt;&lt; ": " &lt;&lt; resQ.front() &lt;&lt; "\n";
		resQ.pop();
		cnt++;
	}

	return 0;
}</pre>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1036" height="143" src="https://lycos7560.com/wp-content/uploads/image-1036.png" alt="" class="wp-image-5337" srcset="https://lycos7560.com/wp-content/uploads/image-1036.png 1036w, https://lycos7560.com/wp-content/uploads/image-1036-300x41.png 300w, https://lycos7560.com/wp-content/uploads/image-1036-768x106.png 768w" sizes="(max-width: 1036px) 100vw, 1036px" /></figure>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Priority_Queue 에 음수로 넣는 것을 깜빡해서 시간 초과가 발생하였다.</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4485%eb%b2%88-%eb%85%b9%ec%83%89-%ec%98%b7-%ec%9e%85%ec%9d%80-%ec%95%a0%ea%b0%80-%ec%a0%a4%eb%8b%a4%ec%a7%80-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5335/">백준 4485번 (녹색 옷 입은 애가 젤다지?, C++, Dijkstra) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-4485%eb%b2%88-%eb%85%b9%ec%83%89-%ec%98%b7-%ec%9e%85%ec%9d%80-%ec%95%a0%ea%b0%80-%ec%a0%a4%eb%8b%a4%ec%a7%80-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5335/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1446번 (지름길, C++, Dijkstra) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 23 Jan 2023 09:23:15 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1446]]></category>
		<category><![CDATA[1446번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Dijkstra]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[길찾기]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[다익스트라]]></category>
		<category><![CDATA[데이크스트라]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1446]]></category>
		<category><![CDATA[백준 1446번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[지름길]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<category><![CDATA[틀렸습니다!]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5322</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1446번 '지름길' 문제에 대한 글입니다. 'Dijkstra' 알고리즘을 이용하여 해결하였습니다. (백준(BAEKJOON) 1446번 '지름길' 문제에 대한 글입니다. 'Dijkstra' 알고리즘을 이용하여 해결하였습니다. (BAEKJOON 1446 This is about the 'shortcut' problem, solved using the 'Dijkstra' algorithm.))</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/">백준 1446번 (지름길, C++, Dijkstra) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">지름길</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1446" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1446</a></p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">5137</td><td class="has-text-align-left" data-align="left">2633</td><td class="has-text-align-left" data-align="left">1998</td><td class="has-text-align-left" data-align="left">50.995%</td></tr></tbody></table></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">문제</h2>



<p class="has-medium-font-size">매일 아침, 세준이는 학교에 가기 위해서 차를 타고 D킬로미터 길이의 고속도로를 지난다. </p>



<p class="has-medium-font-size">이 고속도로는 심각하게 커브가 많아서 정말 운전하기도 힘들다. </p>



<p class="has-medium-font-size">어느 날, 세준이는 이 고속도로에 지름길이 존재한다는 것을 알게 되었다. </p>



<p class="has-medium-font-size">모든 지름길은 일방통행이고, 고속도로를 역주행할 수는 없다.</p>



<p class="has-medium-font-size">세준이가 운전해야 하는 거리의 최솟값을 출력하시오.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">입력</h2>



<p class="has-medium-font-size">첫째 줄에 지름길의 개수 N과 고속도로의 길이 D가 주어진다. </p>



<p class="has-medium-font-size">N은 12 이하인 양의 정수이고, D는 10,000보다 작거나 같은 자연수이다. </p>



<p class="has-medium-font-size">다음 N개의 줄에 지름길의 시작 위치, 도착 위치, 지름길의 길이가 주어진다. </p>



<p class="has-medium-font-size">모든 위치와 길이는 10,000보다 작거나 같은 음이 아닌 정수이다. </p>



<p class="has-medium-font-size">지름길의 시작 위치는 도착 위치보다 작다.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출력</h2>



<p class="has-medium-font-size">세준이가 운전해야하는 거리의 최솟값을 출력하시오.</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5 150
0 50 10
0 50 20
50 100 10
100 151 10
110 140 90</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 1</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">70</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2 100
10 60 40
50 90 20</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 2</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">80</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 입력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8 900
0 10 9
20 60 45
80 190 100
50 70 15
160 180 14
140 160 14
420 901 5
450 900 0</pre>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">예제 출력 3</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">432</pre>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">출처</h2>



<ul class="wp-block-list">
<li>문제를 번역한 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>문제를 다시 작성한 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</a></li>
</ul>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">알고리즘 분류</h2>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/7" target="_blank" rel="noreferrer noopener">그래프 이론</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/22" target="_blank" rel="noreferrer noopener">데이크스트라</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<p class="has-medium-font-size">기본적인 로직은 Dujkstra 알고리즘을 기반으로 한다. </p>



<figure class="wp-block-embed is-type-wp-embed"><div class="wp-block-embed__wrapper">
<blockquote class="wp-embedded-content" data-secret="VztkgwMIoE"><a href="https://lycos7560.com/?p=5223">알고리즘 &#8211; 다익스트라/데이크스트라(Dijkstra) 알고리즘 정리 (길찾기)</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;알고리즘 &#8211; 다익스트라/데이크스트라(Dijkstra) 알고리즘 정리 (길찾기)&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/?p=5223&#038;embed=true#?secret=rNOzQBw4eP#?secret=VztkgwMIoE" data-secret="VztkgwMIoE" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide" style="margin-top:var(--wp--preset--spacing--80);margin-bottom:var(--wp--preset--spacing--80)"/>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="721" height="463" src="https://lycos7560.com/wp-content/uploads/image-1034.png" alt="" class="wp-image-5326" style="width:945px;height:607px" srcset="https://lycos7560.com/wp-content/uploads/image-1034.png 721w, https://lycos7560.com/wp-content/uploads/image-1034-300x193.png 300w" sizes="(max-width: 721px) 100vw, 721px" /></figure>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">주의사항</h2>



<p class="has-medium-font-size">주의할 점은 역주행이 불가능하다는 점 (현재 위치에서 지름길을 더한 값이 목적지를 넘어가면 안된다.)</p>



<p class="has-medium-font-size">또 지름길이 순서대로 이쁘게 주어지지 않는다. (정렬을 해서 처리하는 것도 하나의 방법)</p>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">내 풀이는 최단경로 테이블을 갱신하면 목적지 그 이후의 값을  dist[]가 더 적거나 목적지까지 +1 해주면서 업데이트 해주었다. </p>



<div style="height:54px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="745" height="439" src="https://lycos7560.com/wp-content/uploads/image-1035.png" alt="" class="wp-image-5328" style="width:867px;height:511px" srcset="https://lycos7560.com/wp-content/uploads/image-1035.png 745w, https://lycos7560.com/wp-content/uploads/image-1035-300x177.png 300w" sizes="(max-width: 745px) 100vw, 745px" /></figure>



<div style="height:63px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">통과된 코드</h2>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;vector>

using namespace std;

constexpr int MAXN = 10001;

// 지름길의 개수 N, 고속도로의 길이 D
int N, D;

int A, B, C;

/*
각 노드에 연결되어 있는 노드에 대한 정보를 담는 벡터
a번 노드에서 b번 노드로 가는 비용이 c라는 의미
graph[a].push_back({b, c});
*/
vector&lt;pair&lt;int, int>> graph[MAXN];

// 임시 노드
int dist[MAXN];

int main()
{
	// cin.tie(null); 코드는 cin과 cout의 묶음을 풀어줍니다.
	// scanf와 동기화를 비활성화
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> N >> D;

	for (int i = 0; i &lt; N; i++) {
		cin >> A >> B >> C;
		graph[A].push_back(make_pair(B, C));
	}

	// 기본 초기화
	for (int i = 0; i &lt; MAXN; i++) dist[i] = i;

	int now = 0;
	while (true) {

		if (now == D) { 
			// 목적지에 도착했으므로 결과를 출력
			cout &lt;&lt; dist[now];
			break;
		}

		// 해당 노드에서 연결된 모든 경로를 확인
        for (int i = 0; i &lt; graph[now].size(); i++) {

            // disSum = 임시 노드 + 현재 노드에서 i로가는 비용
            int disSum = dist[now] + graph[now][i].second;
			
			// 역주행을 해야할 경우는 continue
			if (disSum > D) continue; 


            // 비용이 더 작다면 최단경로 테이블 값을 갱신.
            if (disSum &lt; dist[graph[now][i].first]) {
                // 임시 노드 업데이트
				dist[graph[now][i].first] = disSum;

				// 만약 업데이트 했다면 그 이후의 정점들을 순차적으로 올려준다.
				for (int j = graph[now][i].first + 1; j &lt;= D ; j++) {
					// 만약  dist[j]이 더 작거나 같다면 최단거리가 있다는 의미 => Break
					if (disSum >= dist[j]) break;
					else dist[j] = ++disSum;
				}
            }
        }

		now++;
	}

	return 0;
}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1039" height="138" src="https://lycos7560.com/wp-content/uploads/image-1032.png" alt="" class="wp-image-5323" srcset="https://lycos7560.com/wp-content/uploads/image-1032.png 1039w, https://lycos7560.com/wp-content/uploads/image-1032-300x40.png 300w, https://lycos7560.com/wp-content/uploads/image-1032-768x102.png 768w" sizes="(max-width: 1039px) 100vw, 1039px" /></figure>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">dijkstra 알고리즘이 익숙하지 않아 해결하는데 오래 걸렸다&#8230;</p>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/">백준 1446번 (지름길, C++, Dijkstra) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1446%eb%b2%88-%ec%a7%80%eb%a6%84%ea%b8%b8-c-dijkstra-baekjoon/5322/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
