<?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>ios_base::sync_with_stdio(false); Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/ios_basesync_with_stdiofalse/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Fri, 10 Mar 2023 07:58:10 +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>ios_base::sync_with_stdio(false); Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 1992번 (쿼드트리, C++, DivideAndConquer) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 15 Feb 2023 20:32:23 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1992]]></category>
		<category><![CDATA[1992번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DivideAndConquer]]></category>
		<category><![CDATA[divisionconquest]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[std]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1992]]></category>
		<category><![CDATA[백준 1992번]]></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=33181</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1992번 '쿼드트리' 문제에 대한 글입니다. '분할 정복' 알고리즘을 이용하여 해결하였습니다. (This is an article about the problem of 'Quad Tree' in 1992 by BAEKJOON. We solved it using 'DivideAndConquer' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/">백준 1992번 (쿼드트리, 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>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-79efbce7      "
					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/1992" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1992</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">37409</td><td class="has-text-align-left" data-align="left">22836</td><td class="has-text-align-left" data-align="left">17917</td><td class="has-text-align-left" data-align="left">61.630%</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">흑백 영상을 압축하여 표현하는 데이터 구조로 쿼드 트리(Quad Tree)라는 방법이 있다. </p>



<p class="has-medium-font-size">흰 점을 나타내는 0과 검은 점을 나타내는 1로만 이루어진 영상(2차원 배열)에서 같은 숫자의 점들이 한 곳에 많이 몰려있으면, </p>



<p class="has-medium-font-size">쿼드 트리에서는 이를 압축하여 간단히 표현할 수 있다.</p>



<p class="has-medium-font-size">주어진 영상이 모두 0으로만 되어 있으면 압축 결과는 &#8220;0&#8221;이 되고, 모두 1로만 되어 있으면 압축 결과는 &#8220;1&#8221;이 된다. </p>



<p class="has-medium-font-size">만약 0과 1이 섞여 있으면 전체를 한 번에 나타내지를 못하고, </p>



<p class="has-medium-font-size">왼쪽 위, 오른쪽 위, 왼쪽 아래, 오른쪽 아래, 이렇게 4개의 영상으로 나누어 압축하게 되며, </p>



<p class="has-medium-font-size">이 4개의 영역을 압축한 결과를 차례대로 괄호 안에 묶어서 표현한다</p>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="876" height="361" src="https://lycos7560.com/wp-content/uploads/2023/02/image-71.png" alt="" class="wp-image-33182" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-71.png 876w, https://lycos7560.com/wp-content/uploads/2023/02/image-71-300x124.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-71-768x316.png 768w" sizes="(max-width: 876px) 100vw, 876px" /></figure>



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



<p class="has-medium-font-size">위 그림에서 왼쪽의 영상은 오른쪽의 배열과 같이 숫자로 주어지며, </p>



<p class="has-medium-font-size">이 영상을 쿼드 트리 구조를 이용하여 압축하면 &#8220;<code>(0(0011)(0(0111)01)1)</code>&#8220;로 표현된다. </p>



<p class="has-medium-font-size">N ×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 이 주어진다. </p>



<p class="has-medium-font-size">N 은 언제나 2의 제곱수로 주어지며, 1 ≤ N ≤ 64의 범위를 가진다. </p>



<p class="has-medium-font-size">두 번째 줄부터는 길이 N의 문자열이 N개 들어온다. </p>



<p class="has-medium-font-size">각 문자열은 0 또는 1의 숫자로 이루어져 있으며, 영상의 각 점들을 나타낸다.</p>



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



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



<p class="has-medium-font-size">영상을 압축한 결과를 출력한다.</p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8
11110000
11110000
00011100
00011100
11110000
11110000
11110011
11110011</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="">((110(0101))(0010)1(0001))</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/kofgb" target="_blank" rel="noreferrer noopener">kofgb</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/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)"/>



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



<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">이렇게 4개의 영상으로 나누어서 다시 확인한다. (분할 정복)</p>



<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>

using namespace std;

int N;

char map[64][64];

string result;

void DivisionalConquest(int x, int y, int w)
{
	bool check = true;
	for (int i = 0; i &lt; w ; i++) {
		for (int j = 0; j &lt; w; j++) {
			if (map[x][y] != map[x + i][y + j]) check = false;
		}
		if (!check) break;
	}

	if (check) {
		result.push_back(map[x][y]);
		return;
	}
	else if (w == 1) {
		for (int i = 0; i &lt; w; i++) {
			for (int j = 0; j &lt; w; j++) {
				result.push_back(map[x + i][y + j]);
			}
		}

		return;
	}

	result.push_back('(');
	DivisionalConquest(x , y, w / 2);
	DivisionalConquest(x , y + w / 2, w / 2);
	DivisionalConquest(x + w / 2, y, w / 2);
	DivisionalConquest(x + w / 2, y + w / 2, w / 2);
	result.push_back(')');


}

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

	cin >> N;

	string str;

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

	DivisionalConquest(0, 0, N);

	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="1243" height="115" src="https://lycos7560.com/wp-content/uploads/2023/02/image-72.png" alt="" class="wp-image-33189" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-72.png 1243w, https://lycos7560.com/wp-content/uploads/2023/02/image-72-300x28.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-72-768x71.png 768w" sizes="(max-width: 1243px) 100vw, 1243px" /></figure>



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



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



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



<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="">8
11110000
11110000
00011100
00011100
11110000
11110000
11110011
11110011</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="">((110(0101))(0010)1(0001))</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="">16
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000
1111000011110000</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="">((1010)(1010)(1010)(1010))</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="">32
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000
11110000111100001111000011110000</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="">(((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010)))</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="">64
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000
1111000011110000111100001111000011110000111100001111000011110000</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="">((((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010)))(((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010)))(((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010)))(((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))((1010)(1010)(1010)(1010))))</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="">1</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="">1</pre>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/">백준 1992번 (쿼드트리, 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-1992%eb%b2%88-%ec%bf%bc%eb%93%9c%ed%8a%b8%eb%a6%ac-c-divideandconquer-baekjoon/33181/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1389번 (케빈 베이컨의 6단계 법칙, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1389%eb%b2%88-%ec%bc%80%eb%b9%88-%eb%b2%a0%ec%9d%b4%ec%bb%a8%ec%9d%98-6%eb%8b%a8%ea%b3%84-%eb%b2%95%ec%b9%99-c-baekjoon/6182/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1389%eb%b2%88-%ec%bc%80%eb%b9%88-%eb%b2%a0%ec%9d%b4%ec%bb%a8%ec%9d%98-6%eb%8b%a8%ea%b3%84-%eb%b2%95%ec%b9%99-c-baekjoon/6182/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 07 Feb 2023 16:35:58 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1389]]></category>
		<category><![CDATA[1389번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></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[std]]></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[백준 1389]]></category>
		<category><![CDATA[백준 1389번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[케빈 베이컨의 6단계 법칙]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[플로이드 워셜]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=6182</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1389번 '케빈 베이컨의 6단계 법칙' 문제에 대한 글입니다. BFS 탐색을 이용하여 문제를 해결하였습니다. (This article is about the problem of Kevin Bacon's Six-Step Law, BAEKJOON No. 1389. BFS Search was used to resolve the issue.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1389%eb%b2%88-%ec%bc%80%eb%b9%88-%eb%b2%a0%ec%9d%b4%ec%bb%a8%ec%9d%98-6%eb%8b%a8%ea%b3%84-%eb%b2%95%ec%b9%99-c-baekjoon/6182/">백준 1389번 (케빈 베이컨의 6단계 법칙, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-362642f8      "
					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="#케빈-베이컨의-6단계-법칙" class="uagb-toc-link__trigger">케빈 베이컨의 6단계 법칙</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">케빈 베이컨의 6단계 법칙</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1389" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1389</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">28386</td><td class="has-text-align-left" data-align="left">15830</td><td class="has-text-align-left" data-align="left">12440</td><td class="has-text-align-left" data-align="left">55.747%</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">케빈 베이컨의 6단계 법칙에 의하면&nbsp;지구에 있는 모든 사람들은 최대 6단계 이내에서 서로 아는 사람으로 연결될 수 있다. </p>



<p class="has-medium-font-size">케빈 베이컨 게임은 임의의 두 사람이 최소 몇 단계 만에 이어질 수 있는지 계산하는 게임이다.</p>



<p class="has-medium-font-size">예를 들면, 전혀 상관없을 것 같은 인하대학교의 이강호와 서강대학교의 민세희는 몇 단계만에 이어질 수 있을까?</p>



<p class="has-medium-font-size">천민호는 이강호와 같은 학교에 다니는 사이이다.  천민호와 최백준은 Baekjoon Online Judge를 통해 알게 되었다. </p>



<p class="has-medium-font-size">최백준과 김선영은 같이 Startlink를 창업했다. 김선영과 김도현은 같은 학교 동아리 소속이다. </p>



<p class="has-medium-font-size">김도현과 민세희는 같은 학교에 다니는 사이로 서로 알고 있다. </p>



<p class="has-medium-font-size">즉, 이강호-천민호-최백준-김선영-김도현-민세희 와 같이 5단계만 거치면 된다.</p>



<p class="has-medium-font-size">케빈 베이컨은 미국 헐리우드 영화배우들 끼리 케빈 베이컨 게임을 했을때 나오는 단계의 총 합이 가장 적은 사람이라고 한다.</p>



<p class="has-medium-font-size">오늘은 Baekjoon Online Judge의 유저 중에서 케빈 베이컨의 수가 가장 작은 사람을 찾으려고 한다. </p>



<p class="has-medium-font-size">케빈 베이컨 수는 모든 사람과 케빈 베이컨 게임을 했을 때, 나오는 단계의 합이다.</p>



<p class="has-medium-font-size">예를 들어, BOJ의 유저가 5명이고, 1과 3, 1과 4, 2와 3, 3과 4, 4와 5가 친구인 경우를 생각해보자.</p>



<p class="has-medium-font-size">1은 2까지 3을 통해 2단계 만에, 3까지 1단계, 4까지 1단계, 5까지 4를 통해서 2단계 만에 알 수 있다. </p>



<p class="has-medium-font-size">따라서, 케빈 베이컨의 수는 2+1+1+2&nbsp;= 6이다.</p>



<p class="has-medium-font-size">2는 1까지 3을 통해서 2단계 만에, 3까지 1단계 만에, 4까지&nbsp;3을 통해서 2단계 만에, 5까지 3과 4를 통해서 3단계 만에 알 수 있다. </p>



<p class="has-medium-font-size">따라서, 케빈 베이컨의 수는 2+1+2+3 = 8이다.</p>



<p class="has-medium-font-size">3은 1까지 1단계, 2까지 1단계, 4까지 1단계, 5까지 4를&nbsp;통해 2단계 만에 알 수 있다. </p>



<p class="has-medium-font-size">따라서, 케빈 베이컨의 수는 1+1+1+2 = 5이다.</p>



<p class="has-medium-font-size">4는 1까지 1단계, 2까지 3을 통해 2단계, 3까지 1단계, 5까지 1단계 만에 알 수 있다. </p>



<p class="has-medium-font-size">4의 케빈 베이컨의 수는 1+2+1+1 = 5가 된다.</p>



<p class="has-medium-font-size">마지막으로 5는 1까지 4를 통해 2단계, 2까지 4와 3을 통해 3단계, 3까지 4를 통해 2단계, 4까지 1단계 만에 알 수 있다. </p>



<p class="has-medium-font-size">5의 케빈 베이컨의 수는 2+3+2+1 = 8이다.</p>



<p class="has-medium-font-size">5명의 유저 중에서 케빈 베이컨의 수가 가장 작은 사람은 3과 4이다.</p>



<p class="has-medium-font-size">BOJ 유저의 수와 친구 관계가 입력으로 주어졌을 때, </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 (2 ≤ N ≤ 100)과 친구 관계의 수 M (1 ≤ M ≤ 5,000)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄부터 M개의 줄에는 친구 관계가 주어진다. </p>



<p class="has-medium-font-size">친구 관계는 A와 B로 이루어져 있으며, A와 B가 친구라는 뜻이다. </p>



<p class="has-medium-font-size">A와 B가 친구이면, B와 A도 친구이며, A와 B가 같은 경우는 없다. </p>



<p class="has-medium-font-size">친구 관계는 중복되어 들어올 수도 있으며, 친구가 한 명도 없는 사람은 없다. </p>



<p class="has-medium-font-size">또, 모든 사람은 친구 관계로 연결되어져 있다. </p>



<p class="has-medium-font-size">사람의 번호는 1부터 N까지이며, 두 사람이 같은 번호를 갖는 경우는 없다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 BOJ의 유저 중에서 케빈 베이컨의 수가 가장 작은 사람을 출력한다. </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="">5 5
1 3
1 4
4 5
4 3
3 2</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="">3</pre>



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



<div style="height:40px" 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/cscandkswon" target="_blank" rel="noreferrer noopener">cscandkswon</a>,&nbsp;<a href="https://www.acmicpc.net/user/harosh" target="_blank" rel="noreferrer noopener">harosh</a>,&nbsp;<a href="https://www.acmicpc.net/user/kjo7811" target="_blank" rel="noreferrer noopener">kjo7811</a>,&nbsp;<a href="https://www.acmicpc.net/user/onjo0127" target="_blank" rel="noreferrer noopener">onjo0127</a>,&nbsp;<a href="https://www.acmicpc.net/user/semtax" target="_blank" rel="noreferrer noopener">semtax</a></li>



<li>빠진 조건을 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/kipa00" target="_blank" rel="noreferrer noopener">kipa00</a>,&nbsp;<a href="https://www.acmicpc.net/user/minjoonist" target="_blank" rel="noreferrer noopener">minjoonist</a></li>
</ul>



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



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



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



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



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



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="1038" src="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230208_013050682.jpg" alt="" class="wp-image-6191" srcset="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230208_013050682.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230208_013050682-300x195.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230208_013050682-768x498.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230208_013050682-1536x996.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;queue>

using namespace std;

int N, M, tempO, tempT;

int cntCB[101];

bool isVisted[101];

queue&lt;pair&lt;int, int>> myQ;

vector&lt;int> graph[101];

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

	cin >> N >> M;

	while (M--) {

		cin >> tempO >> tempT;
		// 양방향으로 경로를 입력받는다.
		graph[tempO].push_back(tempT);
		graph[tempT].push_back(tempO);
	}

	// 1번 부터 N번까지 전부 확인
	for (int i = 1; i &lt;= N; i++) {
		// 방문 처리를 초기화
		fill(isVisted, isVisted + 101, false);

		myQ.push(make_pair(i, 0));
		isVisted[i] = true;

		while (!myQ.empty()) {
			int now = myQ.front().first;
			int cnt = myQ.front().second;
			myQ.pop();

			for (int j = 0; j &lt; graph[now].size(); j++) {
				
				if (isVisted[graph[now][j]] == true) continue;
				else {
					isVisted[graph[now][j]] = true;

					myQ.push(make_pair(graph[now][j], cnt + 1));
					cntCB[i] += cnt + 1;
				}
			}
		}
	}

	pair&lt;int, int> resultP;
	resultP.second = INT32_MAX;
	for (int i = 1; i &lt;= N; i++) {
		if (resultP.second > cntCB[i]) {
			resultP.second = cntCB[i];
			resultP.first = i;
		}
	}

	cout &lt;&lt; resultP.first;

	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-53.png" alt="" class="wp-image-6184" width="1121" height="111" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-53.png 1034w, https://lycos7560.com/wp-content/uploads/2023/02/image-53-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-53-768x76.png 768w" sizes="(max-width: 1121px) 100vw, 1121px" /></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-1389%eb%b2%88-%ec%bc%80%eb%b9%88-%eb%b2%a0%ec%9d%b4%ec%bb%a8%ec%9d%98-6%eb%8b%a8%ea%b3%84-%eb%b2%95%ec%b9%99-c-baekjoon/6182/">백준 1389번 (케빈 베이컨의 6단계 법칙, 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-1389%eb%b2%88-%ec%bc%80%eb%b9%88-%eb%b2%a0%ec%9d%b4%ec%bb%a8%ec%9d%98-6%eb%8b%a8%ea%b3%84-%eb%b2%95%ec%b9%99-c-baekjoon/6182/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 11286번 (절댓값 힙, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11286%eb%b2%88-%ec%a0%88%eb%8c%93%ea%b0%92-%ed%9e%99-c-baekjoon/6163/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11286%eb%b2%88-%ec%a0%88%eb%8c%93%ea%b0%92-%ed%9e%99-c-baekjoon/6163/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 07 Feb 2023 02:00:12 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11286]]></category>
		<category><![CDATA[11286번]]></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[pair]]></category>
		<category><![CDATA[priority_queue]]></category>
		<category><![CDATA[PriorityQueue]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[std]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 11286]]></category>
		<category><![CDATA[백준 11286번]]></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=6163</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 11286번 '절댓값 힙' 문제에 대한 글입니다. 자료구조 'priority queue' 를 사용하여 해결하였습니다. (This is an article about the 'absolute value hip' problem in BAEKJOON No. 11286. We solved it using the data structure 'Priority Queue'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11286%eb%b2%88-%ec%a0%88%eb%8c%93%ea%b0%92-%ed%9e%99-c-baekjoon/6163/">백준 11286번 (절댓값 힙, 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/11286" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/11286</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">34334</td><td class="has-text-align-left" data-align="left">19057</td><td class="has-text-align-left" data-align="left">15496</td><td class="has-text-align-left" data-align="left">56.292%</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>



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



<p class="has-medium-font-size">1. 배열에 정수 x (x ≠ 0)를 넣는다.</p>



<p class="has-medium-font-size">2. 배열에서 절댓값이 가장 작은 값을 출력하고, 그 값을 배열에서 제거한다. </p>



<p class="has-medium-font-size">절댓값이 가장 작은 값이 여러개일 때는, 가장 작은 수를 출력하고, 그 값을 배열에서 제거한다.</p>



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



<p class="has-medium-font-size">프로그램은 처음에 비어있는 배열에서 시작하게 된다.</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≤100,000)이 주어진다. </p>



<p class="has-medium-font-size">다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. </p>



<p class="has-medium-font-size">만약 x가 0이 아니라면 배열에 x라는 값을 넣는(추가하는) 연산이고, </p>



<p class="has-medium-font-size">x가 0이라면 배열에서 절댓값이 가장 작은 값을 출력하고 그 값을 배열에서 제거하는 경우이다. </p>



<p class="has-medium-font-size">입력되는 정수는 -2<sup>31</sup>보다 크고, 2<sup>31</sup>보다 작다.</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="">18
1
-1
0
0
0
1
1
-1
-1
2
-2
0
0
0
0
0
0
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="">-1
1
0
-1
-1
1
1
-2
2
0</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/dkim" target="_blank" rel="noreferrer noopener">dkim</a></li>



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



<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/sgchoi5" target="_blank" rel="noreferrer noopener">sgchoi5</a>, <a href="https://www.acmicpc.net/user/youngminz" target="_blank" rel="noreferrer noopener">youngminz</a>, <a href="https://www.acmicpc.net/user/zerozero" target="_blank" rel="noreferrer noopener">zerozero</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/1927" target="_blank" rel="noreferrer noopener">1927번. 최소 힙</a></li>



<li><a href="https://www.acmicpc.net/problem/11279" target="_blank" rel="noreferrer noopener">11279번. 최대 힙</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">자</a><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/59" 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">priority_queue의 성질을 이용하여 해결하였다.</p>



<p class="has-medium-font-size">아래의 자료구조만 이해한다면 쉽게 해결할 수 있는 문제</p>



<p class="has-medium-font-size"><a href="https://chanhuiseok.github.io/posts/algo-54/" target="_blank" rel="noreferrer noopener">https://chanhuiseok.github.io/posts/algo-54/</a>  &lt;- 해당 사이트에서 정독하면 쉽게 이해가능합니다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1174" height="86" src="https://lycos7560.com/wp-content/uploads/2023/02/image-50.png" alt="" class="wp-image-6169" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-50.png 1174w, https://lycos7560.com/wp-content/uploads/2023/02/image-50-300x22.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-50-768x56.png 768w" sizes="(max-width: 1174px) 100vw, 1174px" /></figure>



<figure class="wp-block-image size-full"><img decoding="async" width="781" height="311" src="https://lycos7560.com/wp-content/uploads/2023/02/image-52.png" alt="" class="wp-image-6174" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-52.png 781w, https://lycos7560.com/wp-content/uploads/2023/02/image-52-300x119.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-52-768x306.png 768w" sizes="(max-width: 781px) 100vw, 781px" /></figure>



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



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



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

using namespace std;

priority_queue&lt;pair&lt;int, int>, vector&lt;pair&lt;int, int>>, greater&lt;pair&lt;int, int>>> myPQ;

pair&lt;int, int> tempP;

int N, tempO, tempT;

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

		cin >> tempO;

		if (tempO == 0) {
			if (myPQ.empty()) cout &lt;&lt; 0 &lt;&lt; "\n";
			else {
				tempP = myPQ.top();
				cout &lt;&lt; tempP.first * tempP.second &lt;&lt; "\n";
				myPQ.pop();
			}
			continue;
		}

		if (tempO > 0) tempT = 1; // 나중에 출력을 쉽게 하기 위해서 1로 만들어준다.
		else tempT = -1; // 나중에 출력을 쉽게 하기 위해서 -1로 만들어준다.

		myPQ.push(make_pair(abs(tempO), tempT));
	}

	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-49.png" alt="" class="wp-image-6166" width="1188" height="118" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-49.png 1039w, https://lycos7560.com/wp-content/uploads/2023/02/image-49-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-49-768x76.png 768w" sizes="(max-width: 1188px) 100vw, 1188px" /></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-11286%eb%b2%88-%ec%a0%88%eb%8c%93%ea%b0%92-%ed%9e%99-c-baekjoon/6163/">백준 11286번 (절댓값 힙, 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-11286%eb%b2%88-%ec%a0%88%eb%8c%93%ea%b0%92-%ed%9e%99-c-baekjoon/6163/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 9375번 (패션왕 신해빈, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9375%eb%b2%88-%ed%8c%a8%ec%85%98%ec%99%95-%ec%8b%a0%ed%95%b4%eb%b9%88-c-baekjoon/6032/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9375%eb%b2%88-%ed%8c%a8%ec%85%98%ec%99%95-%ec%8b%a0%ed%95%b4%eb%b9%88-c-baekjoon/6032/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 06 Feb 2023 08:56:52 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[9375]]></category>
		<category><![CDATA[9375번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[Combination]]></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[백준 9375]]></category>
		<category><![CDATA[백준 9375번]]></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=6032</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 9375번 "패션왕 신해빈" 문제에 대한 글입니다. 'unsorted map' 자료구조를 이용하여 해결하였습니다. (This is an article on the issue of "Fashion King Shin Hae-bin" in BAEKJOON No. 9375 . We solved it using the 'unsorted map' data structure.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9375%eb%b2%88-%ed%8c%a8%ec%85%98%ec%99%95-%ec%8b%a0%ed%95%b4%eb%b9%88-c-baekjoon/6032/">백준 9375번 (패션왕 신해빈, 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:100px" 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-304e0eb5      "
					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:100px" 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/9375" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/9375</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">27013</td><td class="has-text-align-left" data-align="left">14762</td><td class="has-text-align-left" data-align="left">12643</td><td class="has-text-align-left" data-align="left">54.824%</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">첫째 줄에 테스트 케이스가 주어진다. 테스트 케이스는 최대 100이다.</p>



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



<p class="has-medium-font-size">각 테스트 케이스의 첫째 줄에는 해빈이가 가진 의상의 수 n(0 ≤ n ≤ 30)이&nbsp;주어진다.</p>



<p class="has-medium-font-size">다음 n개에는 해빈이가 가진&nbsp;의상의 이름과 의상의 종류가 공백으로 구분되어 주어진다. </p>



<p class="has-medium-font-size">같은 종류의 의상은 하나만 입을 수 있다.</p>



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



<p class="has-medium-font-size">모든 문자열은 1이상 20이하의 알파벳 소문자로 이루어져있으며 같은 이름을 가진 의상은 존재하지 않는다.</p>



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



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



<p class="has-medium-font-size">각 테스트 케이스에 대해 해빈이가 알몸이 아닌 상태로 의상을 입을 수 있는 경우를 출력하시오.</p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">2
3
hat headgear
sunglasses eyewear
turban headgear
3
mask face
sunglasses face
makeup face</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="">5
3</pre>



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



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



<p class="has-medium-font-size">첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 </p>



<p class="has-medium-font-size">eyewear에 해당하는 의상이 sunglasses이므로 &nbsp;</p>



<p class="has-medium-font-size">(hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다.</p>



<div style="height:40px" 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/1160" target="_blank" rel="noreferrer noopener">BAPC 2013</a>&nbsp;I번</p>



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



<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/sunsal0704" target="_blank" rel="noreferrer noopener">sunsal0704</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/124" target="_blank" rel="noreferrer noopener">수학</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/6" 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>



<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>



<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="1455" src="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230206_174945505.jpg" alt="" class="wp-image-6038" srcset="https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230206_174945505.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230206_174945505-300x273.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230206_174945505-768x698.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/02/KakaoTalk_20230206_174945505-1536x1397.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;unordered_map>

using namespace std;

unordered_map&lt;string, int> myMap;

int T , N, result;

string tempO, tempT;

// 조합 n C r 을 계산하는 함수
int Combination(int n, int r)
{
	if (n == r || r == 0) return 1;
	else return Combination(n - 1, r - 1) + Combination(n - 1, r);
}

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

	cin >> T;

	while (T--) {

		myMap.clear();

		cin >> N;

		while (N--) {

			cin >> tempO >> tempT;

			auto it = myMap.find(tempT);
			
			// 만약 map에 있다면 개수를 + 1
			// 없다면 개수를 1로 새로 넣어준다.
			if (it != myMap.end()) it->second++;
			else myMap.insert(make_pair(tempT, 1));
			
		}

		result = 1;

		for (auto it = myMap.begin(); it != myMap.end(); it++) {
			result *= Combination(it->second + 1, 1); // 아무것도 뽑지 않는다 하나 추가
		}

		cout &lt;&lt; result - 1 &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="1035" height="94" src="https://lycos7560.com/wp-content/uploads/2023/02/image-36.png" alt="" class="wp-image-6039" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-36.png 1035w, https://lycos7560.com/wp-content/uploads/2023/02/image-36-300x27.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-36-768x70.png 768w" sizes="(max-width: 1035px) 100vw, 1035px" /></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-9375%eb%b2%88-%ed%8c%a8%ec%85%98%ec%99%95-%ec%8b%a0%ed%95%b4%eb%b9%88-c-baekjoon/6032/">백준 9375번 (패션왕 신해빈, 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-9375%eb%b2%88-%ed%8c%a8%ec%85%98%ec%99%95-%ec%8b%a0%ed%95%b4%eb%b9%88-c-baekjoon/6032/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 11718번 (그대로 출력하기, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11718%eb%b2%88-%ea%b7%b8%eb%8c%80%eb%a1%9c-%ec%b6%9c%eb%a0%a5%ed%95%98%ea%b8%b0-c-baekjoon/5937/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11718%eb%b2%88-%ea%b7%b8%eb%8c%80%eb%a1%9c-%ec%b6%9c%eb%a0%a5%ed%95%98%ea%b8%b0-c-baekjoon/5937/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 01 Feb 2023 03:35:13 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11718]]></category>
		<category><![CDATA[11718번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[endoffile]]></category>
		<category><![CDATA[EOF]]></category>
		<category><![CDATA[getline]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[std]]></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[백준]]></category>
		<category><![CDATA[백준 11718]]></category>
		<category><![CDATA[백준 11718번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5937</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 11718번 '그대로 출력하기' 문제에 대한 글입니다. (This article is about the problem of 'printing as it is' in BAEKJOON 11718.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11718%eb%b2%88-%ea%b7%b8%eb%8c%80%eb%a1%9c-%ec%b6%9c%eb%a0%a5%ed%95%98%ea%b8%b0-c-baekjoon/5937/">백준 11718번 (그대로 출력하기, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-f290c8f8      "
					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></ol>					</div>
									</div>
				</div>
			


<div style="height:100px" 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/11718" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/11718</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">170703</td><td class="has-text-align-left" data-align="left">45118</td><td class="has-text-align-left" data-align="left">36229</td><td class="has-text-align-left" data-align="left">29.209%</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>



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



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



<p class="has-medium-font-size">입력이 주어진다. 입력은 최대 100줄로 이루어져 있고, </p>



<p class="has-medium-font-size">알파벳 소문자, 대문자, 공백, 숫자로만 이루어져 있다. </p>



<p class="has-medium-font-size">각 줄은 100글자를 넘지 않으며, 빈 줄은 주어지지 않는다. </p>



<p class="has-medium-font-size">또, 각 줄은 공백으로 시작하지 않고, 공백으로 끝나지 않는다.</p>



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



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



<p class="has-medium-font-size">입력받은 그대로 출력한다.</p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Hello
Baekjoon
Online Judge</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="">Hello
Baekjoon
Online Judge</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>
</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/158" 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>



<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;string>

using namespace std;

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

	string str;
	while (cin.eof() != true) { // EOF를 이용하여 검사

		getline(cin, str); // 라인을 string 으로 한번에 받는다. 

		cout &lt;&lt; str &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="1034" height="98" src="https://lycos7560.com/wp-content/uploads/2023/02/image-30.png" alt="" class="wp-image-5939" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-30.png 1034w, https://lycos7560.com/wp-content/uploads/2023/02/image-30-300x28.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-30-768x73.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-11718%eb%b2%88-%ea%b7%b8%eb%8c%80%eb%a1%9c-%ec%b6%9c%eb%a0%a5%ed%95%98%ea%b8%b0-c-baekjoon/5937/">백준 11718번 (그대로 출력하기, 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-11718%eb%b2%88-%ea%b7%b8%eb%8c%80%eb%a1%9c-%ec%b6%9c%eb%a0%a5%ed%95%98%ea%b8%b0-c-baekjoon/5937/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 11659번 (구간 합 구하기 4, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-11659%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-4-c-baekjoon/5726/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-11659%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-4-c-baekjoon/5726/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 29 Jan 2023 15:46:35 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11659]]></category>
		<category><![CDATA[11659번]]></category>
		<category><![CDATA[Baekjoon]]></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[std]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[sum]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구간 합 구하기 4]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[누적]]></category>
		<category><![CDATA[누적합]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 11659]]></category>
		<category><![CDATA[백준 11659번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[자연수]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5726</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 11659번 '구간 합 구하기 4' 문제에 대한 글입니다. (This is an article on the question of 'Joint Section 4' in BAEKJOON No. 11659.)</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-11659%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-4-c-baekjoon/5726/">백준 11659번 (구간 합 구하기 4, 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">구간 합 구하기 4</h1>



<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">59524</td><td class="has-text-align-left" data-align="left">25354</td><td class="has-text-align-left" data-align="left">19498</td><td class="has-text-align-left" data-align="left">41.000%</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개가 주어졌을 때, i번째 수부터 j번째 수까지 합을 구하는 프로그램을 작성하시오.</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개의 수가 주어진다. 수는 1,000보다 작거나 같은 자연수이다. </p>



<p class="has-medium-font-size">셋째 줄부터 M개의 줄에는 합을 구해야 하는 구간 i와 j가 주어진다.</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개의 줄에 입력으로 주어진 i번째 수부터 j번째 수까지 합을 출력한다.</p>



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



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



<ul class="wp-block-list">
<li>1 ≤ N ≤ 100,000</li>



<li>1 ≤ M ≤ 100,000</li>



<li>1 ≤ i ≤ j ≤ N</li>
</ul>



<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 3
5 4 3 2 1
1 3
2 4
5 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="">12
9
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>문제를 만든 사람: <a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/djm03178">dj</a><a href="https://www.acmicpc.net/user/djm03178" target="_blank" rel="noreferrer noopener">m</a><a href="https://www.acmicpc.net/user/djm03178">03178</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/139" 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)"/>



<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>

using namespace std;

constexpr int MAX = 100001;

int N, M;

int arr[MAX];

long long int dp[MAX];

pair&lt;int, int> tempP;

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 >> arr[i];
	}

	dp[0] = 0;
	dp[1] = arr[1];
	// 범위내의 구간합을 전부 구해 놓는다.
	for (int i = 2; i &lt;= N; i++) {
		dp[i] = dp[i - 1] + arr[i];
	}

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

		cin >> tempP.first >> tempP.second;

		// 예를 들어 8 - 11의 합은 
		// 1에서 11까지의 합에서 1에서 7까지의 합을 빼주면 된다.
		cout &lt;&lt; dp[tempP.second] - dp[tempP.first - 1] &lt;&lt; "\n";

	}

	return 0;
}</pre>



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



<p class="has-medium-font-size">생각없이 배열 순회로 구현해서 시간초과</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1037" height="140" src="https://lycos7560.com/wp-content/uploads/2023/01/image-38.png" alt="" class="wp-image-5727" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-38.png 1037w, https://lycos7560.com/wp-content/uploads/2023/01/image-38-300x41.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-38-768x104.png 768w" sizes="(max-width: 1037px) 100vw, 1037px" /></figure>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-11659%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-4-c-baekjoon/5726/">백준 11659번 (구간 합 구하기 4, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-11659%eb%b2%88-%ea%b5%ac%ea%b0%84-%ed%95%a9-%ea%b5%ac%ed%95%98%ea%b8%b0-4-c-baekjoon/5726/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1780번 (종이의 개수, C++, DivideAndConquer) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 29 Jan 2023 07:52:12 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1780]]></category>
		<category><![CDATA[1780번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DivideAndConquer]]></category>
		<category><![CDATA[divisionconquest]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[Recursive]]></category>
		<category><![CDATA[std]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1780]]></category>
		<category><![CDATA[백준 1780번]]></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=5718</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1780번 "종이의 개수" 문제에 대한 글입니다. 재귀를 이용한 "분할정복" 알고리즘을 이용하여 해결하였습니다. (This is an article on the issue of "Number of Paper" in BAEKJOON 1780. It was solved using a "divisional conquest" algorithm using recursive.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/">백준 1780번 (종이의 개수, 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">종이의 개수</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/1780" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1780</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">35301</td><td class="has-text-align-left" data-align="left">20969</td><td class="has-text-align-left" data-align="left">15720</td><td class="has-text-align-left" data-align="left">58.541%</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×N크기의 행렬로 표현되는 종이가 있다. </p>



<p class="has-medium-font-size">종이의 각 칸에는 -1, 0, 1 중 하나가 저장되어 있다. </p>



<p class="has-medium-font-size">우리는 이 행렬을 다음과 같은 규칙에 따라 적절한 크기로 자르려고 한다.</p>



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



<p class="has-medium-font-size">1. 만약 종이가 모두 같은 수로 되어 있다면 이 종이를 그대로 사용한다.</p>



<p class="has-medium-font-size">2. (1)이 아닌 경우에는 종이를 같은 크기의 종이 9개로 자르고, 각각의 잘린 종이에 대해서 (1)의 과정을 반복한다.</p>



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



<p class="has-medium-font-size">이와 같이 종이를 잘랐을 때, -1로만 채워진 종이의 개수, 0으로만 채워진 종이의 개수, </p>



<p class="has-medium-font-size">1로만 채워진 종이의 개수를 구해내는 프로그램을 작성하시오.</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">첫째 줄에 N(1 ≤ N ≤ 3<sup>7</sup>, N은 3<sup>k</sup>&nbsp;꼴)이 주어진다. </p>



<p class="has-medium-font-size">다음 N개의 줄에는 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">첫째 줄에 -1로만 채워진 종이의 개수를, 둘째 줄에 0으로만 채워진 종이의 개수를, </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="">9
0 0 0 1 1 1 -1 -1 -1
0 0 0 1 1 1 -1 -1 -1
0 0 0 1 1 1 -1 -1 -1
1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0
0 1 -1 0 1 -1 0 1 -1
0 -1 1 0 1 -1 0 1 -1
0 1 -1 1 0 -1 0 1 -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="">10
12
11</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">author5</a></li>



<li>데이터를 추가한 사람:&nbsp;<a href="https://www.acmicpc.net/user/djm03178">djm03178</a>,&nbsp;<a href="https://www.acmicpc.net/user/hwankim123">hwankim123</a>,&nbsp;<a href="https://www.acmicpc.net/user/upsk1">upsk1</a></li>



<li>잘못된 데이터를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/tncks0121">tncks0121</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/24">분할 정복</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/62">재귀</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">아니면 9부분으로 나눈 후에 다시 확인 </p>



<p class="has-medium-font-size">길이가 1 (3^0)이 될때 까지 해당 로직을 반복한다.</p>



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



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



<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;cmath>

using namespace std;

constexpr int MAX = 2187;

int map[MAX][MAX];

int N;

// 0 = 0 / 1 = 1 / -1 = 2
int result[3];

void ConquestDivison(int x, int y, int w)
{
	// 종이의 길이가 1(3^0) 이라면 해당 종이의 카운트를 증가시켜 줍니다.
	if (w == 0) { 
		if (map[x][y] == -1) result[2]++;
		else result[map[x][y]]++;
		return;
	}

	int number = map[x][y];
	int temp = pow(3, w);
	bool check = true;
	for (int i = 0; i &lt; temp; i++) {
		for (int j = 0; j &lt; temp; j++) {
			// 모든 부분이 서로 같은지 체크합니다.
			// 다르다면 빠져나가고 마킹해줍니다.
			if (number == map[x + i][y + j]) { continue; }
			else {
				check = false;
				break;
			}
		}
		if (!check) break;
	}

	if (check) { // 모든 부분이 같다면 해강 종이의 카운트를 올려줍니다.
		if (number == -1) result[2]++;
		else result[map[x][y]]++;
		return;
	}
	
	int temp2 = pow(3, w - 1);

	// 분할 정복 9등분
	ConquestDivison(x              , y              , w - 1);
	ConquestDivison(x              , y + temp2      , w - 1);
	ConquestDivison(x              , y + 2 * (temp2), w - 1);

	ConquestDivison(x + temp2	   , y				, w - 1);
	ConquestDivison(x + temp2	   , y + temp2		, w - 1);
	ConquestDivison(x + temp2	   , y + 2 * (temp2), w - 1);

	ConquestDivison(x + 2 * (temp2), y	            , w - 1);
	ConquestDivison(x + 2 * (temp2), y + temp2	    , w - 1);
	ConquestDivison(x + 2 * (temp2), y + 2 * (temp2), w - 1);
}


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 = 0; i &lt; N; i++) {
		for (int j = 0; j &lt; N; j++) {
			cin >> map[i][j];
		}
	}

	// N이 3의 몇승인지 확인합니다.
	int k = 0;
	int temp = N;
	while (temp != 1) {
		temp /= 3;
		k++;
	}
	
	ConquestDivison(0, 0, k);

	cout &lt;&lt; result[2] &lt;&lt; "\n" &lt;&lt; result[0] &lt;&lt; "\n" &lt;&lt; result[1];

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1038" height="145" src="https://lycos7560.com/wp-content/uploads/2023/01/image-37.png" alt="" class="wp-image-5722" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-37.png 1038w, https://lycos7560.com/wp-content/uploads/2023/01/image-37-300x42.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-37-768x107.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></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-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/">백준 1780번 (종이의 개수, 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-1780%eb%b2%88-%ec%a2%85%ec%9d%b4%ec%9d%98-%ea%b0%9c%ec%88%98-c-divideandconquer-baekjoon/5718/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 7569번 (토마토, C++, BFS) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 27 Jan 2023 12:18:40 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[3차원]]></category>
		<category><![CDATA[7569]]></category>
		<category><![CDATA[7569번]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></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[Queue]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[tuple]]></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[백준 7569]]></category>
		<category><![CDATA[백준 7569번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[토마토]]></category>
		<category><![CDATA[튜플]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5667</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 7569번 '토마토' 문제에 대한 글입니다. 'BFS Search' 을 사용하여 해결하였습니다. (This is an article about the 'Tomato' problem in BAEKJOON 7569. Resolved using 'BFS Search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/">백준 7569번 (토마토, C++, BFS) [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/7569" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/7569</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">63015</td><td class="has-text-align-left" data-align="left">25996</td><td class="has-text-align-left" data-align="left">19053</td><td class="has-text-align-left" data-align="left">41.355%</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>



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



<figure class="wp-block-image size-full"><img decoding="async" width="506" height="483" src="https://lycos7560.com/wp-content/uploads/2023/01/image-27.png" alt="" class="wp-image-5668" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-27.png 506w, https://lycos7560.com/wp-content/uploads/2023/01/image-27-300x286.png 300w" sizes="(max-width: 506px) 100vw, 506px" /></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>



<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">첫 줄에는 상자의 크기를 나타내는 두 정수 M,N과 쌓아올려지는 상자의 수를 나타내는 H가 주어진다. </p>



<p class="has-medium-font-size">M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M ≤ 100, 2 ≤ N ≤ 100, 1 ≤ H ≤ 100 이다. </p>



<p class="has-medium-font-size">둘째 줄부터는 가장 밑의 상자부터 가장 위의 상자까지에 저장된 토마토들의 정보가 주어진다. </p>



<p class="has-medium-font-size">즉, 둘째 줄부터 N개의 줄에는 하나의 상자에 담긴 토마토의 정보가 주어진다. </p>



<p class="has-medium-font-size">각 줄에는 상자 가로줄에 들어있는 토마토들의 상태가 M개의 정수로 주어진다. </p>



<p class="has-medium-font-size">정수 1은 익은 토마토, 정수 0 은 익지 않은 토마토, 정수 -1은 토마토가 들어있지 않은 칸을 나타낸다. </p>



<p class="has-medium-font-size">이러한 N개의 줄이 H번 반복하여 주어진다.</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">만약, 저장될 때부터 모든 토마토가 익어있는 상태이면 0을 출력해야 하고, </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 3 1
0 -1 0 0 0
-1 -1 0 1 1
0 0 0 1 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="">-1</pre>



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">4 3 2
1 1 1 1
1 1 1 1
1 1 1 1
1 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">예제 출력 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">출처</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/55" target="_blank" rel="noreferrer noopener">한국정보올림피아드</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/57" target="_blank" rel="noreferrer noopener">한국정보올림피아드시․도지역본선</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/214" target="_blank" rel="noreferrer noopener">지역본선 2013</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/912" target="_blank" rel="noreferrer noopener">초등부</a>&nbsp;3번</p>



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



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



<li>잘못된 데이터를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/tncks0121" target="_blank" rel="noreferrer noopener">tncks0121</a></li>
</ul>



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/126" 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="9yXd8hKgRs"><a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7576%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5196/">백준 7576번 (토마토, C++, BFS) [BAEKJOON]</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;백준 7576번 (토마토, C++, BFS) [BAEKJOON]&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7576%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5196/embed/#?secret=aELhJB14mS#?secret=9yXd8hKgRs" data-secret="9yXd8hKgRs" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



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



<p class="has-medium-font-size">백준 7576번과 차이점은 3차원 배열을 쓴다는 점 빼고는 다같다. </p>



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



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



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



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

using namespace std;

constexpr int MAX = 100;

// N 세로, M 가로, H 높이
int N, M, H, dx, dy, dz, maxCnt = 0;

// N, M의 범위 
int map[MAX][MAX][MAX];

// BFS 방문처리
bool mapCheck[MAX][MAX][MAX];

// 탐색하는 방향 설정
int dxdydz[6][3] = { 
         {0, 0, 1},
         {0, 0, -1},
         {1, 0, 0},
         {-1, 0, 0},
         {0, 1, 0},
         {0, -1, 0}
};

queue&lt;tuple&lt;int, int, int>> myQueue;

tuple&lt;int, int, int> tempTuple;

bool falseCheck = true;

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

    cin >> M >> N >> H;


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

    for (int  k = 0; k &lt; H; k++) {
        for (int i = 0; i &lt; N; i++) {
            for (int j = 0; j &lt; M; j++) {
                if (map[i][j][k] == 1) { // 익은 토마토를 큐에 넣고 방문처리
                    mapCheck[i][j][k] = true;
                    map[i][j][k] = 0; // map[i][j][k] = 익은 날짜
                    myQueue.push(make_tuple(i, j, k));
                }
            }
        }
    }


    while (!myQueue.empty()) {

        tempTuple = myQueue.front();
        myQueue.pop();
        // 상/하/좌/우를 탐색하기 위한 반복문
        for (int i = 0; i &lt; 6; i++) {
            dx = get&lt;0>(tempTuple) + dxdydz[i][0];
            dy = get&lt;1>(tempTuple) + dxdydz[i][1];
            dz = get&lt;2>(tempTuple) + dxdydz[i][2];


            // 문제의 범위를 벗어나는 경우 => 넘어간다.
            if (dx &lt; 0 || dy &lt; 0 || dz &lt; 0 || dx >= N || dy >= M || dz >= H) continue;
            // '-1' 인 경우, 이미 방문한 곳 일 경우 => 넘어간다.
            if (mapCheck[dx][dy][dz] == true || map[dx][dy][dz] == -1) continue;

            map[dx][dy][dz] = map[get&lt;0>(tempTuple)][get&lt;1>(tempTuple)][get&lt;2>(tempTuple)] + 1; // 카운트를 올려준다.
            mapCheck[dx][dy][dz] = true; // 방문처리
            myQueue.push(make_tuple(dx, dy, dz));
        }
    }

    for (int k = 0; k &lt; H &amp;&amp; falseCheck; k++) {
        for (int i = 0; i &lt; N &amp;&amp; falseCheck; i++) {
            for (int j = 0; j &lt; M &amp;&amp; falseCheck; j++) {
                    maxCnt = max(maxCnt, map[i][j][k]); // 날짜 출력
                    // 익지 않은 토마토가 방문처리가 안되어있다면 막혀있다는 뜻 
                    if (map[i][j][k] == 0 &amp;&amp; mapCheck[i][j][k] == false)  falseCheck = false;
            }
        }
    }

    // 익지 않은 토마토가 있다면 -1 출력
    // 없다면 날짜 출력
    if (falseCheck) cout &lt;&lt; maxCnt;
    else cout &lt;&lt; -1;

    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="1032" height="99" src="https://lycos7560.com/wp-content/uploads/2023/01/image-28.png" alt="" class="wp-image-5670" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-28.png 1032w, https://lycos7560.com/wp-content/uploads/2023/01/image-28-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-28-768x74.png 768w" sizes="(max-width: 1032px) 100vw, 1032px" /></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-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/">백준 7569번 (토마토, C++, BFS) [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-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1541번 (잃어버린 괄호, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1541%eb%b2%88-%ec%9e%83%ec%96%b4%eb%b2%84%eb%a6%b0-%ea%b4%84%ed%98%b8-c-baekjoon/5649/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1541%eb%b2%88-%ec%9e%83%ec%96%b4%eb%b2%84%eb%a6%b0-%ea%b4%84%ed%98%b8-c-baekjoon/5649/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 27 Jan 2023 09:57:23 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[ASCII]]></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[Greedy]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></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[백준]]></category>
		<category><![CDATA[백준 1541]]></category>
		<category><![CDATA[백준 1541번]]></category>
		<category><![CDATA[수학]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[파싱]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5649</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1541번 '잃어버린 괄호' 문제에 대한 글입니다. (This is an article on the question of 'Lost Parentheses' in BAEKJOON No. 1541.) </p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1541%eb%b2%88-%ec%9e%83%ec%96%b4%eb%b2%84%eb%a6%b0-%ea%b4%84%ed%98%b8-c-baekjoon/5649/">백준 1541번 (잃어버린 괄호, 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/1541" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1541</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">60829</td><td class="has-text-align-left" data-align="left">31765</td><td class="has-text-align-left" data-align="left">25201</td><td class="has-text-align-left" data-align="left">51.706%</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">첫째 줄에 식이 주어진다. 식은 ‘0’~‘9’, ‘+’, 그리고 ‘-’만으로 이루어져 있고, 가장 처음과 마지막 문자는 숫자이다. </p>



<p class="has-medium-font-size">그리고 연속해서 두 개 이상의 연산자가 나타나지 않고, 5자리보다 많이 연속되는 숫자는 없다. </p>



<p class="has-medium-font-size">수는 0으로 시작할 수 있다. 입력으로 주어지는 식의 길이는 50보다 작거나 같다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 정답을 출력한다.</p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">55-50+40</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="">-35</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="">10+20+30+40</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="">100</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="">00009-00009</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">출처</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/windflower" target="_blank" rel="noreferrer noopener">windflower</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/124">수학</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/158">문자열</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/33" target="_blank" rel="noreferrer noopener">그리디 알고리즘</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/96">파싱</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="1126" src="https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_184748740.jpg" alt="" class="wp-image-5651" srcset="https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_184748740.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_184748740-300x211.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_184748740-768x540.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230127_184748740-1536x1081.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></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>



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

string str, tempStr;

int result = 0;
bool check = false;

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

	cin >> str;

	// 한번이라도 - 가 나온다면 뒤의 수들은 전부 뺴준다.
	for (int i = 0; i &lt; str.length(); i++) {
		if (str[i] == 45) { // '-' = 45
			result += atoi(tempStr.c_str()) * ( pow(-1, check));
			check = true;
			tempStr = "";
		}
		else if (str[i] == 43) { // '+' = 43
			result += atoi(tempStr.c_str()) * (pow(-1, check));
			tempStr = "";
		}
		else tempStr.push_back(str[i]);
	}

	// 마지막 숫자 해결
	result += atoi(tempStr.c_str()) * (pow(-1, check));

	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="1036" height="103" src="https://lycos7560.com/wp-content/uploads/2023/01/image-25.png" alt="" class="wp-image-5652" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-25.png 1036w, https://lycos7560.com/wp-content/uploads/2023/01/image-25-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-25-768x76.png 768w" sizes="(max-width: 1036px) 100vw, 1036px" /></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-1541%eb%b2%88-%ec%9e%83%ec%96%b4%eb%b2%84%eb%a6%b0-%ea%b4%84%ed%98%b8-c-baekjoon/5649/">백준 1541번 (잃어버린 괄호, 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-1541%eb%b2%88-%ec%9e%83%ec%96%b4%eb%b2%84%eb%a6%b0-%ea%b4%84%ed%98%b8-c-baekjoon/5649/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>
	</channel>
</rss>
