<?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-2/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>백준 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 fetchpriority="high" 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>백준 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>
		<item>
		<title>백준 11723번 (집합, C++, 비트마스킹) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11723%eb%b2%88-%ec%a7%91%ed%95%a9-c-%eb%b9%84%ed%8a%b8%eb%a7%88%ec%8a%a4%ed%82%b9-baekjoon/5573/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11723%eb%b2%88-%ec%a7%91%ed%95%a9-c-%eb%b9%84%ed%8a%b8%eb%a7%88%ec%8a%a4%ed%82%b9-baekjoon/5573/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 26 Jan 2023 10:42:15 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11723]]></category>
		<category><![CDATA[11723번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[array]]></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[SET]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[배열]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 11723]]></category>
		<category><![CDATA[백준 11723번]]></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=5573</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 11723번 '집합' 문제에 대한 글 입니다. 비트마스킹, 배열, Set을 이용하여 해결하였습니다. (This is an article about the 'collection' problem in BAEKJOON 11723. It was solved using bit masking, arrangement, and Set.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-11723%eb%b2%88-%ec%a7%91%ed%95%a9-c-%eb%b9%84%ed%8a%b8%eb%a7%88%ec%8a%a4%ed%82%b9-baekjoon/5573/">백준 11723번 (집합, 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/11723" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/11723</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.5 초</td><td class="has-text-align-left" data-align="left">4 MB</td><td class="has-text-align-left" data-align="left">69837</td><td class="has-text-align-left" data-align="left">21400</td><td class="has-text-align-left" data-align="left">15369</td><td class="has-text-align-left" data-align="left">29.201%</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">비어있는 공집합 S가 주어졌을 때, 아래 연산을 수행하는 프로그램을 작성하시오.</p>



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



<p class="has-medium-font-size"><code>add x</code>: S에 x를 추가한다. (1&nbsp;≤ x ≤ 20) S에 x가 이미 있는 경우에는 연산을 무시한다.</p>



<p class="has-medium-font-size"><code>remove&nbsp;x</code>: S에서 x를 제거한다. (1&nbsp;≤ x ≤ 20)&nbsp;S에 x가 없는 경우에는 연산을 무시한다.</p>



<p class="has-medium-font-size"><code>check x</code>: S에 x가 있으면 1을, 없으면 0을 출력한다.&nbsp;(1 ≤ x ≤ 20)</p>



<p class="has-medium-font-size"><code>toggle x</code>: S에 x가 있으면 x를 제거하고, 없으면 x를 추가한다. (1&nbsp;≤ x ≤ 20)</p>



<p class="has-medium-font-size"><code>all</code>: S를 {1, 2, &#8230;, 20} 으로 바꾼다.</p>



<p class="has-medium-font-size"><code>empty</code>: S를 공집합으로 바꾼다.&nbsp;</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 (1 ≤ M ≤ 3,000,000)이 주어진다.</p>



<p class="has-medium-font-size">둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.</p>



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



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



<p class="has-medium-font-size"><code>check</code>&nbsp;연산이 주어질때마다, 결과를 출력한다.</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
add 1
add 2
check 1
check 2
check 3
remove 2
check 1
check 2
toggle 3
check 1
check 2
check 3
check 4
all
check 10
check 20
toggle 10
remove 20
check 10
check 20
empty
check 1
toggle 1
check 1
toggle 1
check 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
1
0
1
0
1
0
1
0
1
1
0
0
0
1
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>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



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



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



<li>문제의 오타를 찾은 사람:&nbsp;<a href="https://www.acmicpc.net/user/pichulia" target="_blank" rel="noreferrer noopener">pichulia</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/14" 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">3가지 방법으로 해결</p>



<p class="has-medium-font-size">=&gt; 비트 마스킹. 배열, set </p>



<p class="has-medium-font-size"><strong>비트 마스킹</strong>이 가장 빠르다.</p>



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



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



<p class="has-medium-font-size"><strong>1. 자료구조 Set</strong></p>



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

using namespace std;

set&lt;int> mySet;

int N, temp;

string str;

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

	cin >> N;
	while (N-- > 0) {
		cin >> str;
		if (str == "add") {
			// add x: S에 x를 추가한다. (1 ≤ x ≤ 20) 
			// S에 x가 이미 있는 경우에는 연산을 무시한다.
			cin >> temp;
			mySet.insert(temp);
		}
		else if (str == "remove") {
			//remove x : S에서 x를 제거한다. (1 ≤ x ≤ 20) 
			// S에 x가 없는 경우에는 연산을 무시한다.
			cin >> temp;
			mySet.erase(temp);
		}
		else if (str == "check") {
			// check x: S에 x가 있으면 1을, 
			// 없으면 0을 출력한다. (1 ≤ x ≤ 20)
			cin >> temp;
			if (mySet.count(temp)) cout &lt;&lt; "1" &lt;&lt; "\n";
			else cout &lt;&lt; "0" &lt;&lt; "\n";
		}
		else if (str == "toggle") {
			// toggle x : S에 x가 있으면 x를 제거하고, 
			// 없으면 x를 추가한다. (1 ≤ x ≤ 20)
			cin >> temp;
			if (mySet.count(temp)) mySet.erase(temp);
			else mySet.insert(temp);
		}
		else if (str == "all") {
			// all: S를 {1, 2, ..., 20} 으로 바꾼다.
			for (int i = 1; i &lt;= 20; i++) mySet.insert(i);
		}
		else { 
			// empty: S를 공집합으로 바꾼다. 
			mySet.clear();
		}
	}

	return 0;
}</pre>



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



<p class="has-medium-font-size"><strong>2. 배열</strong></p>



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

bool arr[20];
int N, temp;

string str;

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

	cin >> N;
	while (N-- > 0) {
		cin >> str;
		if (str == "add") {
			// add x: S에 x를 추가한다. (1 ≤ x ≤ 20) 
			// S에 x가 이미 있는 경우에는 연산을 무시한다.
			cin >> temp;
			arr[temp-1] = 1;
		}
		else if (str == "remove") {
			//remove x : S에서 x를 제거한다. (1 ≤ x ≤ 20) 
			// S에 x가 없는 경우에는 연산을 무시한다.
			cin >> temp;
			arr[temp-1] = 0;
		}
		else if (str == "check") {
			// check x: S에 x가 있으면 1을, 
			// 없으면 0을 출력한다. (1 ≤ x ≤ 20)
			cin >> temp;
			cout &lt;&lt; arr[temp-1] &lt;&lt; "\n";
		}
		else if (str == "toggle") {
			// toggle x : S에 x가 있으면 x를 제거하고, 
			// 없으면 x를 추가한다. (1 ≤ x ≤ 20)
			cin >> temp;
			if (arr[temp-1] == 1) arr[temp-1] = 0;
			else  arr[temp-1] = 1;
		}
		else if (str == "all") {
			// all: S를 {1, 2, ..., 20} 으로 바꾼다.
			for (int i = 0; i &lt; 20; i++) arr[i] = 1;
		}
		else {
			// empty: S를 공집합으로 바꾼다. 
			fill(arr, arr + 20, 0);
		}
	}

	return 0;
}
</pre>



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



<p class="has-medium-font-size"><strong>3. 비트 마스킹</strong></p>



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

using namespace std;

int S = 0; // 비트마스킹
string str;
int N, temp;

int main() {

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

	cin >> N;
	while(N-- > 0) {

		cin >> str;
		if (str == "add") {
			// add x: S에 x를 추가한다. (1 ≤ x ≤ 20) 
			// S에 x가 이미 있는 경우에는 연산을 무시한다.
			cin >> temp;
			S = S | (1 &lt;&lt; temp);
		}
		else if (str == "remove") {
			//remove x : S에서 x를 제거한다. (1 ≤ x ≤ 20) 
			// S에 x가 없는 경우에는 연산을 무시한다.
			cin >> temp;
			S = S &amp; ~(1 &lt;&lt; temp);
		}
		else if (str == "check") {
			// check x: S에 x가 있으면 1을, 
			// 없으면 0을 출력한다. (1 ≤ x ≤ 20)
			cin >> temp;
			if (S &amp; (1 &lt;&lt; temp)) cout &lt;&lt; "1\n";
			else cout &lt;&lt; "0\n";
		}
		else if (str == "toggle") {
			// toggle x : S에 x가 있으면 x를 제거하고, 
			// 없으면 x를 추가한다. (1 ≤ x ≤ 20)
			cin >> temp;
			if (S &amp; (1 &lt;&lt; temp)) {
				S = S &amp; ~(1 &lt;&lt; temp);
			}
			else {
				S = S | (1 &lt;&lt; temp);
			}
		}
		else if (str == "all") {
			// all: S를 {1, 2, ..., 20} 으로 바꾼다.
			S = (1 &lt;&lt; 21) - 1;
		}
		else {
			// empty: S를 공집합으로 바꾼다. 
			S = 0;
		}
	}

	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="1030" height="221" src="https://lycos7560.com/wp-content/uploads/image-1062.png" alt="" class="wp-image-5582" srcset="https://lycos7560.com/wp-content/uploads/image-1062.png 1030w, https://lycos7560.com/wp-content/uploads/image-1062-300x64.png 300w, https://lycos7560.com/wp-content/uploads/image-1062-768x165.png 768w" sizes="(max-width: 1030px) 100vw, 1030px" /></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-11723%eb%b2%88-%ec%a7%91%ed%95%a9-c-%eb%b9%84%ed%8a%b8%eb%a7%88%ec%8a%a4%ed%82%b9-baekjoon/5573/">백준 11723번 (집합, 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-11723%eb%b2%88-%ec%a7%91%ed%95%a9-c-%eb%b9%84%ed%8a%b8%eb%a7%88%ec%8a%a4%ed%82%b9-baekjoon/5573/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 16681번 (등산, C++, Dijkstra) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16681%eb%b2%88-%eb%93%b1%ec%82%b0-c-dijkstra-baekjoon/5559/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16681%eb%b2%88-%eb%93%b1%ec%82%b0-c-dijkstra-baekjoon/5559/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 18:14:49 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[16681]]></category>
		<category><![CDATA[16681번]]></category>
		<category><![CDATA[algorithm]]></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[Dijkstra]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[long long int]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[multimap]]></category>
		<category><![CDATA[mutimap]]></category>
		<category><![CDATA[priority_queue]]></category>
		<category><![CDATA[PriorityQueue]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[고려대]]></category>
		<category><![CDATA[고려대학교]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[길찾기]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[다익스트라]]></category>
		<category><![CDATA[데이크스트라]]></category>
		<category><![CDATA[등산]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 16681]]></category>
		<category><![CDATA[백준 16681번]]></category>
		<category><![CDATA[성취감]]></category>
		<category><![CDATA[시간]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[예제]]></category>
		<category><![CDATA[지름길]]></category>
		<category><![CDATA[체력]]></category>
		<category><![CDATA[추가 반례]]></category>
		<category><![CDATA[추가 예제]]></category>
		<category><![CDATA[추가반례]]></category>
		<category><![CDATA[추가예제]]></category>
		<category><![CDATA[컴파일 에러]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[틀렸습니다]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5559</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 16681번 '등산' 문제에 대한 글입니다. Dijkstra 알고리즘을 이용하여 해결하였습니다. (This is an article about the 'climbing' problem in BAEKJOON No. 16681. It was solved using Dijkstra algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16681%eb%b2%88-%eb%93%b1%ec%82%b0-c-dijkstra-baekjoon/5559/">백준 16681번 (등산, C++, Dijkstra) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



<h1 class="wp-block-heading">등산</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/16681">https://www.acmicpc.n</a><a href="https://www.acmicpc.net/problem/16681" target="_blank" rel="noreferrer noopener">et/problem/16681</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">3180</td><td class="has-text-align-left" data-align="left">827</td><td class="has-text-align-left" data-align="left">568</td><td class="has-text-align-left" data-align="left">22.576%</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">1. 주환이는 지도의 임의의 지점을 골라, 그 지점을 목표로 정한다. 집 또는 고려대학교는 목표로 선택할 수 없다.</p>



<p class="has-medium-font-size">2. 주환이가 집에서 정한 목표에 도달할 때 까지는 항상 높이가 증가하는 방향으로만 이동해야 한다.</p>



<p class="has-medium-font-size">3. 주환이가 정한 목표에 도달한 후, 고려대학교로 갈 때에는 항상 높이가 감소하는 방향으로만 이동해야 한다.</p>



<p class="has-medium-font-size">4. 주환이는 거리 1을 움직일 때 마다&nbsp;<em>D&nbsp;</em>의 체력이 소모된다.</p>



<p class="has-medium-font-size">5. 주환이는 정한 목표에 도달하면 높이 1당&nbsp;<em>E</em>&nbsp;의 성취감을 얻는다. 즉 높이가&nbsp;<em>h</em>인 목표에 도달하면&nbsp;<em>hE</em>의 성취감을 얻는다.</p>



<p class="has-medium-font-size">주환이는 이 등산의 가치를 (얻은 성취감) &#8211; (소모한 체력) 으로 계산하기로 하였다. </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">높이 비례 성취감 획득량을 나타내는 정수&nbsp;<em>N</em>,&nbsp;<em>M</em>,&nbsp;<em>D</em>,&nbsp;<em>E</em>가 공백을 사이에 두고 주어진다. </p>



<p class="has-medium-font-size">(2 ≤&nbsp;<em>N</em>&nbsp;≤ 100,000, 1 ≤&nbsp;<em>M</em>&nbsp;≤ 200,000, 1&nbsp;≤&nbsp;<em>D</em>&nbsp;≤ 100, 1 ≤&nbsp;&nbsp;<em>E&nbsp;</em>≤ 100)</p>



<p class="has-medium-font-size">두 번째 줄에&nbsp;<em>N</em>개의 정수&nbsp;<em>h<sub>1</sub>, &#8230;&nbsp; ,h<sub>N</sub></em>이 공백으로 구분되어 주어진다.&nbsp;<em>h<sub>i</sub></em>는&nbsp;<em>i&nbsp;</em>번째 지점의 높이를 의미한다. </p>



<p class="has-medium-font-size">(1 ≤&nbsp;<em>h<sub>i</sub></em>&nbsp;≤ 1,000,000, 1 ≤&nbsp;<em>i&nbsp;</em>≤&nbsp;<em>N</em>)</p>



<p class="has-medium-font-size">세 번째 줄부터&nbsp;<em>M</em>개의 줄에 걸쳐 세 정수&nbsp;<em>a, b, n</em>이 공백으로 구분되어 주어진다. </p>



<p class="has-medium-font-size">이는&nbsp;<em>a</em>번 지점과&nbsp;<em>b</em>번 지점을 잇는 거리&nbsp;<em>n</em>의 양방향 경로가 있음을 의미한다. (1 ≤&nbsp;<em>a, b</em>&nbsp;≤&nbsp;<em>N</em>, 1 ≤&nbsp;<em>n</em>&nbsp;≤ 100,000)</p>



<p class="has-medium-font-size">어떤 지점에서 다른 지점으로 가는 경로가 여러 개 있을 수도 있으며 (등산로는 여러 개가 있을 수 있다), </p>



<p class="has-medium-font-size">한 지점에서 출발해 그 지점으로 돌아가는 경로가 있을 수도 있다 (쉼터에서 몇 바퀴 돌며 쉴 수도 있다).</p>



<p class="has-medium-font-size">주환이의 집은 1번 지점에 위치하고, 고려대학교는&nbsp;<em>N</em>번 지점에 위치하며 주환이의 집과 고려대학교의 높이는 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>



<p class="has-medium-font-size">만약 조건을 만족하는 등산 경로를 선택할 수 없다면, &#8220;<code>Impossible</code>&#8220;을 쌍따옴표를 제외하고 출력한다. </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="">8 13 4 9
1 4 7 3 10 2 15 1
1 2 3
3 4 2
5 6 6
7 8 2
2 3 4
6 7 2
3 6 1
4 8 3
5 1 6
8 3 5
2 5 4
4 6 3
5 3 8</pre>



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



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



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



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



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



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



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



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



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



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



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



<p><a href="https://www.acmicpc.net/category/5" target="_blank" rel="noreferrer noopener">University</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/341" target="_blank" rel="noreferrer noopener">고려대학교</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/698" target="_blank" rel="noreferrer noopener">2018 고려대학교 프로그래밍 경시대회 (KCPC)</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/1974" target="_blank" rel="noreferrer noopener">Advanced Div.</a>&nbsp;C번</p>



<p><a href="https://www.acmicpc.net/category/5" target="_blank" rel="noreferrer noopener">University</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/341" target="_blank" rel="noreferrer noopener">고려대학교</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/698" target="_blank" rel="noreferrer noopener">2018 고려대학교 프로그래밍 경시대회 (KCPC)</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/1975" target="_blank" rel="noreferrer noopener">Intermediate Div.</a>&nbsp;E번</p>



<ul class="wp-block-list">
<li>문제를 만든 사람:&nbsp;<a href="https://www.acmicpc.net/user/oree2113">oree2113</a></li>
</ul>



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/22" target="_blank" rel="noreferrer noopener">데이크스트라</a></li>
</ul>



<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)"/>



<figure class="wp-block-image size-large"><img decoding="async" width="1421" height="3000" src="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230126_031127765-1421x3000.jpg" alt="" class="wp-image-5568" srcset="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230126_031127765-1421x3000.jpg 1421w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230126_031127765-142x300.jpg 142w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230126_031127765-768x1621.jpg 768w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230126_031127765-728x1536.jpg 728w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230126_031127765-970x2048.jpg 970w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230126_031127765-scaled.jpg 910w" sizes="(max-width: 1421px) 100vw, 1421px" /></figure>



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



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



<p class="has-medium-font-size"><strong>자료형 long long 필수!</strong></p>



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



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

using namespace std;

constexpr int MAXN = 100001;
constexpr long long int INF = INT64_MAX;
constexpr long long int uINF = INT64_MIN;

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

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

// N 지점의 개수, M 지점을 잇는 경로의 개수
// D 주환이의 거리 비례 체력 소모량, E 높이 비례 성취감 획득량
int N, M, D, E;

// 각 지점의 높이를 저장하는 배열
int hArr[MAXN];

// 등산을 하는데 필요한 배열 (집 -> 산)
long long int upArr[MAXN];

long long int temp = 0;
// 결과를 저장
long long int result = uINF;

// 하산을 하는데 필요한 배열 (산 -> 고려대)
long long int downArr[MAXN];

// V1,2 지점, d : 지점 사이의 거리
int V1, V2, d;

void Dijkstra(int start, long long int arr[], vector&lt;pair&lt;int, int>> graph[])
{
    // 임시배열 초기화
    for (int i = 1; i &lt;= N; i++) arr[i] = INF;
    // 우선순위 큐에 삽입.
    myPQ.push({ 0, start }); // &lt; first : 거리 , second : 노드 인덱스 >
    arr[start] = 0;
    while (!myPQ.empty()) {
        // -를 붙이는 이유는 우선순위 큐를 이용하여 정렬하기 위함이다.
        // (최소힙으로 구현)
        long long int nCost = -myPQ.top().first;
        int now = myPQ.top().second;
        myPQ.pop();
        // 이미 담겨 있는 것보다 거리가 크면 넘어간다.
        if (arr[now] &lt; nCost) continue;
        // 해당 노드에서 연결된 모든 경로를 확인
        for (int i = 0; i &lt; graph[now].size(); i++) {
            // disSum = 임시 노드 + 현재 노드에서 i로가는 비용
            long long int disSum = nCost + graph[now][i].second;
            // 비용이 더 작다면 최단경로 테이블 값을 갱신.
            if (disSum &lt; arr[graph[now][i].first]) {
                // 임시 노드 업데이트
                arr[graph[now][i].first] = disSum;
                // 우선순위 큐에 (거리, 노드 인덱스) 푸시
                myPQ.push(make_pair(-disSum, graph[now][i].first));
            }
        }
    }
}


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

    // 문제의 조건들을 입력 받는다.
    cin >> N >> M >> D >> E;

    // 각 지점의 높이를 입력 받는다.
    for (int i = 1; i &lt;= N; i++) cin >> hArr[i];

    // 경로를 입력 받는다.
    for (int i = 0; i &lt; M; i++) {

        cin >> V1 >> V2 >> d;

        // 높이가 같을 경우에는 생각하지 않는다.
        if (hArr[V1] > hArr[V2]) { // V1의 높이가 더 높을 경우
            upGraph[V2].push_back(make_pair(V1, d));
            downGraph[V2].push_back(make_pair(V1, d));
        }
        else if (hArr[V1] &lt; hArr[V2]) { // V1의 높이가 더 낮은 경우
            upGraph[V1].push_back(make_pair(V2, d));
            downGraph[V1].push_back(make_pair(V2, d));
        }

    }

    Dijkstra(1, upArr, upGraph);
    Dijkstra(N, downArr, downGraph);

    for (int i = 1; i &lt;= N; i++) {
        if (upArr[i] == INF || downArr[i] == INF) continue;
        temp = upArr[i] + downArr[i];
        result = max(result, hArr[i] * E - temp * D);
    }

    if (result == uINF) cout &lt;&lt; "Impossible";
    else cout &lt;&lt; result;
    
    return 0;
}</pre>



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



<p class="has-medium-font-size">최악의 경우 예를 들어 N = 100,000 / M = 200,000  / <em>h<sub>i</sub></em> = i / 모든 경로 거리 1 / D = 1 / E = 100 이런 식이면</p>



<p class="has-medium-font-size">int 를 사용하면 터진다. ㅠㅠ</p>



<p class="has-medium-font-size">long long int 로 바꾸어주자</p>



<p class="has-medium-font-size">로직 문제로 오인해서 많이 틀렸다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1038" height="321" src="https://lycos7560.com/wp-content/uploads/image-1060.png" alt="" class="wp-image-5560" srcset="https://lycos7560.com/wp-content/uploads/image-1060.png 1038w, https://lycos7560.com/wp-content/uploads/image-1060-300x93.png 300w, https://lycos7560.com/wp-content/uploads/image-1060-768x238.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-16681%eb%b2%88-%eb%93%b1%ec%82%b0-c-dijkstra-baekjoon/5559/">백준 16681번 (등산, C++, Dijkstra) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16681%eb%b2%88-%eb%93%b1%ec%82%b0-c-dijkstra-baekjoon/5559/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
