<?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>map Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/map/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 08 Mar 2023 10:54:40 +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>map Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Programmers 17684 [3차] 압축 [2018 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-17684-3%ec%b0%a8-%ec%95%95%ec%b6%95-2018-kakao-blind-recruitment/33775/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-17684-3%ec%b0%a8-%ec%95%95%ec%b6%95-2018-kakao-blind-recruitment/33775/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 08 Mar 2023 10:54:37 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[3차] 압축]]></category>
		<category><![CDATA[<string>]]></category>
		<category><![CDATA[17684]]></category>
		<category><![CDATA[17684번]]></category>
		<category><![CDATA[2018 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[LZW]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[Programmers 17684]]></category>
		<category><![CDATA[Programmers 17684번]]></category>
		<category><![CDATA[string]]></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[코테]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33775</guid>

					<description><![CDATA[<p>Programmers 17684 '[3차] 압축' 문제에 대한 글입니다. [2018 KAKAO BLIND RECRUITMENT] (This article is about the programmers 17684 '[3rd] compression' problem. [2018 KAKAO BLIND RECRUITMENT])</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-17684-3%ec%b0%a8-%ec%95%95%ec%b6%95-2018-kakao-blind-recruitment/33775/">Programmers 17684 [3차] 압축 [2018 KAKAO BLIND RECRUITMENT]</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-a6d4df71      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#압축" class="uagb-toc-link__trigger">압축</a><li class="uagb-toc__list"><a href="#접근-방법" class="uagb-toc-link__trigger">접근 방법</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">압축</h1>



<p class="has-medium-font-size"><a href="https://school.programmers.co.kr/learn/courses/30/lessons/17684" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/17684</a></p>



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



<p class="has-medium-font-size">신입사원 어피치는 카카오톡으로 전송되는 메시지를 압축하여 전송 효율을 높이는 업무를 맡게 되었다. </p>



<p class="has-medium-font-size">메시지를 압축하더라도 전달되는 정보가 바뀌어서는 안 되므로, </p>



<p class="has-medium-font-size">압축 전의 정보를 완벽하게 복원 가능한 무손실 압축 알고리즘을 구현하기로 했다.</p>



<p class="has-medium-font-size">어피치는 여러 압축 알고리즘 중에서 성능이 좋고 구현이 간단한 <strong>LZW</strong>(Lempel–Ziv–Welch) 압축을 구현하기로 했다. </p>



<p class="has-medium-font-size">LZW 압축은 1983년 발표된 알고리즘으로, 이미지 파일 포맷인 GIF 등 다양한 응용에서 사용되었다.</p>



<p class="has-medium-font-size">LZW 압축은 다음 과정을 거친다.</p>



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



<p class="has-medium-font-size">1. 길이가 1인 모든 단어를 포함하도록 사전을 초기화한다.</p>



<p class="has-medium-font-size">2. 사전에서 현재 입력과 일치하는 가장 긴 문자열 w를 찾는다.</p>



<p class="has-medium-font-size">3. w에 해당하는 사전의 색인 번호를 출력하고, 입력에서 w를 제거한다.</p>



<p class="has-medium-font-size">4. 입력에서 처리되지 않은 다음 글자가 남아있다면(c), w+c에 해당하는 단어를 사전에 등록한다.</p>



<p class="has-medium-font-size">5. 단계 2로 돌아간다.</p>



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



<p class="has-medium-font-size">압축 알고리즘이 영문 대문자만 처리한다고 할 때, 사전은 다음과 같이 초기화된다. </p>



<p class="has-medium-font-size">사전의 색인 번호는 정수값으로 주어지며, 1부터 시작한다고 하자.</p>



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



<figure 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">1</th><th class="has-text-align-left" data-align="left">2</th><th class="has-text-align-left" data-align="left">3</th><th class="has-text-align-left" data-align="left">&#8230;</th><th class="has-text-align-left" data-align="left">24</th><th class="has-text-align-left" data-align="left">25</th><th class="has-text-align-left" data-align="left">26</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">단어</td><td class="has-text-align-left" data-align="left">A</td><td class="has-text-align-left" data-align="left">B</td><td class="has-text-align-left" data-align="left">C</td><td class="has-text-align-left" data-align="left">&#8230;</td><td class="has-text-align-left" data-align="left">X</td><td class="has-text-align-left" data-align="left">Y</td><td class="has-text-align-left" data-align="left">Z</td></tr></tbody></table></figure>



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



<p class="has-medium-font-size">예를 들어 입력으로 <code>KAKAO</code>가 들어온다고 하자.</p>



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



<p class="has-medium-font-size">1. 현재 사전에는 <code>KAKAO</code>의 첫 글자 <code>K</code>는 등록되어 있으나, 두 번째 글자까지인 <code>KA</code>는 없으므로, 첫 글자 <code>K</code>에 해당하는 색인 번호 11을 출력하고, 다음 글자인 <code>A</code>를 포함한 <code>KA</code>를 사전에 27 번째로 등록한다.</p>



<p class="has-medium-font-size">2. 두 번째 글자 <code>A</code>는 사전에 있으나, 세 번째 글자까지인 <code>AK</code>는 사전에 없으므로, <code>A</code>의 색인 번호 1을 출력하고, <code>AK</code>를 사전에 28 번째로 등록한다.</p>



<p class="has-medium-font-size">3. 세 번째 글자에서 시작하는 <code>KA</code>가 사전에 있으므로, <code>KA</code>에 해당하는 색인 번호 27을 출력하고, 다음 글자 <code>O</code>를 포함한 <code>KAO</code>를 29 번째로 등록한다.</p>



<p class="has-medium-font-size">4. 마지막으로 처리되지 않은 글자 <code>O</code>에 해당하는 색인 번호 15를 출력한다.</p>



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



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">현재 입력(w)</th><th class="has-text-align-left" data-align="left">다음 글자(c)</th><th class="has-text-align-left" data-align="left">출력</th><th class="has-text-align-left" data-align="left">사전 추가(w+c)</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">K</td><td class="has-text-align-left" data-align="left">A</td><td class="has-text-align-left" data-align="left">11</td><td class="has-text-align-left" data-align="left">27: KA</td></tr><tr><td class="has-text-align-left" data-align="left">A</td><td class="has-text-align-left" data-align="left">K</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">28: AK</td></tr><tr><td class="has-text-align-left" data-align="left">KA</td><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">27</td><td class="has-text-align-left" data-align="left">29: KAO</td></tr><tr><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left"></td><td class="has-text-align-left" data-align="left">15</td><td class="has-text-align-left" data-align="left"></td></tr></tbody></table></figure>



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



<p class="has-medium-font-size">이 과정을 거쳐 다섯 글자의 문장 <code>KAKAO</code>가 4개의 색인 번호 [11, 1, 27, 15]로 압축된다.</p>



<p class="has-medium-font-size">입력으로 <code>TOBEORNOTTOBEORTOBEORNOT</code>가 들어오면 다음과 같이 압축이 진행된다.</p>



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



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">현재 입력(w)</th><th class="has-text-align-left" data-align="left">다음 글자(c)</th><th class="has-text-align-left" data-align="left">출력</th><th class="has-text-align-left" data-align="left">사전 추가(w+c)</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">T</td><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">20</td><td class="has-text-align-left" data-align="left">27: TO</td></tr><tr><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">B</td><td class="has-text-align-left" data-align="left">15</td><td class="has-text-align-left" data-align="left">28: OB</td></tr><tr><td class="has-text-align-left" data-align="left">B</td><td class="has-text-align-left" data-align="left">E</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">29: BE</td></tr><tr><td class="has-text-align-left" data-align="left">E</td><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">30: EO</td></tr><tr><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">R</td><td class="has-text-align-left" data-align="left">15</td><td class="has-text-align-left" data-align="left">31: OR</td></tr><tr><td class="has-text-align-left" data-align="left">R</td><td class="has-text-align-left" data-align="left">N</td><td class="has-text-align-left" data-align="left">18</td><td class="has-text-align-left" data-align="left">32: RN</td></tr><tr><td class="has-text-align-left" data-align="left">N</td><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">14</td><td class="has-text-align-left" data-align="left">33: NO</td></tr><tr><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">T</td><td class="has-text-align-left" data-align="left">15</td><td class="has-text-align-left" data-align="left">34: OT</td></tr><tr><td class="has-text-align-left" data-align="left">T</td><td class="has-text-align-left" data-align="left">T</td><td class="has-text-align-left" data-align="left">20</td><td class="has-text-align-left" data-align="left">35: TT</td></tr><tr><td class="has-text-align-left" data-align="left">TO</td><td class="has-text-align-left" data-align="left">B</td><td class="has-text-align-left" data-align="left">27</td><td class="has-text-align-left" data-align="left">36: TOB</td></tr><tr><td class="has-text-align-left" data-align="left">BE</td><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">29</td><td class="has-text-align-left" data-align="left">37: BEO</td></tr><tr><td class="has-text-align-left" data-align="left">OR</td><td class="has-text-align-left" data-align="left">T</td><td class="has-text-align-left" data-align="left">31</td><td class="has-text-align-left" data-align="left">38: ORT</td></tr><tr><td class="has-text-align-left" data-align="left">TOB</td><td class="has-text-align-left" data-align="left">E</td><td class="has-text-align-left" data-align="left">36</td><td class="has-text-align-left" data-align="left">39: TOBE</td></tr><tr><td class="has-text-align-left" data-align="left">EO</td><td class="has-text-align-left" data-align="left">R</td><td class="has-text-align-left" data-align="left">30</td><td class="has-text-align-left" data-align="left">40: EOR</td></tr><tr><td class="has-text-align-left" data-align="left">RN</td><td class="has-text-align-left" data-align="left">O</td><td class="has-text-align-left" data-align="left">32</td><td class="has-text-align-left" data-align="left">41: RNO</td></tr><tr><td class="has-text-align-left" data-align="left">OT</td><td class="has-text-align-left" data-align="left"></td><td class="has-text-align-left" data-align="left">34</td><td class="has-text-align-left" data-align="left"></td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading">입력 형식</h3>



<p class="has-medium-font-size">입력으로 영문 대문자로만 이뤄진 문자열 <code>msg</code>가 주어진다. </p>



<p class="has-medium-font-size"><code>msg</code>의 길이는 1 글자 이상, 1000 글자 이하이다.</p>



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



<h3 class="wp-block-heading">출력 형식</h3>



<p class="has-medium-font-size">주어진 문자열을 압축한 후의 사전 색인 번호를 배열로 출력하라.</p>



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



<h3 class="wp-block-heading">입출력 예제</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">msg</th><th class="has-text-align-left" data-align="left">answer</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left"><code>KAKAO</code></td><td class="has-text-align-left" data-align="left">[11, 1, 27, 15]</td></tr><tr><td class="has-text-align-left" data-align="left"><code>TOBEORNOTTOBEORTOBEORNOT</code></td><td class="has-text-align-left" data-align="left">[20, 15, 2, 5, 15, 18, 14, 15, 20, 27, 29, 31, 36, 30, 32, 34]</td></tr><tr><td class="has-text-align-left" data-align="left"><code>ABABABABABABABAB</code></td><td class="has-text-align-left" data-align="left">[1, 2, 27, 29, 28, 31, 30]</td></tr></tbody></table></figure>



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



<h1 class="wp-block-heading">접근 방법</h1>



<figure class="wp-block-image size-full is-resized"><img fetchpriority="high" decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230308_195014008.jpg" alt="" class="wp-image-33780" width="1450" height="2043" srcset="https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230308_195014008.jpg 1363w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230308_195014008-213x300.jpg 213w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230308_195014008-768x1082.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230308_195014008-1090x1536.jpg 1090w" sizes="(max-width: 1450px) 100vw, 1450px" /></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;string>
#include &lt;vector>
#include &lt;unordered_map>

using namespace std;

unordered_map&lt;string, int> myMap;

vector&lt;int> solution(string msg) {
    
    vector&lt;int> answer;

    for (int i = 1; i &lt;= 26; i++) { // 사전을 초기화
        string temp = "";
        temp.push_back('A' + i - 1);
        myMap.insert(make_pair(temp, i));
    }

    for (int j = 0; j &lt; msg.length(); j++) { // 시작 피봇
        for (int i = msg.length() - j; i >= 1; i--) { // 슬라이싱 피봇
            auto it = myMap.find(msg.substr(j, i));
            if (it != myMap.end()) {
                answer.push_back(it->second);
                if (j + i &lt; msg.length()) 
                    myMap.insert(make_pair(msg.substr(j, i + 1), myMap.size() + 1));            
                j += it->first.length() - 1;
                break;
            }
        }
    }

    return answer;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/03/image-25.png" alt="" class="wp-image-33778" width="1175" height="636" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-25.png 752w, https://lycos7560.com/wp-content/uploads/2023/03/image-25-300x162.png 300w" sizes="(max-width: 1175px) 100vw, 1175px" /></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/programmers/programmers-17684-3%ec%b0%a8-%ec%95%95%ec%b6%95-2018-kakao-blind-recruitment/33775/">Programmers 17684 [3차] 압축 [2018 KAKAO BLIND RECRUITMENT]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/programmers/programmers-17684-3%ec%b0%a8-%ec%95%95%ec%b6%95-2018-kakao-blind-recruitment/33775/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 17677 [1차] 뉴스 클러스터링 [2018 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-17677-1%ec%b0%a8-%eb%89%b4%ec%8a%a4-%ed%81%b4%eb%9f%ac%ec%8a%a4%ed%84%b0%eb%a7%81-2018-kakao-blind-recruitment/33753/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-17677-1%ec%b0%a8-%eb%89%b4%ec%8a%a4-%ed%81%b4%eb%9f%ac%ec%8a%a4%ed%84%b0%eb%a7%81-2018-kakao-blind-recruitment/33753/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 05 Mar 2023 14:57:12 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[1차] 뉴스 클러스터링]]></category>
		<category><![CDATA[17677]]></category>
		<category><![CDATA[17677번]]></category>
		<category><![CDATA[2018 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[multimap]]></category>
		<category><![CDATA[Multiset]]></category>
		<category><![CDATA[programmers 17677]]></category>
		<category><![CDATA[programmers 17677번]]></category>
		<category><![CDATA[SET]]></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>
		<guid isPermaLink="false">https://lycos7560.com/?p=33753</guid>

					<description><![CDATA[<p>programmers 17677 '[1차] 뉴스 클러스터링' 문제에 대한 글입니다. 집합에 대한 문제 입니다. [2018 KAKAO BLIND RECRUITMENT] (This article is about programmers 17677 '[primary] news clustering' problem. This is a problem with the set. [2018 KAKAO BLIND RECRUITMENT])</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-17677-1%ec%b0%a8-%eb%89%b4%ec%8a%a4-%ed%81%b4%eb%9f%ac%ec%8a%a4%ed%84%b0%eb%a7%81-2018-kakao-blind-recruitment/33753/">Programmers 17677 [1차] 뉴스 클러스터링 [2018 KAKAO BLIND RECRUITMENT]</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-711369de      "
					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:62px" aria-hidden="true" class="wp-block-spacer"></div>



<h1 class="wp-block-heading">뉴스 클러스터링</h1>



<p class="has-medium-font-size"><a href="https://school.programmers.co.kr/learn/courses/30/lessons/17677" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/17677</a></p>



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



<p class="has-medium-font-size">여러 언론사에서 쏟아지는 뉴스, 특히 속보성 뉴스를 보면 비슷비슷한 제목의 기사가 많아 정작 필요한 기사를 찾기가 어렵다. </p>



<p class="has-medium-font-size">Daum 뉴스의 개발 업무를 맡게 된 신입사원 튜브는 사용자들이 편리하게 다양한 뉴스를 찾아볼 수 있도록 문제점을 개선하는 업무를 맡게 되었다.</p>



<p class="has-medium-font-size">개발의 방향을 잡기 위해 튜브는 우선 최근 화제가 되고 있는 &#8220;카카오 신입 개발자 공채&#8221; 관련 기사를 검색해보았다.</p>



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



<p class="has-medium-font-size">카카오 첫 공채..&#8217;블라인드&#8217; 방식 채용</p>



<p class="has-medium-font-size">카카오, 합병 후 첫 공채.. 블라인드 전형으로 개발자 채용</p>



<p class="has-medium-font-size">카카오, 블라인드 전형으로 신입 개발자 공채</p>



<p class="has-medium-font-size">카카오 공채, 신입 개발자 코딩 능력만 본다</p>



<p class="has-medium-font-size">카카오, 신입 공채.. &#8220;코딩 실력만 본다&#8221;</p>



<p class="has-medium-font-size">카카오 &#8220;코딩 능력만으로 2018 신입 개발자 뽑는다&#8221;</p>



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



<p class="has-medium-font-size">기사의 제목을 기준으로 &#8220;블라인드 전형&#8221;에 주목하는 기사와 &#8220;코딩 테스트&#8221;에 주목하는 기사로 나뉘는 걸 발견했다. </p>



<p class="has-medium-font-size">튜브는 이들을 각각 묶어서 보여주면 카카오 공채 관련 기사를 찾아보는 사용자에게 유용할 듯싶었다.</p>



<p class="has-medium-font-size">유사한 기사를 묶는 기준을 정하기 위해서 논문과 자료를 조사하던 튜브는 &#8220;자카드 유사도&#8221;라는 방법을 찾아냈다.</p>



<p class="has-medium-font-size">자카드 유사도는 집합 간의 유사도를 검사하는 여러 방법 중의 하나로 알려져 있다. </p>



<p class="has-medium-font-size">두 집합&nbsp;<code>A</code>,&nbsp;<code>B</code>&nbsp;사이의 자카드 유사도&nbsp;<code>J(A, B)</code>는 두 집합의 교집합 크기를 두 집합의 합집합 크기로 나눈 값으로 정의된다.</p>



<p class="has-medium-font-size">예를 들어 집합&nbsp;<code>A</code>&nbsp;= {1, 2, 3}, 집합&nbsp;<code>B</code>&nbsp;= {2, 3, 4}라고 할 때, 교집합&nbsp;<code>A ∩ B</code>&nbsp;= {2, 3}, 합집합&nbsp;<code>A ∪ B</code>&nbsp;= {1, 2, 3, 4}이 되므로, </p>



<p class="has-medium-font-size">집합&nbsp;<code>A</code>,&nbsp;<code>B</code>&nbsp;사이의 자카드 유사도&nbsp;<code>J(A, B)</code>&nbsp;= 2/4 = 0.5가 된다. </p>



<p class="has-medium-font-size">집합 A와 집합 B가 모두 공집합일 경우에는 나눗셈이 정의되지 않으니 따로&nbsp;<code>J(A, B)</code>&nbsp;= 1로 정의한다.</p>



<p class="has-medium-font-size">자카드 유사도는 원소의 중복을 허용하는 다중집합에 대해서 확장할 수 있다. </p>



<p class="has-medium-font-size">다중집합&nbsp;<code>A</code>는 원소 &#8220;1&#8221;을 3개 가지고 있고, 다중집합&nbsp;<code>B</code>는 원소 &#8220;1&#8221;을 5개 가지고 있다고 하자. </p>



<p class="has-medium-font-size">이 다중집합의 교집합&nbsp;<code>A ∩ B</code>는 원소 &#8220;1&#8221;을 min(3, 5)인 3개, 합집합&nbsp;<code>A ∪ B</code>는 원소 &#8220;1&#8221;을 max(3, 5)인 5개 가지게 된다. </p>



<p class="has-medium-font-size">다중집합&nbsp;<code>A</code>&nbsp;= {1, 1, 2, 2, 3}, 다중집합&nbsp;<code>B</code>&nbsp;= {1, 2, 2, 4, 5}라고 하면, 교집합&nbsp;<code>A ∩ B</code>&nbsp;= {1, 2, 2}, 합집합&nbsp;<code>A ∪ B</code>&nbsp;= {1, 1, 2, 2, 3, 4, 5}가 되므로, </p>



<p class="has-medium-font-size">자카드 유사도&nbsp;<code>J(A, B)</code>&nbsp;= 3/7, 약 0.42가 된다.</p>



<p>이를 이용하여 문자열 사이의 유사도를 계산하는데 이용할 수 있다. </p>



<p>문자열 &#8220;FRANCE&#8221;와 &#8220;FRENCH&#8221;가 주어졌을 때, 이를 두 글자씩 끊어서 다중집합을 만들 수 있다. </p>



<p>각각 {FR, RA, AN, NC, CE}, {FR, RE, EN, NC, CH}가 되며, 교집합은 {FR, NC}, 합집합은 {FR, RA, AN, NC, CE, RE, EN, CH}가 되므로, </p>



<p>두 문자열 사이의 자카드 유사도&nbsp;<code>J("FRANCE", "FRENCH")</code>&nbsp;= 2/8 = 0.25가 된다.</p>



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



<h3 class="wp-block-heading">입력 형식</h3>



<ul class="wp-block-list">
<li>입력으로는&nbsp;<code>str1</code>과&nbsp;<code>str2</code>의 두 문자열이 들어온다. 각 문자열의 길이는 2 이상, 1,000 이하이다.</li>



<li>입력으로 들어온 문자열은 두 글자씩 끊어서 다중집합의 원소로 만든다. 이때 영문자로 된 글자 쌍만 유효하고, <br>기타 공백이나 숫자, 특수 문자가 들어있는 경우는 그 글자 쌍을 버린다. 예를 들어 &#8220;ab+&#8221;가 입력으로 들어오면, &#8220;ab&#8221;만 다중집합의 원소로 삼고, &#8220;b+&#8221;는 버린다.</li>



<li>다중집합 원소 사이를 비교할 때, 대문자와 소문자의 차이는 무시한다. &#8220;AB&#8221;와 &#8220;Ab&#8221;, &#8220;ab&#8221;는 같은 원소로 취급한다.</li>
</ul>



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



<h3 class="wp-block-heading">출력 형식</h3>



<p class="has-medium-font-size">입력으로 들어온 두 문자열의 자카드 유사도를 출력한다. </p>



<p class="has-medium-font-size">유사도 값은 0에서 1 사이의 실수이므로, 이를 다루기 쉽도록 65536을 곱한 후에 소수점 아래를 버리고 정수부만 출력한다.</p>



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



<h3 class="wp-block-heading">예제 입출력</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left"><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-ast-global-color-0-color">str1</mark></th><th class="has-text-align-left" data-align="left"><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-ast-global-color-0-color">str2</mark></th><th class="has-text-align-left" data-align="left"><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-ast-global-color-0-color">answer</mark></th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">FRANCE</td><td class="has-text-align-left" data-align="left">french</td><td class="has-text-align-left" data-align="left">16384</td></tr><tr><td class="has-text-align-left" data-align="left">handshake</td><td class="has-text-align-left" data-align="left">shake hands</td><td class="has-text-align-left" data-align="left">65536</td></tr><tr><td class="has-text-align-left" data-align="left">aa1+aa2</td><td class="has-text-align-left" data-align="left">AAAA12</td><td class="has-text-align-left" data-align="left">43690</td></tr><tr><td class="has-text-align-left" data-align="left">E=M*C^2</td><td class="has-text-align-left" data-align="left">e=m*c^2</td><td class="has-text-align-left" data-align="left">65536</td></tr><tr><td class="has-text-align-left" data-align="left">&#8220;A+C&#8221;</td><td class="has-text-align-left" data-align="left">&#8220;DEF&#8221;</td><td class="has-text-align-left" data-align="left">0</td></tr></tbody></table></figure>



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



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

using namespace std;

unordered_map&lt;string, int> mMap1;
unordered_map&lt;string, int> mMap2;
unordered_map&lt;string, int> uMap;

int solution(string str1, string str2) {
    int answer = 0;
    string tempstr1, tempstr2;

    // 대문자를 소문자로 변환
    for (int i = 0; i &lt; str1.length(); i++) {
        if (str1[i] >= 'A' &amp;&amp; str1[i] &lt;= 'Z') {
            str1[i] = tolower(str1[i]);
            tempstr1.push_back(str1[i]);
        }
        else if (str1[i] >= 'a' &amp;&amp; str1[i] &lt;= 'z') tempstr1.push_back(str1[i]);
        else tempstr1.push_back(' ');
    }

    for (int i = 0; i &lt; tempstr1.length() - 1; i++) {
        string temp = tempstr1.substr(i, 2);
        if (temp[0] == ' ' || temp[1] == ' ') continue;
        auto it = mMap1.find(temp);
        if (it != mMap1.end()) mMap1.find(temp)->second++;
        else mMap1.insert(make_pair(temp, 1));
        
    }

    // 대문자를 소문자로 변환
    for (int i = 0; i &lt; str2.length(); i++) {
        if (str2[i] >= 'A' &amp;&amp; str2[i] &lt;= 'Z') {
            str2[i] = tolower(str2[i]);
            tempstr2.push_back(str2[i]);
        }
        else if (str2[i] >= 'a' &amp;&amp; str2[i] &lt;= 'z') tempstr2.push_back(str2[i]);
        else tempstr2.push_back(' ');
    }

    for (int i = 0; i &lt; tempstr2.length() - 1; i++) {
        string temp = tempstr2.substr(i, 2);
        if (temp[0] == ' ' || temp[1] == ' ') continue;
        auto it = mMap2.find(temp);
        if (it != mMap2.end()) mMap2.find(temp)->second++;
        else mMap2.insert(make_pair(temp, 1));

    }

    float Union = 0, intersection = 0;

    for (auto &amp;it : mMap1) {

        auto it2 = mMap2.find(it.first);

        if (it2 != mMap2.end()) intersection += min(it.second, it2->second);
        
        uMap.insert(make_pair(it.first, it.second));
    }

    for (auto&amp; it : mMap2) {

        auto it2 = mMap1.find(it.first);

        if (it2 != mMap1.end()) it.second = max(it.second, it2->second);

        if (uMap.find(it.first) != uMap.end()) uMap.find(it.first)->second = max(uMap.find(it.first)->second, it.second);
        else uMap.insert(make_pair(it.first, it.second));

    }

    for (auto&amp; it : uMap) Union += it.second;
    
    if (mMap1.size() || mMap2.size()) answer = (intersection / Union) * 65536;
    else answer = 1 * 65536;

    return answer;
}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1163" height="384" src="https://lycos7560.com/wp-content/uploads/2023/03/image-23.png" alt="" class="wp-image-33756" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-23.png 1163w, https://lycos7560.com/wp-content/uploads/2023/03/image-23-300x99.png 300w, https://lycos7560.com/wp-content/uploads/2023/03/image-23-768x254.png 768w" sizes="(max-width: 1163px) 100vw, 1163px" /></figure>



<div style="height:59px" 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/programmers/programmers-17677-1%ec%b0%a8-%eb%89%b4%ec%8a%a4-%ed%81%b4%eb%9f%ac%ec%8a%a4%ed%84%b0%eb%a7%81-2018-kakao-blind-recruitment/33753/">Programmers 17677 [1차] 뉴스 클러스터링 [2018 KAKAO BLIND RECRUITMENT]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/programmers/programmers-17677-1%ec%b0%a8-%eb%89%b4%ec%8a%a4-%ed%81%b4%eb%9f%ac%ec%8a%a4%ed%84%b0%eb%a7%81-2018-kakao-blind-recruitment/33753/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>백준 1076번 (저항, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 28 Jan 2023 15:33:10 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1076]]></category>
		<category><![CDATA[1076번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[pair]]></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[백준 1076]]></category>
		<category><![CDATA[백준 1076번]]></category>
		<category><![CDATA[시뮬레이션]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[저항]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5713</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1076번 '저항' 문제에 대한 글입니다. 단순 구현 문제입니다. (This is an article on the 'resistance' problem in BAEKJOON No. 1076. It's a simple implementation problem.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/">백준 1076번 (저항, 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/1076" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1076</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">25774</td><td class="has-text-align-left" data-align="left">11409</td><td class="has-text-align-left" data-align="left">9784</td><td class="has-text-align-left" data-align="left">44.643%</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">저항은 색 3개를 이용해서 그 저항이 몇 옴인지 나타낸다. </p>



<p class="has-medium-font-size">처음 색 2개는 저항의 값이고, 마지막 색은 곱해야 하는 값이다. </p>



<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="628" height="777" src="https://lycos7560.com/wp-content/uploads/2023/01/image-35.png" alt="" class="wp-image-5714" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-35.png 628w, https://lycos7560.com/wp-content/uploads/2023/01/image-35-242x300.png 242w" sizes="(max-width: 628px) 100vw, 628px" /></figure>



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



<p class="has-medium-font-size">예를 들어, 저항의 색이 yellow, violet, red였다면 저항의 값은 4,700이 된다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 첫 번째 색, 둘째 줄에 두 번째 색, 셋째 줄에 세 번째 색이 주어진다. </p>



<p class="has-medium-font-size">위의 표에 있는 색만 입력으로 주어진다.</p>



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



<h2 class="wp-block-heading">출력</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="">yellow
violet
red</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="">4700</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="">orange
red
blue</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="">32000000</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="">white
white
white</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="">99000000000</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/shiroed1211" target="_blank" rel="noreferrer noopener">shiroed1211</a></li>
</ul>



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102">구현</a></li>
</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>



<div style="height:40px" 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;map>

using namespace std;

string str;

long long int result;

multimap&lt;string, pair&lt;int, long long int>> mMap = { 
		{"black", make_pair(0, 1)},
		{"brown", make_pair(1, 10)},
		{"red", make_pair(2, 100)},
		{"orange", make_pair(3, 1000)},
		{"yellow", make_pair(4, 10000)},
		{"green", make_pair(5, 100000)},
		{"blue", make_pair(6, 1000000)},
		{"violet", make_pair(7, 10000000)},
		{"grey", make_pair(8, 100000000)},
		{"white", make_pair(9, 1000000000)}
};

int main()
{
	cin >> str;
	result += (mMap.find(str)->second.first * 10);
	cin >> str;
	result += (mMap.find(str)->second.first);
	cin >> str;
	result *= (mMap.find(str)->second.second);
	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="1248" height="126" src="https://lycos7560.com/wp-content/uploads/2023/01/image-36.png" alt="" class="wp-image-5715" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-36.png 1248w, https://lycos7560.com/wp-content/uploads/2023/01/image-36-300x30.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-36-768x78.png 768w" sizes="(max-width: 1248px) 100vw, 1248px" /></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-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/">백준 1076번 (저항, 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-1076%eb%b2%88-%ec%a0%80%ed%95%ad-c-baekjoon/5713/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>백준 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>
		<item>
		<title>백준 18870번 (좌표 압축, C++, Map) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 25 Jan 2023 12:53:29 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[18870]]></category>
		<category><![CDATA[18870번]]></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[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[sort]]></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[백준 18870]]></category>
		<category><![CDATA[백준 18870번]]></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=5547</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 18870번 '좌표 압축' 문제에 대한 글입니다. 'map' 자료구조를 이용하여 해결하였습니다. (This is an article about the problem of 'coordinate compression' in BAEKJOON 1880. I solved it using 'map' data structure.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/">백준 18870번 (좌표 압축, C++, Map) [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/18870" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/18870</a></p>



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">54604</td><td class="has-text-align-left" data-align="left">22882</td><td class="has-text-align-left" data-align="left">17501</td><td class="has-text-align-left" data-align="left">39.800%</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개의 좌표 X<sub>1</sub>, X<sub>2</sub>, &#8230;, X<sub>N</sub>이 있다. 이 좌표에 좌표 압축을 적용하려고 한다.</p>



<p class="has-medium-font-size">X<sub>i</sub>를 좌표 압축한 결과 X&#8217;<sub>i</sub>의 값은 X<sub>i</sub>&nbsp;&gt; X<sub>j</sub>를 만족하는 서로 다른 좌표의 개수와 같아야 한다.</p>



<p class="has-medium-font-size">X<sub>1</sub>, X<sub>2</sub>, &#8230;, X<sub>N</sub>에 좌표 압축을 적용한 결과 X&#8217;<sub>1</sub>, X&#8217;<sub>2</sub>, &#8230;, X&#8217;<sub>N</sub>를 출력해보자.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 N이 주어진다.</p>



<p class="has-medium-font-size">둘째 줄에는 공백 한 칸으로 구분된 X<sub>1</sub>, X<sub>2</sub>, &#8230;, X<sub>N</sub>이 주어진다.</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">첫째 줄에 X&#8217;<sub>1</sub>, X&#8217;<sub>2</sub>, &#8230;, X&#8217;<sub>N</sub>을 공백 한 칸으로 구분해서 출력한다.</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 ≤ 1,000,000</li>



<li>-10<sup>9</sup>&nbsp;≤ X<sub>i</sub>&nbsp;≤ 10<sup>9</sup></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
2 4 -10 4 -9</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="">2 3 0 3 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="">6
1000 999 1000 999 1000 999</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="">1 0 1 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>
</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/97" target="_blank" rel="noreferrer noopener">정렬</a></li>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="1329" src="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021.jpg" alt="" class="wp-image-5551" srcset="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021.jpg 1600w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021-300x249.jpg 300w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021-768x638.jpg 768w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230125_214732021-1536x1276.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



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



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



<div style="height: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;map>

using namespace std;

int arrN[1000001];
int number[1000000];

map&lt;int, int> myMap;

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

	cin >> arrN[0];

	for (int i = 1; i &lt;= arrN[0]; i++) cin >> arrN[i];

	// map을 이용한 정렬 
	for (int i = 1; i &lt;= arrN[0]; i++) 
		myMap.insert(make_pair(arrN[i], 0)); 

	int cnt = 0;
	for (auto it = myMap.begin(); it != myMap.end(); it++) 
		it->second = cnt++;

	for (int i = 1; i &lt;= arrN[0]; i++) 
		cout &lt;&lt; myMap.find(arrN[i])->second &lt;&lt; " ";

	return 0;
}
</pre>



<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="1027" height="219" src="https://lycos7560.com/wp-content/uploads/image-1059.png" alt="" class="wp-image-5549" srcset="https://lycos7560.com/wp-content/uploads/image-1059.png 1027w, https://lycos7560.com/wp-content/uploads/image-1059-300x64.png 300w, https://lycos7560.com/wp-content/uploads/image-1059-768x164.png 768w" sizes="(max-width: 1027px) 100vw, 1027px" /></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-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/">백준 18870번 (좌표 압축, C++, Map) [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-18870%eb%b2%88-%ec%a2%8c%ed%91%9c-%ec%95%95%ec%b6%95-c-map-baekjoon/5547/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 2211번 (네트워크 복구, C++, Dijkstra) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2211%eb%b2%88-%eb%84%a4%ed%8a%b8%ec%9b%8c%ed%81%ac-%eb%b3%b5%ea%b5%ac-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5453/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2211%eb%b2%88-%eb%84%a4%ed%8a%b8%ec%9b%8c%ed%81%ac-%eb%b3%b5%ea%b5%ac-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5453/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 24 Jan 2023 14:13:16 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[2211]]></category>
		<category><![CDATA[2211번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Dijkstra]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[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[백준 2211]]></category>
		<category><![CDATA[백준 2211번]]></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=5453</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 2211번 '네트워크 복구' 문제에 대한 글입니다. Dijkstra 알고리즘과 자료구조 'map' 을 이용하여 해결하였습니다. (This is an article on the 'Network Recovery' problem in BAEKJOON No. 2211. It was solved using Dijkstra algorithm and data structure 'map'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-2211%eb%b2%88-%eb%84%a4%ed%8a%b8%ec%9b%8c%ed%81%ac-%eb%b3%b5%ea%b5%ac-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5453/">백준 2211번 (네트워크 복구, 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/2211" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/2211</a></p>



<div style="height:30px" 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">192 MB</td><td class="has-text-align-left" data-align="left">5644</td><td class="has-text-align-left" data-align="left">2849</td><td class="has-text-align-left" data-align="left">1960</td><td class="has-text-align-left" data-align="left">48.951%</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(1 ≤ N ≤ 1,000)개의 컴퓨터로 구성된 네트워크가 있다. </p>



<p class="has-medium-font-size">이들 중 몇 개의 컴퓨터들은 서로 네트워크 연결이 되어 있어 서로 다른 두 컴퓨터 간 통신이 가능하도록 되어 있다. </p>



<p class="has-medium-font-size">통신을 할 때에는 서로 직접 연결되어 있는 회선을 이용할 수도 있으며, 회선과 다른 컴퓨터를 거쳐서 통신을 할 수도 있다.</p>



<p class="has-medium-font-size">각 컴퓨터들과 회선은 그 성능이 차이가 날 수 있다. </p>



<p class="has-medium-font-size">따라서 각각의 직접 연결되어 있는 회선을 이용해서 통신을 하는데 걸리는 시간이 서로 다를 수 있다. </p>



<p class="has-medium-font-size">심지어는 직접 연결되어 있는 회선이 오히려 더 느려서, 다른 컴퓨터를 통해서 통신을 하는 것이 더 유리할 수도 있다. </p>



<p class="has-medium-font-size">직접 연결되어 있는 회선을 사용할 경우에는 그 회선을 이용해서 통신을 하는 데 드는 시간만큼이 들게 된다. </p>



<p class="has-medium-font-size">여러 개의 회선을 거치는 경우에는 각 회선을 이용해서 통신을 하는 데 드는 시간의 합만큼의 시간이 걸리게 된다.</p>



<p class="has-medium-font-size">어느 날, 해커가 네트워크에 침입하였다. </p>



<p class="has-medium-font-size">네트워크의 관리자는 우선 모든 회선과 컴퓨터를 차단한 후, 해커의 공격을 막을 수 있었다.</p>



<p class="has-medium-font-size"> 관리자는 컴퓨터에 보안 시스템을 설치하려 하였는데, 버전 문제로 보안 시스템을 한 대의 슈퍼컴퓨터에만 설치할 수 있었다. </p>



<p class="has-medium-font-size">한 컴퓨터가 공격을 받게 되면, 네트워크를 통해 슈퍼컴퓨터에 이 사실이 전달이 되고, </p>



<p class="has-medium-font-size">그러면 슈퍼컴퓨터에서는 네트워크를 이용해서 보안 패킷을 전송하는 방식을 사용하기로 하였다. </p>



<p class="has-medium-font-size">준비를 마친 뒤, 관리자는 다시 네트워크를 복구하기로 하였다. 이때, 다음의 조건들이 만족되어야 한다.</p>



<p class="has-medium-font-size">1. 해커가 다시 공격을 할 우려가 있기 때문에, 최소 개수의 회선만을 복구해야 한다. </p>



<p class="has-medium-font-size">물론, 그렇다면 아무 회선도 복구하지 않으면 되겠지만, 이럴 경우 네트워크의 사용에 지장이 생기게 된다. </p>



<p class="has-medium-font-size">따라서 네트워크를 복구한 후에 서로 다른 두 컴퓨터 간에 통신이 가능하도록 복구해야 한다.</p>



<p class="has-medium-font-size">2. 네트워크를 복구해서 통신이 가능하도록 만드는 것도 중요하지만, </p>



<p class="has-medium-font-size">해커에게 공격을 받았을 때 보안 패킷을 전송하는 데 걸리는 시간도 중요한 문제가 된다. </p>



<p class="has-medium-font-size">따라서 슈퍼컴퓨터가 다른 컴퓨터들과 통신하는데 걸리는 최소 시간이, </p>



<p class="has-medium-font-size">원래의 네트워크에서 통신하는데 걸리는 최소 시간보다 커져서는 안 된다.</p>



<p class="has-medium-font-size">원래의 네트워크에 대한 정보가 주어졌을 때, </p>



<p class="has-medium-font-size">위의 조건을 만족하면서 네트워크를 복구하는 방법을 알아내는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 두 정수 N, M이 주어진다. </p>



<p class="has-medium-font-size">다음 M개의 줄에는 회선의 정보를 나타내는 세 정수 A, B, C가 주어진다. </p>



<p class="has-medium-font-size">이는 A번 컴퓨터와 B번 컴퓨터가 통신 시간이 C (1 ≤ C ≤ 10)인 회선으로 연결되어 있다는 의미이다. </p>



<p class="has-medium-font-size">컴퓨터들의 번호는 1부터 N까지의 정수이며, 1번 컴퓨터는 보안 시스템을 설치할 슈퍼컴퓨터이다. </p>



<p class="has-medium-font-size">모든 통신은 완전쌍방향 방식으로 이루어지기 때문에, </p>



<p class="has-medium-font-size">한 회선으로 연결된 두 컴퓨터는 어느 방향으로도 통신할 수 있다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 복구할 회선의 개수 K를 출력한다. </p>



<p class="has-medium-font-size">다음 K개의 줄에는 복구한 회선을 나타내는 두 정수 A, B를 출력한다. </p>



<p class="has-medium-font-size">이는 A번 컴퓨터와 B번 컴퓨터를 연결하던 회선을 복구한다는 의미이다. </p>



<p class="has-medium-font-size">출력은 임의의 순서대로 하며, 답이 여러 개 존재하는 경우에는 아무 것이나 하나만 출력하면 된다.</p>



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



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



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



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



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



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



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



<p><a href="https://www.acmicpc.net/board/view/70830" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/view/70830</a> &lt;- 참조</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">24 45
20 16 5 
24 7 9 
24 18 6 
4 2 7 
23 5 7 
8 19 5 
1 6 3 
9 8 7 
2 3 5 
11 12 4 
4 20 1 
2 16 5 
22 11 1 
17 10 4 
3 7 4 
18 10 9 
21 2 5 
20 18 3 
5 10 5 
15 2 4 
14 10 7 
4 15 9 
20 10 8 
14 12 8 
12 8 1 
23 14 8 
15 24 9 
12 5 1 
15 8 3 
21 15 7 
12 7 6 
18 12 5 
13 7 2 
7 10 3 
24 5 1 
15 10 7 
3 2 2 
22 5 6 
3 16 4 
1 12 1 
9 17 3 
17 12 7 
8 12 8 
11 15 7 
4 9 5</pre>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">23
2 15
3 7
4 20
5 12
6 1
7 12
8 12
9 8
10 5
11 12
12 1
13 7
14 12
15 8
16 20
17 12
18 12
19 8
20 18
21 15
22 11
23 5
24 5</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/his130" target="_blank" rel="noreferrer noopener">his130</a></li>



<li>어색한 표현을 찾은 사람: <a href="https://www.acmicpc.net/user/mwy3055" target="_blank" rel="noreferrer noopener">mwy3055</a></li>
</ul>



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



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



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



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



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



<h2 class="wp-block-heading">풀이 과정</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="1091" height="1920" src="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230124_230823201-scaled.jpg" alt="" class="wp-image-5464" srcset="https://lycos7560.com/wp-content/uploads/KakaoTalk_20230124_230823201-scaled.jpg 1091w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230124_230823201-170x300.jpg 170w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230124_230823201-768x1352.jpg 768w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230124_230823201-873x1536.jpg 873w, https://lycos7560.com/wp-content/uploads/KakaoTalk_20230124_230823201-1164x2048.jpg 1164w" sizes="(max-width: 1091px) 100vw, 1091px" /></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">map을 사용하는 생각이 바로 떠올라서 빠르게 해결</p>



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



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

using namespace std;

// N(1 ≤ N ≤ 1,000)개의 컴퓨터
constexpr int MAXN = 1001;
constexpr int INF = INT32_MAX;

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

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

// 문제의 결과를 출력하기 위한 map 
map&lt;int, int> myMap;

// dist[i][j]  
// => i 에서 j 까지의 최단거리 (임시 노드)
int timeArr[MAXN];

// dist[i][j]  
// => i 에서 j 까지의 최단거리 (임시 노드)
int cntArr[MAXN];

// N : 정점의 개수, M : 간선의 개수
// U: 현재 노드, V : 이웃 노드, t : 통신 시간
int N, M, U, V, t;


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

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

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

        // 해당 노드에서 연결된 모든 경로를 확인
        for (int i = 0; i &lt; graph[now].size(); i++) {
            // 0이라면 길이 없다는 의미 continue
            if (graph[now][i].second == 0) continue;
            // disSum = 임시 노드 + 현재 노드에서 i로가는 비용
            int disSum = nCost + graph[now][i].second;
            // 비용이 더 작다면 최단경로 테이블 값을 갱신.
            if (disSum &lt; timeArr[graph[now][i].first]) {
                // 임시 노드 업데이트
                timeArr[graph[now][i].first] = disSum;
                // 우선순위 큐에 (거리, 노드 인덱스) 푸시
                myPQ.push(make_pair(-disSum, graph[now][i].first));

                // 만약 map의 key 값이 겹친다면 해당 값을 지운다.
                if (myMap.count(graph[now][i].first)) myMap.erase(graph[now][i].first);
                // 도착지를 Key 값으로 map에 저장
                myMap.insert(make_pair(graph[now][i].first, now));
            }
        }
    }
}

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

    cin >> N >> M;

    for (int i = 0; i &lt; M; i++) {
        cin >> U >> V >> t;
        // 양방향 통신 가능
        graph[U].push_back(make_pair(V, t));
        graph[V].push_back(make_pair(U, t)); 
    }

    Dijkstra(1);

    // map의 사이즈를 출력합니다.
    cout &lt;&lt; myMap.size() &lt;&lt; "\n";

    // 복구한 회선을 출력
    for (auto it = myMap.begin(); it != myMap.end(); it++) 
        cout &lt;&lt; it->first &lt;&lt; " " &lt;&lt; it->second &lt;&lt; "\n";

	return 0;
}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1045" height="105" src="https://lycos7560.com/wp-content/uploads/image-1050.png" alt="" class="wp-image-5459" srcset="https://lycos7560.com/wp-content/uploads/image-1050.png 1045w, https://lycos7560.com/wp-content/uploads/image-1050-300x30.png 300w, https://lycos7560.com/wp-content/uploads/image-1050-768x77.png 768w" sizes="(max-width: 1045px) 100vw, 1045px" /></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-2211%eb%b2%88-%eb%84%a4%ed%8a%b8%ec%9b%8c%ed%81%ac-%eb%b3%b5%ea%b5%ac-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5453/">백준 2211번 (네트워크 복구, 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-2211%eb%b2%88-%eb%84%a4%ed%8a%b8%ec%9b%8c%ed%81%ac-%eb%b3%b5%ea%b5%ac-c-dijkstra-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5453/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1181번 (단어 정렬, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/1181-word-alignment-c-baekjoon/4421/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/1181-word-alignment-c-baekjoon/4421/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 10 Jan 2023 16:59:49 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1181]]></category>
		<category><![CDATA[1181번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[multimap]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[단어 정렬]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1181]]></category>
		<category><![CDATA[백준 1181번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4421</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1181번 "단어 정렬" 문제에 대한 글입니다. (This article is about the "word alignment" problem in BAEKJOON 1181.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/1181-word-alignment-c-baekjoon/4421/">백준 1181번 (단어 정렬, 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:68px" 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/1181" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/1181</a></p>



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



<figure id="problem-info" class="wp-block-table has-small-font-size"><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">123599</td><td class="has-text-align-left" data-align="left">51378</td><td class="has-text-align-left" data-align="left">38349</td><td class="has-text-align-left" data-align="left">40.167%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">알파벳 소문자로 이루어진 N개의 단어가 들어오면 아래와 같은 조건에 따라 정렬하는 프로그램을 작성하시오.</p>



<p class="has-medium-font-size">1. 길이가 짧은 것부터</p>



<p class="has-medium-font-size">2. 길이가 같으면 사전 순으로</p>



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



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



<p class="has-medium-font-size">첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) </p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. </p>



<p class="has-medium-font-size">주어지는 문자열의 길이는 50을 넘지 않는다.</p>



<div style="height:59px" 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:44px" 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="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">13
but
i
wont
hesitate
no
more
no
more
it
cannot
wait
im
yours</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="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">i
im
it
no
but
more
wait
wont
yours
cannot
hesitate</pre>



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



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



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



<div style="height:50px" 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/158" target="_blank" rel="noreferrer noopener">문자열</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/97" target="_blank" rel="noreferrer noopener">정렬</a></li>
</ul>



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



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



<p class="has-medium-font-size">입력받은 단어를 아래의 기준으로 정렬하는 문제</p>



<p class="has-medium-font-size">1. 길이가 짧은 것부터</p>



<p class="has-medium-font-size">2. 길이가 같으면 사전 순으로</p>



<p class="has-medium-font-size">map과 multimap의 성질을 이용하여 해결하였습니다.</p>



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

using namespace std;

map&lt;string, int> myMap;

multimap&lt;int, string> mMap;

string str;

int n;

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

	cin >> n;

	// map에 넣어서 중복된 단어를 제거하고
	// 알파벳 순으로 정렬 합니다. (map의 성질)
	// key = string, value = int 
	for (int i = 0; i &lt; n; i++) {
		cin >> str;
		myMap.insert(make_pair(str, str.length()));
	}

	// multimap에 넣어 숫자가 같으면 들어온 순서대로 입력됩니다.
	// key = int (multimap은 중복 허용), value = string
	for (auto it = myMap.begin(); it != myMap.end(); it++) {
		mMap.insert(make_pair(it->second, it->first));
	}

	for (auto it = mMap.begin(); it != mMap.end(); it++) {
		cout &lt;&lt; it->second &lt;&lt; "\n";
	}
	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1034" height="156" src="https://lycos7560.com/wp-content/uploads/image-914.png" alt="" class="wp-image-4423" srcset="https://lycos7560.com/wp-content/uploads/image-914.png 1034w, https://lycos7560.com/wp-content/uploads/image-914-300x45.png 300w, https://lycos7560.com/wp-content/uploads/image-914-768x116.png 768w" sizes="(max-width: 1034px) 100vw, 1034px" /></figure>



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



<p class="has-medium-font-size">정렬 기준을 반대로 해서 틀림</p>



<div style="height:34px" 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/1181-word-alignment-c-baekjoon/4421/">백준 1181번 (단어 정렬, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/1181-word-alignment-c-baekjoon/4421/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 11650번 (좌표 정렬하기, C++, multimap) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/11650-aligning-coordinates-c-multimap-baekjoon/4382/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/11650-aligning-coordinates-c-multimap-baekjoon/4382/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 10 Jan 2023 00:59:20 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[11650]]></category>
		<category><![CDATA[11650번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[multimap]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[맵]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 11650]]></category>
		<category><![CDATA[백준 11650번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[정렬]]></category>
		<category><![CDATA[좌표 정렬하기]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=4382</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 11650번 '좌표 정렬하기' 문제에 대한 글입니다. multimap 을 이용하여 해결하였습니다. (This is an article about the problem of 'aligning coordinates' in BAEKJOON 1160. I solved it using multimap.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/11650-aligning-coordinates-c-multimap-baekjoon/4382/">백준 11650번 (좌표 정렬하기, C++, multimap) [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>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-5698326622209671" data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<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/11650" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/11650</a></p>



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



<figure id="problem-info" class="wp-block-table"><table><thead><tr><th>시간 제한</th><th>메모리 제한</th><th>제출</th><th>정답</th><th>맞힌 사람</th><th>정답 비율</th></tr></thead><tbody><tr><td>1 초</td><td>256 MB</td><td>97665</td><td>46253</td><td>35805</td><td>47.923%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">2차원 평면 위의 점 N개가 주어진다. </p>



<p class="has-medium-font-size">좌표를 x좌표가 증가하는 순으로, x좌표가 같으면 y좌표가 증가하는 순서로 정렬한 다음 출력하는 프로그램을 작성하시오.</p>



<div style="height:56px" 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개의 줄에는 i번점의 위치 x<sub>i</sub>와 y<sub>i</sub>가 주어진다. (-100,000 ≤ x<sub>i</sub>, y<sub>i</sub>&nbsp;≤ 100,000) </p>



<p class="has-medium-font-size">좌표는 항상 정수이고, 위치가 같은 두 점은 없다.</p>



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



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



<p class="has-medium-font-size">첫째 줄부터 N개의 줄에 점을 정렬한&nbsp;결과를 출력한다.</p>



<div style="height:49px" 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="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">5
3 4
1 1
1 -1
2 2
3 3</pre>



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



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



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



<div style="height:39px" 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/kidw0124" target="_blank" rel="noreferrer noopener">kidw0124</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/97" target="_blank" rel="noreferrer noopener">정렬</a></li>
</ul>



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



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



<p class="has-medium-font-size">간편하게 multimap의 성질을 이용하여 정렬을 했다. </p>



<p class="has-medium-font-size">먼저 오름차순으로 Y값을 정렬하여 문제에서 원하는 순서를 맞춰주고</p>



<p class="has-medium-font-size">그다음 X값으로 정렬하여 문제에서 원하는 답을 구했다. </p>



<p class="has-medium-font-size">(value 값은 정렬이 안된다. -> 들어오는 순서 그대로 / key 값이 메인 )</p>



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



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



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

using namespace std;

multimap&lt;int, int> myMap;
multimap&lt;int, int> myMap2;

int arr[3];

// multimap의 특성을 이용한 정렬

int main()
{
	cin >> arr[0];
	for (int i = 0; i &lt; arr[0]; i++) {
		cin >> arr[1] >> arr[2];
		myMap.insert(make_pair(arr[2],arr[1]));
		// Y로 오름차순으로 정렬
	}

	for (auto it = myMap.begin(); it != myMap.end(); it++) {
		myMap2.insert(make_pair(it->second, it->first));
		// Y로 정렬된 리스트를 X로 정렬
		// value 값은 들어온 순서대로
	}

	for (auto it = myMap2.begin(); it != myMap2.end(); it++) {
		cout &lt;&lt; it->first &lt;&lt; " " &lt;&lt; it->second &lt;&lt; "\n";
	}

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1035" height="95" src="https://lycos7560.com/wp-content/uploads/image-907.png" alt="" class="wp-image-4383" srcset="https://lycos7560.com/wp-content/uploads/image-907.png 1035w, https://lycos7560.com/wp-content/uploads/image-907-300x28.png 300w, https://lycos7560.com/wp-content/uploads/image-907-768x70.png 768w" sizes="(max-width: 1035px) 100vw, 1035px" /></figure>



<div style="height:65px" 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/11650-aligning-coordinates-c-multimap-baekjoon/4382/">백준 11650번 (좌표 정렬하기, C++, multimap) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/11650-aligning-coordinates-c-multimap-baekjoon/4382/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
