<?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/%ec%8b%9c%ea%b0%84%ec%b4%88%ea%b3%bc/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Fri, 24 Mar 2023 03:10:27 +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>백준 1613번 (역사, C++, Floyd-Warshall) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1613%eb%b2%88-%ec%97%ad%ec%82%ac-c-floyd-warshall-baekjoon/33239/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1613%eb%b2%88-%ec%97%ad%ec%82%ac-c-floyd-warshall-baekjoon/33239/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 18 Feb 2023 01:44:41 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1613]]></category>
		<category><![CDATA[1613번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Floyd-Warshall]]></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[백준 1613]]></category>
		<category><![CDATA[백준 1613번]]></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=33239</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1613번 '역사' 문제에 대한 글입니다. Floyd-Warshall 알고리즘을 이용하여 해결하였습니다. (This is BAEKJOON's 1613 'History' issue. It was solved using the Floyd-Warshall algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1613%eb%b2%88-%ec%97%ad%ec%82%ac-c-floyd-warshall-baekjoon/33239/">백준 1613번 (역사, C++, Floyd-Warshall) [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-6b88ed7e      "
					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/1613" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1613</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">13395</td><td class="has-text-align-left" data-align="left">4248</td><td class="has-text-align-left" data-align="left">3117</td><td class="has-text-align-left" data-align="left">34.196%</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">이를 해결하는 프로그램을 작성해 보도록 하자.</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(400 이하의 자연수)과 알고 있는 사건의 전후 관계의 개수 k(50,000 이하의 자연수)가 주어진다. </p>



<p class="has-medium-font-size">다음 k줄에는 전후 관계를 알고 있는 두 사건의 번호가 주어진다. </p>



<p class="has-medium-font-size">이는 앞에 있는 번호의 사건이 뒤에 있는 번호의 사건보다 먼저 일어났음을 의미한다.</p>



<p class="has-medium-font-size"> 물론 사건의 전후 관계가 모순인 경우는 없다. </p>



<p class="has-medium-font-size">다음에는 사건의 전후 관계를 알고 싶은 사건 쌍의 수 s(50,000 이하의 자연수)이 주어진다. </p>



<p class="has-medium-font-size">다음 s줄에는 각각 서로 다른 두 사건의 번호가 주어진다. </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">s줄에 걸쳐 물음에 답한다. </p>



<p class="has-medium-font-size">각 줄에 만일 앞에 있는 번호의 사건이 먼저 일어났으면 -1, </p>



<p class="has-medium-font-size">뒤에 있는 번호의 사건이 먼저 일어났으면 1, 어떤지 모르면(유추할 수 없으면) 0을 출력한다.</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
1 3
2 3
3 4
2 4
3
1 5
2 4
3 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="">0
-1
1</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/author5" target="_blank" rel="noreferrer noopener">author5</a></li>



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



<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/joonas" target="_blank" rel="noreferrer noopener">joonas</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/31" 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 fetchpriority="high" decoding="async" width="1600" height="1306" src="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230218_104211238.jpg" alt="" class="wp-image-33244" srcset="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230218_104211238.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230218_104211238-300x245.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230218_104211238-768x627.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230218_104211238-1536x1254.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



<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>
#include &lt;list>

using namespace std;

int n, k, f, b, s;

constexpr int MAX = 401;

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

list&lt;pair&lt;int, int>> myList;

int disArr[MAX][MAX];

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

	cin >> n >> k;

	// 사건의 전후 관계 입력
	for (int i = 0; i &lt; k; i++) {
		cin >> f >> b;
		graph[f].push_back(make_pair(b, -1));
		graph[b].push_back(make_pair(f, 1)); // 역방향 가능
	}

	// 질문을 입력 받는다.
	cin >> s;

	pair&lt;int, int> tempP;

	while (s--) { // 문제를 입력받는다.
		cin >> tempP.first >> tempP.second;
		myList.push_back(tempP);
	}

	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;
			disArr[i][v] = weight;
		}
	}


	for (int k = 1; k &lt;= n; k++) {
		for (int i = 1; i &lt;= n; i++) {
			for (int j = 1; j &lt;= n; j++) {
				if (i == j) disArr[i][j] = 0;
				else if (disArr[i][k] == 1 &amp;&amp; disArr[k][j] == 1) disArr[i][j] = 1;
				else if (disArr[i][k] == -1 &amp;&amp; disArr[k][j] == -1) disArr[i][j] = -1;
			}
		}
	}

	for (auto it = myList.begin(); it != myList.end(); it++) {
		cout &lt;&lt; disArr[it->first][it->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"><img decoding="async" width="912" height="126" src="https://lycos7560.com/wp-content/uploads/2023/02/image-83.png" alt="" class="wp-image-33242" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-83.png 912w, https://lycos7560.com/wp-content/uploads/2023/02/image-83-300x41.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-83-768x106.png 768w" sizes="(max-width: 912px) 100vw, 912px" /></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-1613%eb%b2%88-%ec%97%ad%ec%82%ac-c-floyd-warshall-baekjoon/33239/">백준 1613번 (역사, C++, Floyd-Warshall) [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-1613%eb%b2%88-%ec%97%ad%ec%82%ac-c-floyd-warshall-baekjoon/33239/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1507번 (궁금한 민호, C++, Floyd-Warshall) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1507%eb%b2%88-%ea%b6%81%ea%b8%88%ed%95%9c-%eb%af%bc%ed%98%b8-c-floyd-warshall-baekjoon/33230/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1507%eb%b2%88-%ea%b6%81%ea%b8%88%ed%95%9c-%eb%af%bc%ed%98%b8-c-floyd-warshall-baekjoon/33230/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 17 Feb 2023 07:43:51 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1507]]></category>
		<category><![CDATA[1507번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Floyd-Warshall]]></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[백준 1507]]></category>
		<category><![CDATA[백준 1507번]]></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=33230</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1507번 '궁금한 민호' 문제에 대한 글입니다. 'Floyd-Warshall' 알고리즘을 이용하여 해결하였습니다.  (This is BAEKJOON's 1507 "Curious Minho" question. Solved using the 'Floyd-Warshall' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1507%eb%b2%88-%ea%b6%81%ea%b8%88%ed%95%9c-%eb%af%bc%ed%98%b8-c-floyd-warshall-baekjoon/33230/">백준 1507번 (궁금한 민호, C++, Floyd-Warshall) [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-54dab500      "
					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/1507" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1507</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">5291</td><td class="has-text-align-left" data-align="left">2771</td><td class="has-text-align-left" data-align="left">2180</td><td class="has-text-align-left" data-align="left">51.198%</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">강호는 N개의 도시로 이루어진 나라에 살고 있다. </p>



<p class="has-medium-font-size">각 도시는 M개의 도로로 연결되어 있으며, 각 도로를 지날 때 필요한 시간이 존재한다.&nbsp;</p>



<p class="has-medium-font-size">도로는 잘 연결되어 있기 때문에, 도시 A에서 B로 이동할 수 없는 경우는 존재하지 않는다.</p>



<p class="has-medium-font-size">도시 A에서 도시 B로 바로 갈 수 있는 도로가 있거나, </p>



<p class="has-medium-font-size">다른 도시를 거쳐서 갈 수 있을 때, 도시 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">예를 들어, 도시 1-2, 2-3, 1-4, 3-4, 4-5, 3-5를 연결하는 도로만 있다고 가정해도, 강호가 구한 모든 쌍의 최솟값을 구할 수 있다. </p>



<p class="has-medium-font-size">이 경우 도로의&nbsp;개수는 6개이고, 모든 도로의 시간의 합은 55이다.</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(1 ≤ N ≤ 20)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에 각각의 도시 사이에 이동하는데 필요한 시간이&nbsp;주어진다. </p>



<p class="has-medium-font-size">A에서 B로 가는 시간과 B에서 A로 가는 시간은 같다. 또, A와 B가 같은 경우에는&nbsp;0이 주어지고, </p>



<p class="has-medium-font-size">그 외의 경우에 필요한 시간은 2500보다 작거나 같은 자연수이다.</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">첫째 줄에 도로 개수가&nbsp;최소일 때, 모든 도로의 시간의 합을 출력한다. </p>



<p class="has-medium-font-size">불가능한 경우에는 -1을 출력한다.</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 6 15 2 6
6 0 9 8 12
15 9 0 16 18
2 8 16 0 4
6 12 18 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="">55</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="">3
0 2 2
2 0 2
2 2 0</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="">6</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
0 1 6 17 26 13 7 16
1 0 5 16 25 12 7 15
6 5 0 21 21 8 12 11
17 16 21 0 41 28 23 31
26 25 21 41 0 13 32 10
13 12 8 28 13 0 19 3
7 7 12 23 32 19 0 22
16 15 11 31 10 3 22 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="">69</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="">3
0 1 3
1 0 1
3 1 0</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="">-1</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/medic_programmer" target="_blank" rel="noreferrer noopener">medic_programmer</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/31" 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>



<p class="has-medium-font-size">i -&gt; j로 가는 최단경로와 i -&gt; k, k -&gt; j 로 가는 최단경로의 합이 같다면 i -&gt; j경로는 없애준다.</p>



<p class="has-medium-font-size">i -&gt; j의 최단경로가 더 크다면 입력이 잘못된 것이므로 result를 -1로 저장해준다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="1343" src="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_163646475.jpg" alt="" class="wp-image-33235" srcset="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_163646475.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_163646475-300x252.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_163646475-768x645.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_163646475-1536x1289.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



<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 = 21;

int disArr[MAX][MAX];

int route[MAX][MAX];

int N, result;

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

	cin >> N;

	for (int i = 1; i &lt;= N; i++) {
		for (int j = 1; j &lt;= N; j++) {
			cin >> disArr[i][j];
			route[i][j] = disArr[i][j];
		}
	}

	for (int i = 1; i &lt;= N; i++) {
		for (int j = 1; j &lt;= N; j++) {
			for (int k = 1; k &lt;= N; k++) {

				if (j == k || i == k) continue;

				// 불가능한 경우이므로 -1 출력
				if (disArr[i][j] > disArr[i][k] + disArr[k][j]) {
					cout &lt;&lt; "-1";
					return 0;
				}

				// 경로를 지워준다.
				if (disArr[i][j] == disArr[i][k] + disArr[k][j]) route[i][j] = 0;
			}
		}
	}


	for (int i = 1; i &lt;= N; i++) 
		for (int j = 1; j &lt;= N; j++) result += route[i][j];
	
	// 반으로 나누어준다.
	cout &lt;&lt; result / 2;

	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/02/image-82.png" alt="" class="wp-image-33232" width="1151" height="112" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-82.png 909w, https://lycos7560.com/wp-content/uploads/2023/02/image-82-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-82-768x75.png 768w" sizes="(max-width: 1151px) 100vw, 1151px" /></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-1507%eb%b2%88-%ea%b6%81%ea%b8%88%ed%95%9c-%eb%af%bc%ed%98%b8-c-floyd-warshall-baekjoon/33230/">백준 1507번 (궁금한 민호, C++, Floyd-Warshall) [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-1507%eb%b2%88-%ea%b6%81%ea%b8%88%ed%95%9c-%eb%af%bc%ed%98%b8-c-floyd-warshall-baekjoon/33230/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 11562번 (백양로 브레이크, C++, Floyd-Warshall) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11562%eb%b2%88-%eb%b0%b1%ec%96%91%eb%a1%9c-%eb%b8%8c%eb%a0%88%ec%9d%b4%ed%81%ac-c-floyd-warshall-baekjoon/33218/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11562%eb%b2%88-%eb%b0%b1%ec%96%91%eb%a1%9c-%eb%b8%8c%eb%a0%88%ec%9d%b4%ed%81%ac-c-floyd-warshall-baekjoon/33218/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 17 Feb 2023 04:38:02 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11562]]></category>
		<category><![CDATA[11562번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Floyd-Warshall]]></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[백준 11562]]></category>
		<category><![CDATA[백준 11562번]]></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=33218</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 11562번 '백양로 브레이크' 문제에 대한 글입니다. 'Floyd-Warshall' 알고리즘을 이용하여 해결하였습니다. (This is an article on the issue of Baekyang-ro Brake, BAEKJOON No. 11562. Solved using the 'Floyd-Warshall' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11562%eb%b2%88-%eb%b0%b1%ec%96%91%eb%a1%9c-%eb%b8%8c%eb%a0%88%ec%9d%b4%ed%81%ac-c-floyd-warshall-baekjoon/33218/">백준 11562번 (백양로 브레이크, C++, Floyd-Warshall) [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-9a3904cd      "
					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="#시간-초과-코드-dfs" class="uagb-toc-link__trigger">시간 초과 코드 (DFS)</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/11562" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/11562</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">2698</td><td class="has-text-align-left" data-align="left">1354</td><td class="has-text-align-left" data-align="left">1024</td><td class="has-text-align-left" data-align="left">47.828%</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">서울 소재 Y모 대학교에서 대규모 공사를 진행하면서, 학교가 마치 미로처럼 변해버리고 말았다. </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">길을 잃어 3일 밤낮을 헤매다가 공학관에서 종합관으로 가는 길은 존재하지 않는다는 결론을 내렸다.</p>



<p class="has-medium-font-size">3일 사이에 과제도 내지 못하고 출석도 하지 못해 학사경고 위기에 처한 남규는 전공을 살려 </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">&#8220;공학관에서 대강당 갈 수 있어?&#8221;</p>



<p class="has-medium-font-size">&#8220;상경대 별관에서 학관으로는?&#8221;</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">첫 줄에 Y대학교 건물의 수 n과 길의 수 m이 주어진다. (n ≤ 250, m ≤ n * (n &#8211; 1) / 2 )</p>



<p class="has-medium-font-size">다음 m줄에 걸쳐, u v b (1 ≤ u ≤ n, 1 ≤ v ≤ n, u != v, b = 0 또는 1) 의 형태로 길에 대한 정보가 주어진다.</p>



<p class="has-medium-font-size">b가 0일 경우 u에서 v로 가는 일방통행 길인 것이고, b가 1일 경우 u와 v를 잇는 양방향 길이다.</p>



<p class="has-medium-font-size">어떤 두 건물 사이를 잇는 길은 최대 한 개이다.</p>



<p class="has-medium-font-size">다음 줄에 학생들의 질문의 수 k가 주어진다. (1 ≤ k ≤ 30,000)</p>



<p class="has-medium-font-size">다음 k줄에 걸쳐 s e (1 ≤ s ≤ n, 1 ≤ e ≤ n)의 형태로 학생들의 질문들이 주어진다.</p>



<p class="has-medium-font-size">이는 질문한 학생이 건물 s에서 건물 e로 가고 싶다는 의미이다.</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">출력은 k줄에 걸쳐 이루어진다.</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">예제 입력 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="">4 3
1 2 0
2 3 1
3 4 0
7
1 1
1 2
2 1
1 4
4 1
2 3
4 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="">0
0
1
0
2
0
1</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/5" target="_blank" rel="noreferrer noopener">University</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/334" target="_blank" rel="noreferrer noopener">연세대학교</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/1419" target="_blank" rel="noreferrer noopener">2015 연세대학교 프로그래밍 경시대회</a>&nbsp;F번</p>



<ul class="wp-block-list">
<li>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/portableangel" target="_blank" rel="noreferrer noopener">portableangel</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/31" 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="1600" height="1826" src="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_133534115.jpg" alt="" class="wp-image-33225" srcset="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_133534115.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_133534115-263x300.jpg 263w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_133534115-768x876.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230217_133534115-1346x1536.jpg 1346w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



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



<h1 class="wp-block-heading">시간 초과 코드 (DFS)</h1>



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



<p class="has-medium-font-size">DFS 탐색을 이용하여 도착지부터 출발지까지 최소 거리를 카운트하여 탐색한 코드 </p>



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



<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>
#include &lt;list>

using namespace std;

constexpr int INF = INT32_MAX / 2;

constexpr int MAX = 251;

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

list&lt;pair&lt;int, int>> myList;

int disArr[MAX][MAX];
bool check[MAX];

// N : 도시의 수, M : 길의 수
int N, M, s, d, w, b, K, result;

void Tracking(int start, int now, int cnt)
{
	if (start == now || disArr[now][start] == 0) {
		result = min(result, cnt);
		return;
	}

	for (int j = 0; j &lt; graph[now].size(); j++) {
		int v = graph[now][j].first; // 도착점
		int weight = graph[now][j].second; // 가중치

		if (check[v] == true) continue;

		if (weight == INF) {
			cnt++;
			check[v] = true;
			Tracking(start, v, cnt);
			check[v] = false;
			cnt--;	
		}
		else
		{
			check[v] = true;
			Tracking(start, v, cnt);
			check[v] = false;
		}
	}
}


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 = 0; i &lt; M; i++) {

		// 출발 s, 도착 d, b 양/단 방향
		cin >> s >> d >> b;

		if (b == 0) { // 단방향
			graph[s].push_back(make_pair(d, 0));
			graph[d].push_back(make_pair(s, INF));
		}
		else { // 양방향
			graph[s].push_back(make_pair(d, 0));
			graph[d].push_back(make_pair(s, 0));
		}

	}

	// 질문을 입력 받는다.
	cin >> K;
	pair&lt;int, int> tempP;
	while (K--) {
		cin >> tempP.first >> tempP.second;
		myList.push_back(tempP);
	}




	// 최단 거리 배열 disArr 배열을 INF 초기화
	for (int i = 1; i &lt;= N; i++) {
		for (int j = 1; j &lt;= N; j++) {

			if (i == j) disArr[i][j] = 0;
			else disArr[i][j] = INF;

		}
	}

	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][v] > weight) 	disArr[i][v] = weight;

		}
	}

	// 무지성 플로이드
	for (int k = 1; k &lt;= N; k++) {
		for (int i = 1; i &lt;= N; i++) {
			for (int j = 1; j &lt;= N; j++) {

				if (i == j) disArr[i][j] = 0;
				else disArr[i][j] = min(disArr[i][j], disArr[i][k] + disArr[k][j]);

			}
		}
	}

	for (auto it = myList.begin(); it != myList.end(); it++) {
		result = INF;
		if (disArr[it->first][it->second] == 0) cout &lt;&lt; disArr[it->first][it->second] &lt;&lt; "\n";
		else {
			Tracking(it->second, it->first, 0);
			cout &lt;&lt; result &lt;&lt; "\n";
		}
	}

	return 0;
}</pre>



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



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



<p class="has-medium-font-size">Floyd-Warshall 알고리즘이 어떤 식으로 작동하는지 안다면 뒤집는 부분에 왜 1 이 들어가는지 알 수 있다.</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;vector>
#include &lt;list>

using namespace std;

constexpr int INF = INT32_MAX / 2;

constexpr int MAX = 251;

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

list&lt;pair&lt;int, int>> myList;

int disArr[MAX][MAX];

// N : 도시의 수, M : 길의 수
int N, M, s, d, w, b, K, result;

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

	cin >> N >> M;

	// 최단 거리 배열 disArr 배열을 INF 초기화
	for (int i = 1; i &lt;= N; i++) {
		for (int j = 1; j &lt;= N; j++) {
			disArr[i][j] = INF;
		}
	}

	// 길의 정보를 입력
	for (int i = 0; i &lt; M; i++) {

		// 출발 s, 도착 d, b 양/단 방향
		cin >> s >> d >> b;

		if (b == 0) { // 단방향
			graph[s].push_back(make_pair(d, 0));
			disArr[d][s] = 1; // (disArr[i][k] + disArr[k][j] vs INF)
		}
		else { // 양방향
			graph[s].push_back(make_pair(d, 0));
			graph[d].push_back(make_pair(s, 0));
		}

	}

	// 질문을 입력 받는다.
	cin >> K;

	pair&lt;int, int> tempP;

	while (K--) {
		cin >> tempP.first >> tempP.second;
		myList.push_back(tempP);
	}

	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][v] > weight) disArr[i][v] = weight;
		}
	}

	// 무지성 플로이드
	for (int k = 1; k &lt;= N; k++) {
		for (int i = 1; i &lt;= N; i++) {
			for (int j = 1; j &lt;= N; j++) {

				if (i == j) disArr[i][j] = 0;
				else disArr[i][j] = min(disArr[i][j], disArr[i][k] + disArr[k][j]);

			}
		}
	}

	for (auto it = myList.begin(); it != myList.end(); it++) {
		cout &lt;&lt; disArr[it->first][it->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/02/image-81.png" alt="" class="wp-image-33220" width="1192" height="166" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-81.png 917w, https://lycos7560.com/wp-content/uploads/2023/02/image-81-300x42.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-81-768x107.png 768w" sizes="(max-width: 1192px) 100vw, 1192px" /></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-11562%eb%b2%88-%eb%b0%b1%ec%96%91%eb%a1%9c-%eb%b8%8c%eb%a0%88%ec%9d%b4%ed%81%ac-c-floyd-warshall-baekjoon/33218/">백준 11562번 (백양로 브레이크, C++, Floyd-Warshall) [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-11562%eb%b2%88-%eb%b0%b1%ec%96%91%eb%a1%9c-%eb%b8%8c%eb%a0%88%ec%9d%b4%ed%81%ac-c-floyd-warshall-baekjoon/33218/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 5430번 (AC, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5430%eb%b2%88-ac-c-baekjoon/6247/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5430%eb%b2%88-ac-c-baekjoon/6247/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 08 Feb 2023 17:58:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[5430]]></category>
		<category><![CDATA[5430번]]></category>
		<category><![CDATA[AC]]></category>
		<category><![CDATA[atoi]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[deque]]></category>
		<category><![CDATA[string]]></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[백준 5430]]></category>
		<category><![CDATA[백준 5430번]]></category>
		<category><![CDATA[시간 초과]]></category>
		<category><![CDATA[시간초과]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=6247</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 5430번 'AC' 문제에 대한 글입니다. 자료구조 'deque'을 이용하여 해결하였습니다. (This is an article about the 'AC' problem in BAEKJOON No. 5430. I solved it using the data structure 'decque'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-5430%eb%b2%88-ac-c-baekjoon/6247/">백준 5430번 (AC, 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:40px" 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-24d06010      "
					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="#ac" class="uagb-toc-link__trigger">AC</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:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">AC</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/5430" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/5430</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">102422</td><td class="has-text-align-left" data-align="left">22704</td><td class="has-text-align-left" data-align="left">16003</td><td class="has-text-align-left" data-align="left">19.830%</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">선영이는 주말에 할 일이 없어서 새로운 언어 AC를 만들었다. </p>



<p class="has-medium-font-size">AC는 정수 배열에 연산을 하기 위해 만든 언어이다. </p>



<p class="has-medium-font-size">이 언어에는 두 가지 함수 R(뒤집기)과 D(버리기)가 있다.</p>



<p class="has-medium-font-size">함수 R은 배열에 있는 수의 순서를 뒤집는 함수이고, D는 첫 번째 수를 버리는 함수이다. </p>



<p class="has-medium-font-size">배열이 비어있는데 D를 사용한 경우에는 에러가 발생한다.</p>



<p class="has-medium-font-size">함수는 조합해서 한 번에 사용할 수 있다. </p>



<p class="has-medium-font-size">예를 들어, &#8220;AB&#8221;는 A를 수행한 다음에 바로 이어서 B를 수행하는 함수이다. </p>



<p class="has-medium-font-size">예를 들어, &#8220;RDD&#8221;는 배열을 뒤집은 다음 처음 두 수를 버리는 함수이다.</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">첫째 줄에 테스트 케이스의 개수 T가 주어진다. T는 최대 100이다.</p>



<p class="has-medium-font-size">각 테스트 케이스의 첫째 줄에는 수행할 함수 p가 주어진다. </p>



<p class="has-medium-font-size">p의 길이는 1보다 크거나 같고, 100,000보다 작거나 같다.</p>



<p class="has-medium-font-size">다음 줄에는 배열에 들어있는 수의 개수 n이 주어진다. (0 ≤ n ≤ 100,000)</p>



<p class="has-medium-font-size">다음 줄에는 [x<sub>1</sub>,&#8230;,x<sub>n</sub>]과 같은 형태로 배열에 들어있는 정수가 주어진다. (1 ≤ x<sub>i</sub>&nbsp;≤ 100)</p>



<p class="has-medium-font-size">전체 테스트 케이스에 주어지는 p의 길이의 합과 n의 합은 70만을 넘지 않는다.</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">만약, 에러가 발생한 경우에는 error를 출력한다.</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="">4
RDD
4
[1,2,3,4]
DD
1
[42]
RRD
6
[1,1,2,3,5,8]
D
0
[]</pre>



<div style="height:30px" 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,1]
error
[1,2,3,5,8]
error</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/10" target="_blank" rel="noreferrer noopener">Europe</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/15" target="_blank" rel="noreferrer noopener">Northwestern European Regional Contest</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/89" target="_blank" rel="noreferrer noopener">Benelux Algorithm Programming Contest</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/424" target="_blank" rel="noreferrer noopener">BAPC 2012</a>&nbsp;I번</p>



<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/chatterboy" target="_blank" rel="noreferrer noopener">chatterboy</a>,&nbsp;<a href="https://www.acmicpc.net/user/doju" target="_blank" rel="noreferrer noopener">doju</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/jh05013">jh</a><a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">0</a><a href="https://www.acmicpc.net/user/jh05013">5013</a>,&nbsp;<a href="https://www.acmicpc.net/user/sojungkid" target="_blank" rel="noreferrer noopener">sojungkid</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">구현</a></li>



<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/158" target="_blank" rel="noreferrer noopener">문자열</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/96" target="_blank" rel="noreferrer noopener">파싱</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/73" 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)"/>



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



<p class="has-medium-font-size">이 문제는 deque 자료 구조를 쓰는 것은 어렵지 않지만</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="1600" height="1178" src="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230209_025203344.jpg" alt="" class="wp-image-6251" srcset="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230209_025203344.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230209_025203344-300x221.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230209_025203344-768x565.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230209_025203344-1536x1131.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



<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;deque>
#include &lt;cstdlib>
#include &lt;string>

using namespace std;

int T, N;

string P, arrStr;

bool isFront = false;

int main()
{

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

	cin >> T;

	while (T--) {
		cin >> P;
		cin >> N >> arrStr;
		isFront = true;
		deque&lt;int> myDeque;
		string tempStr;
		for (int i = 1; i &lt; arrStr.length(); i++) {
			if (arrStr[i] == ',' || arrStr[i] == ']') {
				if (tempStr != "") {
					myDeque.push_back(atoi(tempStr.c_str()));
				}

				tempStr = "";
			}
			else {
				tempStr.push_back(arrStr[i]);
			}
		}

		for (int i = 0; i &lt; P.length(); i++) {
			
			if (P[i] == 'R') isFront = !isFront;
			else {
				if (myDeque.empty()) {
					tempStr = "error\n";
					break;
				}

				if (isFront) myDeque.pop_front();
				else myDeque.pop_back();
			}
		}


		if (tempStr[0] == 'e') cout &lt;&lt; tempStr;
		else {
			cout &lt;&lt; "[";
			if (isFront) {
				while (!myDeque.empty()) {
					cout &lt;&lt; myDeque.front();
					myDeque.pop_front();
					if (myDeque.empty()) continue;
					else cout &lt;&lt; ",";
				}
			}
			else {
				while (!myDeque.empty()) {
					cout &lt;&lt; myDeque.back();
					myDeque.pop_back();
					if (myDeque.empty()) continue;
					else cout &lt;&lt; ",";
				}
			}

			cout &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"><img decoding="async" width="1040" height="142" src="https://lycos7560.com/wp-content/uploads/2023/02/image-54.png" alt="" class="wp-image-6249" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-54.png 1040w, https://lycos7560.com/wp-content/uploads/2023/02/image-54-300x41.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-54-768x105.png 768w" sizes="(max-width: 1040px) 100vw, 1040px" /></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-5430%eb%b2%88-ac-c-baekjoon/6247/">백준 5430번 (AC, 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-5430%eb%b2%88-ac-c-baekjoon/6247/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1074번 (Z, C++, DivideAndConquer) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1074%eb%b2%88-z-c-divideandconquer-baekjoon/5628/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1074%eb%b2%88-z-c-divideandconquer-baekjoon/5628/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 26 Jan 2023 16:25:33 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1074]]></category>
		<category><![CDATA[1074번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DivideAndConquer]]></category>
		<category><![CDATA[divisionconquest]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Z]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1074]]></category>
		<category><![CDATA[백준 1074번]]></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>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5628</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1074번 "Z" 문제에 대한 글입니다. 'DivideAndConquer' 알고리즘을 이용하여 해결하였습니다. (This is an article about the "Z" problem in BAEKJOON 1074. Solved using 'DivideAndConquer' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1074%eb%b2%88-z-c-divideandconquer-baekjoon/5628/">백준 1074번 (Z, C++, DivideAndConquer) [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">Z</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1074" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1074</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">0.5 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">56813</td><td class="has-text-align-left" data-align="left">21714</td><td class="has-text-align-left" data-align="left">16372</td><td class="has-text-align-left" data-align="left">39.511%</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">한수는 크기가 2<sup>N</sup> × 2<sup>N</sup>인 2차원 배열을 Z모양으로 탐색하려고 한다. </p>



<p class="has-medium-font-size">예를 들어, 2×2배열을 왼쪽 위칸, 오른쪽 위칸, 왼쪽 아래칸, 오른쪽 아래칸 순서대로 방문하면 Z모양이다.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="275" height="288" src="https://lycos7560.com/wp-content/uploads/2023/01/image-20.png" alt="" class="wp-image-5629"/></figure>



<p class="has-medium-font-size">N &gt;&nbsp;1인 경우, 배열을 크기가 2<sup>N-1</sup>&nbsp;× 2<sup>N-1</sup>로 4등분&nbsp;한 후에 재귀적으로 순서대로 방문한다.</p>



<p class="has-medium-font-size">다음 예는 2<sup>2</sup>&nbsp;× 2<sup>2</sup>&nbsp;크기의 배열을 방문한 순서이다.</p>



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



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



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



<p class="has-medium-font-size">N이 주어졌을 때, r행&nbsp;c열을 몇 번째로 방문하는지 출력하는 프로그램을 작성하시오.</p>



<p class="has-medium-font-size">다음은 N=3일 때의 예이다.</p>



<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/01/image-22.png" alt="" class="wp-image-5631" width="603" height="604" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-22.png 804w, https://lycos7560.com/wp-content/uploads/2023/01/image-22-300x300.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-22-150x150.png 150w, https://lycos7560.com/wp-content/uploads/2023/01/image-22-768x769.png 768w" sizes="(max-width: 603px) 100vw, 603px" /></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">첫째 줄에 정수 N, r, c가 주어진다.</p>



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



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



<p class="has-medium-font-size">r행 c열을 몇 번째로 방문했는지 출력한다.</p>



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



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



<ul class="wp-block-list">
<li>1 ≤ N ≤ 15</li>



<li>0 ≤ r, c &lt; 2<sup>N</sup></li>
</ul>



<div style="height:20px" 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 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="">11</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="">3 7 7</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="">63</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="">1 0 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="">0</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="">4 7 7</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="">63</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="">10 511 511</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="">262143</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="">10 512 512</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="">786432</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/hmw9309" target="_blank" rel="noreferrer noopener">hmw9309</a></li>
</ul>



<div style="height:20px" 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/24" target="_blank" rel="noreferrer noopener">분할 정복</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/62" 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="1600" height="1151" src="https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_012041662.jpg" alt="" class="wp-image-5639" srcset="https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_012041662.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_012041662-300x216.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_012041662-768x552.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_012041662-1536x1105.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



<div style="height:100px" 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="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;cmath>

using namespace std;

int N, r, c, cnt, result;

// (넓이, 시작 x 좌표 , 시작 y 좌표)
void DivideAndConquer(int w, int x, int y)
{
	if (w == 1) {
		for (int i = 0; i &lt; 2; i++) {
			for (int j = 0; j &lt; 2; j++){
				if (x + i == r &amp;&amp; y + j == c ) result = cnt;
				cnt++;
			}
		}
		return;
	}
	
	// R, C 의 위치를 각 4분면으로 나누어서 
	// 해당 위치에 없다면 재귀함수로 진입하지않고 계산으로 시간 단축
	if (result == 0) { // 결과가 정해지면 더이상 진행하지 않는다.
		if (x + pow(2, w - 1) > r &amp;&amp; y + pow(2, w - 1) > c) DivideAndConquer(w - 1, x, y); // 2
		else  cnt += pow(pow(2, w - 1), 2);

		if (x + pow(2, w - 1) > r &amp;&amp; y + pow(2, w - 1) &lt;= c) DivideAndConquer(w - 1, x, y + pow(2, w - 1)); // 1
		else  cnt += pow(pow(2, w - 1), 2);

		if (x + pow(2, w - 1) &lt;= r &amp;&amp; y + pow(2, w - 1) > c) DivideAndConquer(w - 1, x + pow(2, w - 1), y); // 3
		else  cnt += pow(pow(2, w - 1), 2);

		if (x + pow(2, w - 1) &lt;= r &amp;&amp; y + pow(2, w - 1) &lt;= c) DivideAndConquer(w - 1, x + pow(2, w - 1), y + pow(2, w - 1)); // 4
		else  cnt += pow(pow(2, w - 1), 2);

	}
}

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

	cnt = 0;
	result = 0;

	cin >> N >> r >> c;
	
	// 분할 정복
	DivideAndConquer(N, 0, 0);

	cout &lt;&lt; result;

	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="1035" height="143" src="https://lycos7560.com/wp-content/uploads/2023/01/image-24.png" alt="" class="wp-image-5643" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-24.png 1035w, https://lycos7560.com/wp-content/uploads/2023/01/image-24-300x41.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-24-768x106.png 768w" sizes="(max-width: 1035px) 100vw, 1035px" /></figure>



<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/01/image-23.png" alt="" class="wp-image-5635" width="946" height="478" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-23.png 1261w, https://lycos7560.com/wp-content/uploads/2023/01/image-23-300x152.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-23-768x388.png 768w" sizes="(max-width: 946px) 100vw, 946px" /></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-1074%eb%b2%88-z-c-divideandconquer-baekjoon/5628/">백준 1074번 (Z, C++, DivideAndConquer) [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-1074%eb%b2%88-z-c-divideandconquer-baekjoon/5628/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>백준 1916번 (최소비용 구하기, C++, Dijkstra) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1916%eb%b2%88-%ec%b5%9c%ec%86%8c%eb%b9%84%ec%9a%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5438/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1916%eb%b2%88-%ec%b5%9c%ec%86%8c%eb%b9%84%ec%9a%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5438/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 24 Jan 2023 10:53:05 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1916]]></category>
		<category><![CDATA[1916번]]></category>
		<category><![CDATA[algorithm]]></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[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[백준 1916]]></category>
		<category><![CDATA[백준 1916번]]></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=5438</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1916번 '최소비용 구하기'에대한 글입니다. Dijkstra 알고리즘을 이용하여 해결하였습니다.  (This is BAEKJOON's 1916 article about "Getting the Minimum Cost". 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-1916%eb%b2%88-%ec%b5%9c%ec%86%8c%eb%b9%84%ec%9a%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5438/">백준 1916번 (최소비용 구하기, 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/1916" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1916</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">0.5 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">64786</td><td class="has-text-align-left" data-align="left">20209</td><td class="has-text-align-left" data-align="left">13257</td><td class="has-text-align-left" data-align="left">32.113%</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">N개의&nbsp;도시가 있다. 그리고 한 도시에서 출발하여 다른 도시에 도착하는 M개의 버스가 있다. </p>



<p class="has-medium-font-size">우리는 A번째 도시에서 B번째 도시까지 가는데 드는 버스 비용을 최소화 시키려고 한다.&nbsp;</p>



<p class="has-medium-font-size">A번째 도시에서 B번째 도시까지 가는데 드는 최소비용을 출력하여라. </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">첫째 줄에 도시의 개수 N(1 ≤ N ≤ 1,000)이 주어지고 둘째 줄에는 버스의 개수 M(1 ≤ M ≤ 100,000)이 주어진다. </p>



<p class="has-medium-font-size">그리고 셋째 줄부터 M+2줄까지 다음과 같은 버스의 정보가 주어진다. </p>



<p class="has-medium-font-size">먼저 처음에는 그 버스의 출발 도시의 번호가 주어진다. </p>



<p class="has-medium-font-size">그리고 그 다음에는 도착지의 도시 번호가 주어지고 또 그 버스 비용이 주어진다. </p>



<p class="has-medium-font-size">버스 비용은 0보다 크거나 같고, 100,000보다 작은 정수이다.</p>



<p class="has-medium-font-size">그리고 M+3째 줄에는 우리가 구하고자 하는 구간 출발점의 도시번호와 도착점의 도시번호가 주어진다. </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:37px" 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
8
1 2 2
1 3 3
1 4 1
1 5 10
2 4 2
3 4 1
3 5 1
4 5 3
1 5</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="">4</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="">2
1
1 2 0
1 2</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">예제 입력 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
3
2 1 1
1 3 1
3 4 1
2 4</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="">3</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="">1000
999
1 2 99999
2 3 99999
3 4 99999
4 5 99999
5 6 99999
6 7 99999
7 8 99999
8 9 99999
9 10 99999
10 11 99999
11 12 99999
12 13 99999
13 14 99999
14 15 99999
15 16 99999
16 17 99999
17 18 99999
18 19 99999
19 20 99999
20 21 99999
21 22 99999
22 23 99999
23 24 99999
24 25 99999
25 26 99999
26 27 99999
27 28 99999
28 29 99999
29 30 99999
30 31 99999
31 32 99999
32 33 99999
33 34 99999
34 35 99999
35 36 99999
36 37 99999
37 38 99999
38 39 99999
39 40 99999
40 41 99999
41 42 99999
42 43 99999
43 44 99999
44 45 99999
45 46 99999
46 47 99999
47 48 99999
48 49 99999
49 50 99999
50 51 99999
51 52 99999
52 53 99999
53 54 99999
54 55 99999
55 56 99999
56 57 99999
57 58 99999
58 59 99999
59 60 99999
60 61 99999
61 62 99999
62 63 99999
63 64 99999
64 65 99999
65 66 99999
66 67 99999
67 68 99999
68 69 99999
69 70 99999
70 71 99999
71 72 99999
72 73 99999
73 74 99999
74 75 99999
75 76 99999
76 77 99999
77 78 99999
78 79 99999
79 80 99999
80 81 99999
81 82 99999
82 83 99999
83 84 99999
84 85 99999
85 86 99999
86 87 99999
87 88 99999
88 89 99999
89 90 99999
90 91 99999
91 92 99999
92 93 99999
93 94 99999
94 95 99999
95 96 99999
96 97 99999
97 98 99999
98 99 99999
99 100 99999
100 101 99999
101 102 99999
102 103 99999
103 104 99999
104 105 99999
105 106 99999
106 107 99999
107 108 99999
108 109 99999
109 110 99999
110 111 99999
111 112 99999
112 113 99999
113 114 99999
114 115 99999
115 116 99999
116 117 99999
117 118 99999
118 119 99999
119 120 99999
120 121 99999
121 122 99999
122 123 99999
123 124 99999
124 125 99999
125 126 99999
126 127 99999
127 128 99999
128 129 99999
129 130 99999
130 131 99999
131 132 99999
132 133 99999
133 134 99999
134 135 99999
135 136 99999
136 137 99999
137 138 99999
138 139 99999
139 140 99999
140 141 99999
141 142 99999
142 143 99999
143 144 99999
144 145 99999
145 146 99999
146 147 99999
147 148 99999
148 149 99999
149 150 99999
150 151 99999
151 152 99999
152 153 99999
153 154 99999
154 155 99999
155 156 99999
156 157 99999
157 158 99999
158 159 99999
159 160 99999
160 161 99999
161 162 99999
162 163 99999
163 164 99999
164 165 99999
165 166 99999
166 167 99999
167 168 99999
168 169 99999
169 170 99999
170 171 99999
171 172 99999
172 173 99999
173 174 99999
174 175 99999
175 176 99999
176 177 99999
177 178 99999
178 179 99999
179 180 99999
180 181 99999
181 182 99999
182 183 99999
183 184 99999
184 185 99999
185 186 99999
186 187 99999
187 188 99999
188 189 99999
189 190 99999
190 191 99999
191 192 99999
192 193 99999
193 194 99999
194 195 99999
195 196 99999
196 197 99999
197 198 99999
198 199 99999
199 200 99999
200 201 99999
201 202 99999
202 203 99999
203 204 99999
204 205 99999
205 206 99999
206 207 99999
207 208 99999
208 209 99999
209 210 99999
210 211 99999
211 212 99999
212 213 99999
213 214 99999
214 215 99999
215 216 99999
216 217 99999
217 218 99999
218 219 99999
219 220 99999
220 221 99999
221 222 99999
222 223 99999
223 224 99999
224 225 99999
225 226 99999
226 227 99999
227 228 99999
228 229 99999
229 230 99999
230 231 99999
231 232 99999
232 233 99999
233 234 99999
234 235 99999
235 236 99999
236 237 99999
237 238 99999
238 239 99999
239 240 99999
240 241 99999
241 242 99999
242 243 99999
243 244 99999
244 245 99999
245 246 99999
246 247 99999
247 248 99999
248 249 99999
249 250 99999
250 251 99999
251 252 99999
252 253 99999
253 254 99999
254 255 99999
255 256 99999
256 257 99999
257 258 99999
258 259 99999
259 260 99999
260 261 99999
261 262 99999
262 263 99999
263 264 99999
264 265 99999
265 266 99999
266 267 99999
267 268 99999
268 269 99999
269 270 99999
270 271 99999
271 272 99999
272 273 99999
273 274 99999
274 275 99999
275 276 99999
276 277 99999
277 278 99999
278 279 99999
279 280 99999
280 281 99999
281 282 99999
282 283 99999
283 284 99999
284 285 99999
285 286 99999
286 287 99999
287 288 99999
288 289 99999
289 290 99999
290 291 99999
291 292 99999
292 293 99999
293 294 99999
294 295 99999
295 296 99999
296 297 99999
297 298 99999
298 299 99999
299 300 99999
300 301 99999
301 302 99999
302 303 99999
303 304 99999
304 305 99999
305 306 99999
306 307 99999
307 308 99999
308 309 99999
309 310 99999
310 311 99999
311 312 99999
312 313 99999
313 314 99999
314 315 99999
315 316 99999
316 317 99999
317 318 99999
318 319 99999
319 320 99999
320 321 99999
321 322 99999
322 323 99999
323 324 99999
324 325 99999
325 326 99999
326 327 99999
327 328 99999
328 329 99999
329 330 99999
330 331 99999
331 332 99999
332 333 99999
333 334 99999
334 335 99999
335 336 99999
336 337 99999
337 338 99999
338 339 99999
339 340 99999
340 341 99999
341 342 99999
342 343 99999
343 344 99999
344 345 99999
345 346 99999
346 347 99999
347 348 99999
348 349 99999
349 350 99999
350 351 99999
351 352 99999
352 353 99999
353 354 99999
354 355 99999
355 356 99999
356 357 99999
357 358 99999
358 359 99999
359 360 99999
360 361 99999
361 362 99999
362 363 99999
363 364 99999
364 365 99999
365 366 99999
366 367 99999
367 368 99999
368 369 99999
369 370 99999
370 371 99999
371 372 99999
372 373 99999
373 374 99999
374 375 99999
375 376 99999
376 377 99999
377 378 99999
378 379 99999
379 380 99999
380 381 99999
381 382 99999
382 383 99999
383 384 99999
384 385 99999
385 386 99999
386 387 99999
387 388 99999
388 389 99999
389 390 99999
390 391 99999
391 392 99999
392 393 99999
393 394 99999
394 395 99999
395 396 99999
396 397 99999
397 398 99999
398 399 99999
399 400 99999
400 401 99999
401 402 99999
402 403 99999
403 404 99999
404 405 99999
405 406 99999
406 407 99999
407 408 99999
408 409 99999
409 410 99999
410 411 99999
411 412 99999
412 413 99999
413 414 99999
414 415 99999
415 416 99999
416 417 99999
417 418 99999
418 419 99999
419 420 99999
420 421 99999
421 422 99999
422 423 99999
423 424 99999
424 425 99999
425 426 99999
426 427 99999
427 428 99999
428 429 99999
429 430 99999
430 431 99999
431 432 99999
432 433 99999
433 434 99999
434 435 99999
435 436 99999
436 437 99999
437 438 99999
438 439 99999
439 440 99999
440 441 99999
441 442 99999
442 443 99999
443 444 99999
444 445 99999
445 446 99999
446 447 99999
447 448 99999
448 449 99999
449 450 99999
450 451 99999
451 452 99999
452 453 99999
453 454 99999
454 455 99999
455 456 99999
456 457 99999
457 458 99999
458 459 99999
459 460 99999
460 461 99999
461 462 99999
462 463 99999
463 464 99999
464 465 99999
465 466 99999
466 467 99999
467 468 99999
468 469 99999
469 470 99999
470 471 99999
471 472 99999
472 473 99999
473 474 99999
474 475 99999
475 476 99999
476 477 99999
477 478 99999
478 479 99999
479 480 99999
480 481 99999
481 482 99999
482 483 99999
483 484 99999
484 485 99999
485 486 99999
486 487 99999
487 488 99999
488 489 99999
489 490 99999
490 491 99999
491 492 99999
492 493 99999
493 494 99999
494 495 99999
495 496 99999
496 497 99999
497 498 99999
498 499 99999
499 500 99999
500 501 99999
501 502 99999
502 503 99999
503 504 99999
504 505 99999
505 506 99999
506 507 99999
507 508 99999
508 509 99999
509 510 99999
510 511 99999
511 512 99999
512 513 99999
513 514 99999
514 515 99999
515 516 99999
516 517 99999
517 518 99999
518 519 99999
519 520 99999
520 521 99999
521 522 99999
522 523 99999
523 524 99999
524 525 99999
525 526 99999
526 527 99999
527 528 99999
528 529 99999
529 530 99999
530 531 99999
531 532 99999
532 533 99999
533 534 99999
534 535 99999
535 536 99999
536 537 99999
537 538 99999
538 539 99999
539 540 99999
540 541 99999
541 542 99999
542 543 99999
543 544 99999
544 545 99999
545 546 99999
546 547 99999
547 548 99999
548 549 99999
549 550 99999
550 551 99999
551 552 99999
552 553 99999
553 554 99999
554 555 99999
555 556 99999
556 557 99999
557 558 99999
558 559 99999
559 560 99999
560 561 99999
561 562 99999
562 563 99999
563 564 99999
564 565 99999
565 566 99999
566 567 99999
567 568 99999
568 569 99999
569 570 99999
570 571 99999
571 572 99999
572 573 99999
573 574 99999
574 575 99999
575 576 99999
576 577 99999
577 578 99999
578 579 99999
579 580 99999
580 581 99999
581 582 99999
582 583 99999
583 584 99999
584 585 99999
585 586 99999
586 587 99999
587 588 99999
588 589 99999
589 590 99999
590 591 99999
591 592 99999
592 593 99999
593 594 99999
594 595 99999
595 596 99999
596 597 99999
597 598 99999
598 599 99999
599 600 99999
600 601 99999
601 602 99999
602 603 99999
603 604 99999
604 605 99999
605 606 99999
606 607 99999
607 608 99999
608 609 99999
609 610 99999
610 611 99999
611 612 99999
612 613 99999
613 614 99999
614 615 99999
615 616 99999
616 617 99999
617 618 99999
618 619 99999
619 620 99999
620 621 99999
621 622 99999
622 623 99999
623 624 99999
624 625 99999
625 626 99999
626 627 99999
627 628 99999
628 629 99999
629 630 99999
630 631 99999
631 632 99999
632 633 99999
633 634 99999
634 635 99999
635 636 99999
636 637 99999
637 638 99999
638 639 99999
639 640 99999
640 641 99999
641 642 99999
642 643 99999
643 644 99999
644 645 99999
645 646 99999
646 647 99999
647 648 99999
648 649 99999
649 650 99999
650 651 99999
651 652 99999
652 653 99999
653 654 99999
654 655 99999
655 656 99999
656 657 99999
657 658 99999
658 659 99999
659 660 99999
660 661 99999
661 662 99999
662 663 99999
663 664 99999
664 665 99999
665 666 99999
666 667 99999
667 668 99999
668 669 99999
669 670 99999
670 671 99999
671 672 99999
672 673 99999
673 674 99999
674 675 99999
675 676 99999
676 677 99999
677 678 99999
678 679 99999
679 680 99999
680 681 99999
681 682 99999
682 683 99999
683 684 99999
684 685 99999
685 686 99999
686 687 99999
687 688 99999
688 689 99999
689 690 99999
690 691 99999
691 692 99999
692 693 99999
693 694 99999
694 695 99999
695 696 99999
696 697 99999
697 698 99999
698 699 99999
699 700 99999
700 701 99999
701 702 99999
702 703 99999
703 704 99999
704 705 99999
705 706 99999
706 707 99999
707 708 99999
708 709 99999
709 710 99999
710 711 99999
711 712 99999
712 713 99999
713 714 99999
714 715 99999
715 716 99999
716 717 99999
717 718 99999
718 719 99999
719 720 99999
720 721 99999
721 722 99999
722 723 99999
723 724 99999
724 725 99999
725 726 99999
726 727 99999
727 728 99999
728 729 99999
729 730 99999
730 731 99999
731 732 99999
732 733 99999
733 734 99999
734 735 99999
735 736 99999
736 737 99999
737 738 99999
738 739 99999
739 740 99999
740 741 99999
741 742 99999
742 743 99999
743 744 99999
744 745 99999
745 746 99999
746 747 99999
747 748 99999
748 749 99999
749 750 99999
750 751 99999
751 752 99999
752 753 99999
753 754 99999
754 755 99999
755 756 99999
756 757 99999
757 758 99999
758 759 99999
759 760 99999
760 761 99999
761 762 99999
762 763 99999
763 764 99999
764 765 99999
765 766 99999
766 767 99999
767 768 99999
768 769 99999
769 770 99999
770 771 99999
771 772 99999
772 773 99999
773 774 99999
774 775 99999
775 776 99999
776 777 99999
777 778 99999
778 779 99999
779 780 99999
780 781 99999
781 782 99999
782 783 99999
783 784 99999
784 785 99999
785 786 99999
786 787 99999
787 788 99999
788 789 99999
789 790 99999
790 791 99999
791 792 99999
792 793 99999
793 794 99999
794 795 99999
795 796 99999
796 797 99999
797 798 99999
798 799 99999
799 800 99999
800 801 99999
801 802 99999
802 803 99999
803 804 99999
804 805 99999
805 806 99999
806 807 99999
807 808 99999
808 809 99999
809 810 99999
810 811 99999
811 812 99999
812 813 99999
813 814 99999
814 815 99999
815 816 99999
816 817 99999
817 818 99999
818 819 99999
819 820 99999
820 821 99999
821 822 99999
822 823 99999
823 824 99999
824 825 99999
825 826 99999
826 827 99999
827 828 99999
828 829 99999
829 830 99999
830 831 99999
831 832 99999
832 833 99999
833 834 99999
834 835 99999
835 836 99999
836 837 99999
837 838 99999
838 839 99999
839 840 99999
840 841 99999
841 842 99999
842 843 99999
843 844 99999
844 845 99999
845 846 99999
846 847 99999
847 848 99999
848 849 99999
849 850 99999
850 851 99999
851 852 99999
852 853 99999
853 854 99999
854 855 99999
855 856 99999
856 857 99999
857 858 99999
858 859 99999
859 860 99999
860 861 99999
861 862 99999
862 863 99999
863 864 99999
864 865 99999
865 866 99999
866 867 99999
867 868 99999
868 869 99999
869 870 99999
870 871 99999
871 872 99999
872 873 99999
873 874 99999
874 875 99999
875 876 99999
876 877 99999
877 878 99999
878 879 99999
879 880 99999
880 881 99999
881 882 99999
882 883 99999
883 884 99999
884 885 99999
885 886 99999
886 887 99999
887 888 99999
888 889 99999
889 890 99999
890 891 99999
891 892 99999
892 893 99999
893 894 99999
894 895 99999
895 896 99999
896 897 99999
897 898 99999
898 899 99999
899 900 99999
900 901 99999
901 902 99999
902 903 99999
903 904 99999
904 905 99999
905 906 99999
906 907 99999
907 908 99999
908 909 99999
909 910 99999
910 911 99999
911 912 99999
912 913 99999
913 914 99999
914 915 99999
915 916 99999
916 917 99999
917 918 99999
918 919 99999
919 920 99999
920 921 99999
921 922 99999
922 923 99999
923 924 99999
924 925 99999
925 926 99999
926 927 99999
927 928 99999
928 929 99999
929 930 99999
930 931 99999
931 932 99999
932 933 99999
933 934 99999
934 935 99999
935 936 99999
936 937 99999
937 938 99999
938 939 99999
939 940 99999
940 941 99999
941 942 99999
942 943 99999
943 944 99999
944 945 99999
945 946 99999
946 947 99999
947 948 99999
948 949 99999
949 950 99999
950 951 99999
951 952 99999
952 953 99999
953 954 99999
954 955 99999
955 956 99999
956 957 99999
957 958 99999
958 959 99999
959 960 99999
960 961 99999
961 962 99999
962 963 99999
963 964 99999
964 965 99999
965 966 99999
966 967 99999
967 968 99999
968 969 99999
969 970 99999
970 971 99999
971 972 99999
972 973 99999
973 974 99999
974 975 99999
975 976 99999
976 977 99999
977 978 99999
978 979 99999
979 980 99999
980 981 99999
981 982 99999
982 983 99999
983 984 99999
984 985 99999
985 986 99999
986 987 99999
987 988 99999
988 989 99999
989 990 99999
990 991 99999
991 992 99999
992 993 99999
993 994 99999
994 995 99999
995 996 99999
996 997 99999
997 998 99999
998 999 99999
999 1000 99999
1 1000</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="">99899001</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/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a>,&nbsp;<a href="https://www.acmicpc.net/user/qf9ar8nv" target="_blank" rel="noreferrer noopener">qf9ar8nv</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/djm03178" target="_blank" rel="noreferrer noopener">djm03178</a></li>



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



<li>잘못된 데이터를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/hsnks100" target="_blank" rel="noreferrer noopener">hsnks100</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/luke0201" target="_blank" rel="noreferrer noopener">luke0201</a>,&nbsp;<a href="https://www.acmicpc.net/user/toysmars" target="_blank" rel="noreferrer noopener">toysmars</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)"/>



<p class="has-medium-font-size">버스 비용은 0보다 크거나 같고, 100,000보다 작은 정수 </p>



<p class="has-medium-font-size">=&gt; <strong>버스의 비용이 0 인 경우가 존재</strong>한다는 것에 주의</p>



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



<p class="has-medium-font-size">추가적으로 현재 임시노드보다 거리가 크다면 넘어간다 (없으면 시간초과 발생)</p>



<figure class="wp-block-image size-full"><img decoding="async" width="842" height="132" src="https://lycos7560.com/wp-content/uploads/image-1049.png" alt="" class="wp-image-5448" srcset="https://lycos7560.com/wp-content/uploads/image-1049.png 842w, https://lycos7560.com/wp-content/uploads/image-1049-300x47.png 300w, https://lycos7560.com/wp-content/uploads/image-1049-768x120.png 768w" sizes="(max-width: 842px) 100vw, 842px" /></figure>



<div style="height:39px" 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>
#include &lt;queue>

using namespace std;

constexpr int MAXN = 10001;
constexpr int INF = INT32_MAX;

// Dijkstra 알고리즘에 사용할 우선순위 큐
priority_queue&lt;pair&lt;int, int>> myPQ;

///*
//각 노드에 연결되어 있는 노드에 대한 정보를 담는 벡터
//a번 노드에서 b번 노드로 가는 비용이 c라는 의미
//graph[a].push_back((make_pair(B, C));
//*/
vector&lt;pair&lt;int, int>> graph[MAXN];

// 임시노드
int disArr[MAXN];

// N : 도시의 개수, M : 간선의 개수, K : 시작 노드, E : 도착 노드
// u : 현재 노드, v : 이웃 노드, dist : 거리
int N, M, K, E, u, v, dist;

void Dijkstra(int start)
{
    // 임시배열 초기화
    for (int i = 1; i &lt;= N; i++) disArr[i] = INF;
    // 우선순위 큐에 삽입.
    myPQ.push({ 0, start }); // &lt; first : 거리 , second : 노드 인덱스 >
    disArr[start] = 0;

    while (!myPQ.empty()) {
        // -를 붙이는 이유는 우선순위 큐를 이용하여 정렬하기 위함이다.
        // (최소힙으로 구현)
        int nCost = -myPQ.top().first;
        int now = myPQ.top().second;
        myPQ.pop();

        // 이미 담겨 있는 것보다 거리가 크면 넘어간다.
        if (disArr[now] &lt; nCost) continue;

        // 해당 노드에서 연결된 모든 경로를 확인
        for (int i = 0; i &lt; graph[now].size(); i++) {

            // disSum = 임시 노드 + 현재 노드에서 i로가는 비용
            int disSum = nCost + graph[now][i].second;
            // 비용이 작다면 최단경로 테이블 값을 갱신.
            if (disSum &lt; disArr[graph[now][i].first]) {
                // 임시 노드 업데이트
                disArr[graph[now][i].first] = disSum;
                // 우선순위 큐에 (거리, 노드 인덱스) 푸시
                myPQ.push(make_pair(-disSum, graph[now][i].first));
            }
        }
    }
}

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

    // N 정점의 개수, E 간선의 개수를 입력받는다.
    cin >> N >> M;

    for (int i = 0; i &lt; M; i++) {
        cin >> u >> v >> dist;
        graph[u].push_back(make_pair(v, dist));
    }

    cin >> K >> E;

    Dijkstra(K);

    cout &lt;&lt; disArr[E];

    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="1034" height="225" src="https://lycos7560.com/wp-content/uploads/image-1048.png" alt="" class="wp-image-5441" srcset="https://lycos7560.com/wp-content/uploads/image-1048.png 1034w, https://lycos7560.com/wp-content/uploads/image-1048-300x65.png 300w, https://lycos7560.com/wp-content/uploads/image-1048-768x167.png 768w" sizes="(max-width: 1034px) 100vw, 1034px" /></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-1916%eb%b2%88-%ec%b5%9c%ec%86%8c%eb%b9%84%ec%9a%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5438/">백준 1916번 (최소비용 구하기, 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-1916%eb%b2%88-%ec%b5%9c%ec%86%8c%eb%b9%84%ec%9a%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5438/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 6 4 3 8 6 8 9 7 0 6 9 2 3 4 7 7 0 4
3 8 2 7 9 6 8 6 1 7 6 2 0 6 8 6 3 5 0 6 6 8 6 5 8
0 9 7 5 6 4 6 2 5 4 2 5 9 1 2 6 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3 7 5 6 5 1 4 3 3 4 9 7 7 3 2 8 0 8 0 0 1 4 3
8 6 0 0 0 5 8 3 1 5 7 3 2 0 2 3 7 1 2 9 3 9 5 2 1 8 0 5 7 4 4 9 4 5 0 8 7 1 3 0 0 1 9 6 5 1 5 4 4 7 4 2 9 1 6 1 3 8 3 5 6 4 5 9 1 9 5 5 0 2 2 1 7 8 3 5 0 5 1 7 8 4 2 4 3 0 1 5 6 6 1 4 2 7 7 3 0 0 1 3
3 9 5 6 6 5 0 2 3 5 5 6 8 8 0 2 5 6 0 8 8 3 6 7 7 8 5 1 9 7 2 3 1 1 7 1 7 3 8 0 5 8 4 5 2 1 0 7 2 2 3 1 0 3 9 1 0 8 5 5 8 4 0 1 0 6 9 4 3 0 9 3 8 2 9 8 4 5 4 3 9 6 5 5 4 4 8 9 0 6 4 9 2 1 7 7 5 0 0 6
2 8 1 3 5 6 6 4 5 8 9 7 5 3 7 0 0 2 2 5 7 6 5 8 3 4 8 8 9 5 3 7 4 9 9 3 7 1 5 3 2 3 9 1 2 3 2 5 6 5 1 4 9 1 3 2 6 1 0 3 8 8 4 5 0 0 9 0 7 9 9 5 7 6 7 1 0 6 6 9 9 4 6 3 4 8 8 3 9 2 1 2 6 1 0 0 7 8 0 0
4 3 6 2 4 3 9 2 6 6 2 0 6 4 9 1 2 3 4 1 0 3 4 0 6 5 1 8 3 8 9 4 2 6 0 4 2 9 9 9 1 4 8 3 9 1 9 7 7 5 9 8 0 3 0 6 5 8 8 0 2 2 2 5 5 0 4 3 9 4 0 6 3 3 7 9 9 3 7 6 4 1 5 1 2 5 7 3 3 5 8 4 9 4 0 8 1 8 6 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="">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>
	</channel>
</rss>
