<?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>algorithm Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/algorithm/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Mon, 13 Oct 2025 06:07:16 +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>algorithm Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>백준 14003번 (가장 긴 증가하는 부분 수열 5, C++)</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 13 Oct 2025 06:06:17 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[14003]]></category>
		<category><![CDATA[14003번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Algorithm Analysis]]></category>
		<category><![CDATA[Algorithm Explanation]]></category>
		<category><![CDATA[Algorithm Practice]]></category>
		<category><![CDATA[Algorithm Study]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[Binary Search]]></category>
		<category><![CDATA[Binary Search LIS]]></category>
		<category><![CDATA[binary_search]]></category>
		<category><![CDATA[BOJ 14003]]></category>
		<category><![CDATA[BOJ Solution]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C++ Algorithm]]></category>
		<category><![CDATA[C++ STL]]></category>
		<category><![CDATA[Coding Interview]]></category>
		<category><![CDATA[Coding Lecture]]></category>
		<category><![CDATA[Coding Test]]></category>
		<category><![CDATA[Competitive Coding]]></category>
		<category><![CDATA[Competitive Programming]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DP Table]]></category>
		<category><![CDATA[Dynamic Programming]]></category>
		<category><![CDATA[Efficiency]]></category>
		<category><![CDATA[Example Walkthrough]]></category>
		<category><![CDATA[Fast IO]]></category>
		<category><![CDATA[Greedy]]></category>
		<category><![CDATA[Greedy Algorithm]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Increasing Sequence]]></category>
		<category><![CDATA[Index Mapping]]></category>
		<category><![CDATA[Index Tracking]]></category>
		<category><![CDATA[Input Output]]></category>
		<category><![CDATA[LIS]]></category>
		<category><![CDATA[LIS Diagram]]></category>
		<category><![CDATA[LIS Example]]></category>
		<category><![CDATA[LIS Flow]]></category>
		<category><![CDATA[LIS Indexing]]></category>
		<category><![CDATA[LIS Pattern]]></category>
		<category><![CDATA[LIS Reconstruction]]></category>
		<category><![CDATA[LIS Reconstruction Algorithm]]></category>
		<category><![CDATA[LIS step by step]]></category>
		<category><![CDATA[LIS Study]]></category>
		<category><![CDATA[LIS Table]]></category>
		<category><![CDATA[LIS Tail]]></category>
		<category><![CDATA[LIS Track]]></category>
		<category><![CDATA[LIS Tutorial]]></category>
		<category><![CDATA[LIS using Binary Search]]></category>
		<category><![CDATA[LIS Visualization]]></category>
		<category><![CDATA[LIS 강의]]></category>
		<category><![CDATA[LIS 구현]]></category>
		<category><![CDATA[LIS 단계별]]></category>
		<category><![CDATA[LIS 문제]]></category>
		<category><![CDATA[LIS 문제풀이]]></category>
		<category><![CDATA[LIS 복원]]></category>
		<category><![CDATA[LIS 복원 알고리즘]]></category>
		<category><![CDATA[LIS 알고리즘]]></category>
		<category><![CDATA[LIS 예제]]></category>
		<category><![CDATA[LIS 추적]]></category>
		<category><![CDATA[LIS 코드]]></category>
		<category><![CDATA[LIS 패턴]]></category>
		<category><![CDATA[Logic Explanation]]></category>
		<category><![CDATA[Longest Increasing Subsequence]]></category>
		<category><![CDATA[Longest Subsequence]]></category>
		<category><![CDATA[lower_bound]]></category>
		<category><![CDATA[Memory Limit]]></category>
		<category><![CDATA[Memory Optimization]]></category>
		<category><![CDATA[O(N log N)]]></category>
		<category><![CDATA[O(N^2)]]></category>
		<category><![CDATA[O(NlogN)]]></category>
		<category><![CDATA[Optimal Algorithm]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Prev Index]]></category>
		<category><![CDATA[Problem Explanation]]></category>
		<category><![CDATA[problem solving]]></category>
		<category><![CDATA[Programming Algorithm]]></category>
		<category><![CDATA[Programming Study]]></category>
		<category><![CDATA[Sequence Analysis]]></category>
		<category><![CDATA[Sequence Optimization]]></category>
		<category><![CDATA[Sequence Problem]]></category>
		<category><![CDATA[Sequence Reconstruction]]></category>
		<category><![CDATA[Sequence Trace]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Subsequence]]></category>
		<category><![CDATA[Tail Array]]></category>
		<category><![CDATA[Theory]]></category>
		<category><![CDATA[Time Complexity]]></category>
		<category><![CDATA[Time Limit]]></category>
		<category><![CDATA[Traceback]]></category>
		<category><![CDATA[upper_bound]]></category>
		<category><![CDATA[vector]]></category>
		<category><![CDATA[가장 긴 증가하는 부분 수열]]></category>
		<category><![CDATA[가장 긴 증가하는 부분 수열 5]]></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[백준 14003]]></category>
		<category><![CDATA[백준 14003번]]></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[인덱스 기반 LIS]]></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=40314</guid>

					<description><![CDATA[<p>가장 긴 증가하는 부분 수열 5 https://www.acmicpc.net/problem/14003 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 3 초 512 MB 45574 15974 11322 34.533% 문제 수열 A가 주어졌을 때, 가장 긴 증가하는&#160;부분&#160;수열을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분&#160;수열은&#160;A = {10,&#160;20, [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/">백준 14003번 (가장 긴 증가하는 부분 수열 5, C++)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-87ca5ab3      "
					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="#가장-긴-증가하는-부분-수열-5" class="uagb-toc-link__trigger">가장 긴 증가하는 부분 수열 5</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#문제" class="uagb-toc-link__trigger">문제</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#입력" class="uagb-toc-link__trigger">입력</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#출력" class="uagb-toc-link__trigger">출력</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#예제-입력-1" class="uagb-toc-link__trigger">예제 입력 1</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#예제-출력-1" class="uagb-toc-link__trigger">예제 출력 1</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#출처" class="uagb-toc-link__trigger">출처</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#비슷한-문제" class="uagb-toc-link__trigger">비슷한 문제</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#알고리즘-분류" class="uagb-toc-link__trigger">알고리즘 분류</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#1차-시도-로직-그대로-구현" class="uagb-toc-link__trigger">1차 시도 &#8211; 로직 그대로 구현</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#2차-시도-이분-탐색-인덱스-추적을-이용한-lis-복원-on-log-n" class="uagb-toc-link__trigger">2차 시도 &#8211; 이분 탐색 + 인덱스 추적을 이용한 LIS 복원 / O(N log N)</a></ul></ol>					</div>
									</div>
				</div>
			


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



<h2 class="wp-block-heading">가장 긴 증가하는 부분 수열 5 <img decoding="async" width="35" height="45" class="wp-image-37909" style="width: 35px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Platinum_5.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Platinum_5.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Platinum_5-234x300.jpg 234w" sizes="(max-width: 35px) 100vw, 35px" /></h2>



<p><a href="https://www.acmicpc.net/problem/14003" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/14003</a></p>



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



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>시간 제한</th><th>메모리 제한</th><th>제출</th><th>정답</th><th>맞힌 사람</th><th>정답 비율</th></tr></thead><tbody><tr><td>3 초</td><td>512 MB</td><td>45574</td><td>15974</td><td>11322</td><td>34.533%</td></tr></tbody></table></figure>



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



<p>수열 A가 주어졌을 때, 가장 긴 증가하는&nbsp;부분&nbsp;수열을 구하는 프로그램을 작성하시오.</p>



<p>예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분&nbsp;수열은&nbsp;A = {<strong>10</strong>,&nbsp;<strong>20</strong>, 10,&nbsp;<strong>30</strong>, 20,&nbsp;<strong>50</strong>} 이고, 길이는 4이다.</p>



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



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



<p>첫째 줄에 수열 A의 크기 N (1 ≤ N ≤ 1,000,000)이 주어진다.</p>



<p>둘째 줄에는 수열 A를 이루고 있는 A<sub>i</sub>가 주어진다. (-1,000,000,000&nbsp;≤ A<sub>i</sub>&nbsp;≤ 1,000,000,000)</p>



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



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



<p>첫째 줄에 수열 A의 가장 긴 증가하는 부분 수열의 길이를 출력한다.</p>



<p>둘째 줄에는 정답이 될 수 있는 가장 긴 증가하는 부분 수열을 출력한다.</p>



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



<div class="wp-block-uagb-container uagb-block-aa78ee06 alignfull uagb-is-root-container"><div class="uagb-container-inner-blocks-wrap">
<div class="wp-block-uagb-container uagb-block-70c24c24">
<h3 class="wp-block-heading">예제 입력 1</h3>



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



<div class="wp-block-uagb-container uagb-block-2c88bb50">
<h3 class="wp-block-heading">예제 출력 1</h3>



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



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



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



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



<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/harinboy">harinboy</a>, <a href="https://www.acmicpc.net/user/jh05013">jh05013</a>, <a href="https://www.acmicpc.net/user/kkw564">kkw564</a>, <a href="https://www.acmicpc.net/user/ldw0318">ldw0318</a>, <a href="https://www.acmicpc.net/user/minho6428">minho6428</a>, <a href="https://www.acmicpc.net/user/sohnryang">sohnryang</a>, <a href="https://www.acmicpc.net/user/surung9898">surung9898</a>, <a href="https://www.acmicpc.net/user/yeo2507">yeo2507</a></li>



<li>빠진 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/Acka">Acka</a></li>
</ul>



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



<h3 class="wp-block-heading">비슷한 문제</h3>



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/11053" target="_blank" rel="noreferrer noopener">11053번. 가장 긴 증가하는 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/11054" target="_blank" rel="noreferrer noopener">11054번. 가장 긴 바이토닉 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/11055" target="_blank" rel="noreferrer noopener">11055번. 가장 큰 증가하는 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/11722" target="_blank" rel="noreferrer noopener">11722번. 가장 긴 감소하는 부분 수열</a></li>



<li><a href="https://www.acmicpc.net/problem/12015" target="_blank" rel="noreferrer noopener">12015번. 가장 긴 증가하는 부분 수열 2</a></li>



<li><a href="https://www.acmicpc.net/problem/12738" target="_blank" rel="noreferrer noopener">12738번. 가장 긴 증가하는 부분 수열 3</a></li>



<li><a href="https://www.acmicpc.net/problem/14002" target="_blank" rel="noreferrer noopener">14002번. 가장 긴 증가하는 부분 수열 4</a></li>
</ul>



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/12" target="_blank" rel="noreferrer noopener">이분 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/235" target="_blank" rel="noreferrer noopener">역추적</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/43" 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--60);margin-bottom:var(--wp--preset--spacing--60)"/>



<h3 class="wp-block-heading">1차 시도 &#8211; 로직 그대로 구현</h3>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1043" height="115" src="https://lycos7560.com/wp-content/uploads/2025/10/image-4.png" alt="" class="wp-image-40317" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-4.png 1043w, https://lycos7560.com/wp-content/uploads/2025/10/image-4-300x33.png 300w, https://lycos7560.com/wp-content/uploads/2025/10/image-4-768x85.png 768w" sizes="(max-width: 1043px) 100vw, 1043px" /></figure>



<p>한 번의 입력(<code>num</code>)에 의해 생성된 새로운 시퀀스들을 임시로 저장</p>



<p>어떤 수열에도 붙을 수 없으면 독립된 시퀀스 시작</p>



<p>나중에 불필요한 시퀀스(같은 길이인데 꼬리가 큰 것)는 제거</p>



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

using namespace std;

int n; // 수열의 개수
vector&lt;vector&lt;int>> Sequences;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    if (n &lt;= 0) return 0;

    int num;
    cin >> num;

    // 첫 번째 수로 초기 시퀀스 하나 생성
    vector&lt;int> sequence;
    sequence.push_back(num);
    Sequences.push_back(sequence);

    for (int i = 1; i &lt; n; i++)
    {
        cin >> num;
        int length = Sequences.size();

        bool canExtend = false;
        vector&lt;vector&lt;int>> newSequences;

        // 기존 시퀀스들을 모두 검사
        for (int j = 0; j &lt; length; j++)
        {
            int last = Sequences[j].back();

            // 확장 가능한 경우 : 새로운 시퀀스 생성
            if (last &lt; num)
            {
                canExtend = true;
                vector&lt;int> extendedSeq = Sequences[j];
                extendedSeq.push_back(num);
                newSequences.push_back(extendedSeq);
            }
        }

        // 어떤 시퀀스에도 붙지 못하면 새로운 시퀀스 시작
        if (!canExtend)
        {
            vector&lt;int> newSeq;
            newSeq.push_back(num);
            newSequences.push_back(newSeq);
        }

        // 새로 생긴 시퀀스들을 기존에 합침
        for (auto&amp; seq : newSequences)
            Sequences.push_back(seq);

        // 최적 시퀀스 길이 및 꼬리값 계산
        int maxSeqSize = 0;
        int bestIndex = 0;
        int bestTail = 1000000001;

        for (int j = 0; j &lt; (int)Sequences.size(); j++)
        {
            int sz = Sequences[j].size();
            int tail = Sequences[j].back();
            if (sz > maxSeqSize || (sz == maxSeqSize &amp;&amp; tail &lt; bestTail))
            {
                maxSeqSize = sz;
                bestTail = tail;
                bestIndex = j;
            }
        }

        // 가지치기: 같은 길이인데 꼬리값이 큰 시퀀스 제거
        for (int j = 0; j &lt; (int)Sequences.size();)
        {
            int sz = Sequences[j].size();
            int tail = Sequences[j].back();

            if (sz == maxSeqSize &amp;&amp; tail > bestTail)
            {
                Sequences.erase(Sequences.begin() + j);
            }
            else
            {
                j++;
            }
        }
    }

	// 결과 중 가장 긴 시퀀스 찾기
    int maxSize = 0;
    int bestIdx = 0;
    for (int i = 0; i &lt; (int)Sequences.size(); i++)
    {
        if (Sequences[i].size() > maxSize)
        {
            maxSize = Sequences[i].size();
            bestIdx = i;
        }
    }

    cout &lt;&lt; maxSize &lt;&lt; "\n";
    for (int x : Sequences[bestIdx])
        cout &lt;&lt; x &lt;&lt; " ";

    return 0;
}
</pre>



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



<p>브루트포스 방식으로 모든 가능한 증가 수열을 시도하는 방법은 시간 초과 및 메모리 초과로 인하여 통과할 수 없음.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="604" height="509" src="https://lycos7560.com/wp-content/uploads/2025/10/image-3.png" alt="" class="wp-image-40318" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-3.png 604w, https://lycos7560.com/wp-content/uploads/2025/10/image-3-300x253.png 300w" sizes="(max-width: 604px) 100vw, 604px" /></figure>



<p><strong>매 반복마다</strong> <code>Sequences</code>의 크기가 <strong>기하급수적으로 늘어나는 구조</strong></p>



<p>n개의 원소가 들어오면 2ⁿ에 비례하는 시퀀스로 통과하기 힘들다. (O(2ⁿ))</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>단계</th><th>가능한 Sequences 수</th></tr></thead><tbody><tr><td>1</td><td>[ [1] ]</td></tr><tr><td>2</td><td>[ [1], [2], [1,2] ]</td></tr><tr><td>3</td><td>[ [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3] ]</td></tr><tr><td>4</td><td>거의 모든 가능한 증가 부분 수열이 등장함 (약 15개)</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading">2차 시도 &#8211; <strong>이분 탐색 + 인덱스 추적</strong>을 이용한 LIS 복원 / O(N log N)</h3>



<figure class="wp-block-image size-full"><img decoding="async" width="1042" height="39" src="https://lycos7560.com/wp-content/uploads/2025/10/image-7.png" alt="" class="wp-image-40322" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-7.png 1042w, https://lycos7560.com/wp-content/uploads/2025/10/image-7-300x11.png 300w, https://lycos7560.com/wp-content/uploads/2025/10/image-7-768x29.png 768w" sizes="(max-width: 1042px) 100vw, 1042px" /></figure>



<p>최장 증가 수열 (LIS, Longest Increasing Subsequence)</p>



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

using namespace std;

// (LIS, Longest Increasing Subsequence)

int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    int N;
    std::cin >> N;

    vector&lt;int> input(N);
    for (int i = 0; i &lt; N; i++)
        std::cin >> input[i];

    vector&lt;int> tail;  // LIS를 구성하는 인덱스들
    vector&lt;int> prev_idx(N, -1);  //각 요소가 LIS에 포함될 때, 그 직전 요소의 인덱스를 저장


    for (int i = 0; i &lt; N; i++)
    {
        // 이분 탐색으로 input[i]가 tail 배열에서 들어가야 할 위치 찾기
        int lo = 0;
        int hi = (int)tail.size() - 1;
        int pos = (int)tail.size(); // 기본값은 맨 뒤

        while (lo &lt;= hi)
        {
            int mid = (lo + hi) / 2;
            // input[i]보다 크거나 같은 첫 번째 tail 원소 위치(pos)를 찾
            if (input[tail[mid]] &lt; input[i])
            {
                lo = mid + 1;
            }
            else
            {
                pos = mid;
                hi = mid - 1;
            }
        }

        // 이전 인덱스 설정
        if (pos > 0)
        {
            prev_idx[i] = tail[pos - 1];
        }
        else
        {
            prev_idx[i] = -1;  // 첫 번째 요소
        }

        // tail 업데이트
        if (pos == (int)tail.size())
        {
            tail.push_back(i);
        }
        else
        {
            tail[pos] = i;
        }
    }

    // 결과: LIS 길이
    int lis_len = (int)tail.size();
    std::cout &lt;&lt; lis_len &lt;&lt; "\n";

    // 실제 LIS 수열 재구성
    vector&lt;int> lis;
    for (int idx = tail.back(); idx != -1; idx = prev_idx[idx])
    {
        lis.push_back(input[idx]);
    }
    reverse(lis.begin(), lis.end());

    for (int v : lis)
        std::cout &lt;&lt; v &lt;&lt; " ";
    std::cout &lt;&lt; "\n";

    return 0;
}</pre>



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



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



<p><code>input[i]</code>가 들어가야 할 위치(<code>pos</code>)를 찾음</p>



<p>즉, <code>tail</code> 배열 내에서 <strong>input[i]보다 작지만 가장 큰 값 다음 위치</strong>를 찾는다.</p>



<figure class="wp-block-image size-full"><img decoding="async" width="513" height="466" src="https://lycos7560.com/wp-content/uploads/2025/10/image-6.png" alt="" class="wp-image-40320" srcset="https://lycos7560.com/wp-content/uploads/2025/10/image-6.png 513w, https://lycos7560.com/wp-content/uploads/2025/10/image-6-300x273.png 300w" sizes="(max-width: 513px) 100vw, 513px" /></figure>



<p><code>prev_idx[i]</code>는 <code>input[i]</code> 바로 앞에 올 LIS 원소의 인덱스입니다.</p>



<p><code>pos > 0</code>이면 → 현재 원소가 &#8220;길이 pos+1&#8243;짜리 LIS의 마지막이 되므로 &#8220;그 바로 이전 원소&#8221;는 <code>tail[pos - 1]</code></p>



<p><code>pos == 0</code>이면 → 수열의 첫 번째 원소이므로 이전이 없음</p>



<p><code>pos == tail.size()</code> → <code>input[i]</code>가 지금 까지의 모든 수보다 크므로 LIS 길이 1 증가</p>



<p>그렇지 않으면 → 기존 LIS 후보 중 &#8220;끝값이 더 큰 것&#8221;을 <code>input[i]</code>로 <strong>치환</strong> (더 작은 끝값 유지)</p>



<h4 class="wp-block-heading">예시 1</h4>



<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="">input = [5, 2, 8, 6, 3, 6, 9, 7]</pre>



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



<figure class="wp-block-table"><table><thead><tr><th class="has-text-align-left" data-align="left">단계</th><th class="has-text-align-left" data-align="left">i</th><th class="has-text-align-left" data-align="left">input[i]</th><th class="has-text-align-left" data-align="left">tail (인덱스)</th><th class="has-text-align-left" data-align="left">tail (값으로 표현)</th><th class="has-text-align-left" data-align="left">prev_idx</th><th class="has-text-align-left" data-align="left">설명</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">0</td><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">[0]</td><td class="has-text-align-left" data-align="left">[5]</td><td class="has-text-align-left" data-align="left">[-1, ?, ?, ?, ?, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">첫 번째 원소 → 새로운 LIS 시작</td></tr><tr><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">[1]</td><td class="has-text-align-left" data-align="left">[2]</td><td class="has-text-align-left" data-align="left">[-1, -1, ?, ?, ?, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">2 &lt; 5 → 기존 tail[0] 교체 (더 작은 끝값 유지)</td></tr><tr><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">8</td><td class="has-text-align-left" data-align="left">[1, 2]</td><td class="has-text-align-left" data-align="left">[2, 8]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, ?, ?, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">8 &gt; 2 → 길이 2짜리 LIS 형성</td></tr><tr><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">[1, 3]</td><td class="has-text-align-left" data-align="left">[2, 6]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, ?, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">6은 2보다 크지만 8보다 작음 → 8을 6으로 교체</td></tr><tr><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">[1, 4]</td><td class="has-text-align-left" data-align="left">[2, 3]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, 1, ?, ?, ?]</td><td class="has-text-align-left" data-align="left">3은 2보다 크고 6보다 작음 → 6을 3으로 교체</td></tr><tr><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">[1, 4, 5]</td><td class="has-text-align-left" data-align="left">[2, 3, 6]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, 1, 4, ?, ?]</td><td class="has-text-align-left" data-align="left">6은 3보다 크므로 길이 3짜리 LIS 생성</td></tr><tr><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left">9</td><td class="has-text-align-left" data-align="left">[1, 4, 5, 6]</td><td class="has-text-align-left" data-align="left">[2, 3, 6, 9]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, 1, 4, 5, ?]</td><td class="has-text-align-left" data-align="left">9 &gt; 6 → 길이 4짜리 LIS 생성</td></tr><tr><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left">[1, 4, 5, 7]</td><td class="has-text-align-left" data-align="left">[2, 3, 6, 7]</td><td class="has-text-align-left" data-align="left">[-1, -1, 1, 1, 1, 4, 5, 5]</td><td class="has-text-align-left" data-align="left">7은 6보다 크지만 9보다 작음 → 9를 7로 교체</td></tr></tbody></table></figure>



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



<h4 class="wp-block-heading">예시 2</h4>



<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="">이분 탐색을 이용한 LIS 구성 로직

input = [3, 5, 2, 7, 4, 1, 8]

--------------------------------

i=0 (값: 3)
tail: [] (빈 배열)
이분탐색: tail.size() = 0 → while문 스킵
pos = 0 (기본값)

prev_idx[0] = -1 (pos=0이므로)
tail 업데이트: pos == tail.size() → push_back(0)
결과: tail = [0] (값: [3])

--------------------------------

i=1 (값: 5)
tail: [0] (값: [3])
이분탐색:
  lo=0, hi=0, mid=0
  input[tail[0]] = 3 &lt; 5 → lo = mid+1 = 1
  lo=1 > hi=0 → 종료
pos = tail.size() = 1

prev_idx[1] = tail[0] = 0 (5 앞에 3)
tail 업데이트: push_back(1)
결과: tail = [0,1] (값: [3,5])

--------------------------------

i=2 (값: 2)
tail: [0,1] (값: [3,5])
이분탐색:
  lo=0, hi=1, mid=0
  input[tail[0]] = 3 >= 2 → pos=0, hi=-1
  lo=0 > hi=-1 → 종료
pos = 0

prev_idx[2] = -1 (pos=0이므로)
tail 업데이트: tail[0] = 2
결과: tail = [2,1] (값: [2,5])

--------------------------------

i=3 (값: 7)
tail: [2,1] (값: [2,5])
이분탐색:
  lo=0, hi=1, mid=0: input[tail[0]]=2 &lt; 7 → lo=1
  lo=1, hi=1, mid=1: input[tail[1]]=5 &lt; 7 → lo=2
  lo=2 > hi=1 → 종료
pos = tail.size() = 2

prev_idx[3] = tail[1] = 1 (7 앞에 5)
tail 업데이트: push_back(3)
결과: tail = [2,1,3] (값: [2,5,7])

--------------------------------

i=4 (값: 4)
tail: [2,1,3] (값: [2,5,7])
이분탐색:
  lo=0, hi=2, mid=1: input[tail[1]]=5 >= 4 → pos=1, hi=0
  lo=0, hi=0, mid=0: input[tail[0]]=2 &lt; 4 → lo=1
  lo=1 > hi=0 → 종료
pos = 1

prev_idx[4] = tail[0] = 2 (4 앞에 2)
tail 업데이트: tail[1] = 4
결과: tail = [2,4,3] (값: [2,4,7])

--------------------------------

i=5 (값: 1)
tail: [2,4,3] (값: [2,4,7])
이분탐색:
  lo=0, hi=2, mid=1: input[tail[1]]=4 >= 1 → pos=1, hi=0
  lo=0, hi=0, mid=0: input[tail[0]]=2 >= 1 → pos=0, hi=-1
  lo=0 > hi=-1 → 종료
pos = 0

prev_idx[5] = -1
tail 업데이트: tail[0] = 5
결과: tail = [5,4,3] (값: [1,4,7])

--------------------------------

i=6 (값: 8)

tail: [5,4,3] (값: [1,4,7])
이분탐색:
  lo=0, hi=2, mid=1: input[tail[1]]=4 &lt; 8 → lo=2
  lo=2, hi=2, mid=2: input[tail[2]]=7 &lt; 8 → lo=3
  lo=3 > hi=2 → 종료
pos = tail.size() = 3

prev_idx[6] = tail[2] = 3 (8 앞에 7)
tail 업데이트: push_back(6)
결과: tail = [5,4,3,6] (값: [1,4,7,8])

</pre>



<p></p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/">백준 14003번 (가장 긴 증가하는 부분 수열 5, C++)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-14003%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b8%b4-%ec%a6%9d%ea%b0%80%ed%95%98%eb%8a%94-%eb%b6%80%eb%b6%84-%ec%88%98%ec%97%b4-5-c/40314/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>백준 9663번 (N-Queen, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 19 May 2023 04:37:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[<algorithm>]]></category>
		<category><![CDATA[9663]]></category>
		<category><![CDATA[9663번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[N-Queen]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 9663]]></category>
		<category><![CDATA[백준 9663번]]></category>
		<category><![CDATA[백트레킹]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34814</guid>

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



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-b04bb7c8      "
					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="#n-queen" class="uagb-toc-link__trigger">N-Queen</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">N-Queen</h1>



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



<div style="height:62px" 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">메모리 제한</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">10 초</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">91882</td><td class="has-text-align-left" data-align="left">44089</td><td class="has-text-align-left" data-align="left">28607</td><td class="has-text-align-left" data-align="left">46.649%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">N-Queen 문제는&nbsp;크기가 N × N인 체스판 위에 퀸 N개를&nbsp;서로 공격할 수 없게 놓는&nbsp;문제이다.</p>



<p class="has-medium-font-size">N이 주어졌을 때, 퀸을 놓는 방법의 수를 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 N이 주어진다. (1 ≤ N &lt; 15)</p>



<div style="height:62px" 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:62px" 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 17</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</pre>



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



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



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/5">백트래킹</a></li>
</ul>



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



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



<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/05/KakaoTalk_20230519_111808847.jpg" alt="" class="wp-image-34817" width="1139" height="1440" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847.jpg 1519w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-237x300.jpg 237w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-768x971.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230519_111808847-1215x1536.jpg 1215w" sizes="(max-width: 1139px) 100vw, 1139px" /></figure>



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



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;cmath>
using namespace std;
constexpr int Max = 15; // 체스판의 최대 
int _N, _Res, _Queen[Max];

bool CheckQueens(int _row)
{
	for (int i = 0; i &lt; _row; i++) {
		// 절대값으로 대각선으로 전부 확인
		if (_Queen[i] == _Queen[_row] || ( abs(_Queen[i] - _Queen[_row]) == abs(i - _row))) {
			return false;
		}
	}
	return true;
}

void BackTracing(int _row) {
	// N번째까지 왔다면 경우의 수 추가
	if (_row == _N) {
		_Res++;
		return; 
	}

	for (int _col = 0; _col &lt; _N; _col++) {
		_Queen[_row] = _col;
		//해당 행이 가능한지 확인한다.
		if (CheckQueens(_row)) 
			BackTracing(_row + 1);
	}
}

int main()
{
	cin >> _N; // 체스판의 크기 입력
	BackTracing(0); // 백트레킹으로 체크
	cout &lt;&lt; _Res;
	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/05/image-88.png" alt="" class="wp-image-34820" width="904" height="73" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-88.png 1205w, https://lycos7560.com/wp-content/uploads/2023/05/image-88-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-88-768x62.png 768w" sizes="(max-width: 904px) 100vw, 904px" /></figure>



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



<h1 class="wp-block-heading">더 효율적인 코드</h1>



<p class="has-medium-font-size">DFS 탐색을 이용한 백트레킹</p>



<p class="has-medium-font-size">dy dx를 대각선으로 표현하여 검사</p>



<figure class="wp-block-image size-full"><img decoding="async" width="400" height="396" src="https://lycos7560.com/wp-content/uploads/2023/05/image-90.png" alt="" class="wp-image-34825" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-90.png 400w, https://lycos7560.com/wp-content/uploads/2023/05/image-90-300x297.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-90-150x150.png 150w" sizes="(max-width: 400px) 100vw, 400px" /></figure>



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



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
constexpr int Max = 15;
int _N, _Res;
// 체스판 
bool MapArr[Max];
//체스판의 대각선을 표현하기위한 변수
//대각선은 2N - 1개 필요
bool dx[29], dy[29];

void BackTracking(int level)
{
	if (level == _N) {
		_Res++;
		return;
	}
	for (int i = 0; i &lt; _N; i++) {
		//현재 열, 왼쪽 대각선 및 오른쪽 대각선에 이미 배치된 여왕이 없는지 확인
		// dx, dy는 체스판의 특정한 위치를 나타내는 변수가 아니다.
		// dx, dy를 이용하여 대각선을 추적하는 것
		// 배열의 각 인덱스는 dx대각선을 나타내며 해당 인덱스의 값은 대각선이 여왕에 의해 점유되는지 여부를 나타냅니다. 
		if (!MapArr[i] &amp;&amp; !dx[i - level + _N] &amp;&amp; !dy[i + level]) {
			
			MapArr[i] = dx[i - level + _N] = dy[i + level] = true;
			BackTracking(level + 1);
			MapArr[i] = dx[i - level + _N] = dy[i + level] = false;
		}
	}
}

int main() {
	_Res = 0;
	cin >> _N;
	BackTracking(0);
	cout &lt;&lt; _Res;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1038" height="99" src="https://lycos7560.com/wp-content/uploads/2023/05/image-89.png" alt="" class="wp-image-34821" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-89.png 1038w, https://lycos7560.com/wp-content/uploads/2023/05/image-89-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-89-768x73.png 768w" sizes="(max-width: 1038px) 100vw, 1038px" /></figure>



<p></p>



<p></p>



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-9663%eb%b2%88-n-queen-c-baekjoon/34814/">백준 9663번 (N-Queen, 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-9663%eb%b2%88-n-queen-c-baekjoon/34814/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 17070번 (파이프 옮기기 1, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 03 May 2023 12:28:58 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[<algorithm>]]></category>
		<category><![CDATA[17070]]></category>
		<category><![CDATA[17070번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 17070]]></category>
		<category><![CDATA[백준 17070번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[파이프 옮기기 1]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34406</guid>

					<description><![CDATA[<p>백준 17070번 '파이프 옮기기 1' 문제에 대한 글입니다. BFS 탐색 또는 DP 알고리즘을 이용하여 해결이 가능합니다. (This article is about Baekjoon Number 17070 'Pipe Transfer 1' problem. It can be solved using BFS search or DP algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/">백준 17070번 (파이프 옮기기 1, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-0725da64      "
					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="#파이프-옮기기-1" class="uagb-toc-link__trigger">파이프 옮기기 1</a><li class="uagb-toc__list"><a href="#통과된-코드-bfs" class="uagb-toc-link__trigger">통과된 코드 (BFS)</a><li class="uagb-toc__list"><a href="#통과된-코드-dp" class="uagb-toc-link__trigger">통과된 코드 (DP)</a></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">파이프 옮기기 1</h1>



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



<div style="height:40px" 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">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초 (추가 시간 없음)</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">31068</td><td class="has-text-align-left" data-align="left">14557</td><td class="has-text-align-left" data-align="left">9962</td><td class="has-text-align-left" data-align="left">45.783%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size">유현이가 새 집으로 이사했다. 새 집의 크기는 N×N의 격자판으로 나타낼 수 있고, </p>



<p class="has-medium-font-size">1×1크기의 정사각형 칸으로 나누어져 있다. </p>



<p class="has-medium-font-size">각각의 칸은 (r, c)로 나타낼 수 있다. 여기서 r은 행의 번호, c는 열의 번호이고, </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>



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



<figure class="wp-block-image size-full"><img decoding="async" width="292" height="156" src="https://lycos7560.com/wp-content/uploads/2023/05/image.png" alt="" class="wp-image-34408"/></figure>



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



<p class="has-medium-font-size">파이프는 회전시킬 수 있으며, 아래와 같이 3가지 방향이 가능하다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="948" height="294" src="https://lycos7560.com/wp-content/uploads/2023/05/image-1.png" alt="" class="wp-image-34409" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-1.png 948w, https://lycos7560.com/wp-content/uploads/2023/05/image-1-300x93.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-1-768x238.png 768w" sizes="(max-width: 948px) 100vw, 948px" /></figure>



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



<p class="has-medium-font-size">파이프는 매우 무겁기 때문에, 유현이는 파이프를 밀어서 이동시키려고 한다. </p>



<p class="has-medium-font-size">벽에는 새로운 벽지를 발랐기 때문에, 파이프가 벽을 긁으면 안 된다. </p>



<p class="has-medium-font-size">즉, 파이프는 항상 빈 칸만 차지해야 한다.</p>



<p class="has-medium-font-size">파이프를 밀 수 있는 방향은 총 3가지가 있으며,&nbsp;→,&nbsp;<img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2198.png" alt="↘" class="wp-smiley" style="height: 1em; max-height: 1em;" />,&nbsp;↓ 방향이다. </p>



<p class="has-medium-font-size">파이프는 밀면서 회전시킬 수 있다. 회전은 45도만 회전시킬 수 있으며, </p>



<p class="has-medium-font-size">미는 방향은 오른쪽, 아래, 또는 오른쪽 아래 대각선 방향이어야 한다.</p>



<p class="has-medium-font-size">파이프가 가로로 놓여진 경우에&nbsp;가능한 이동 방법은 총 2가지, </p>



<p class="has-medium-font-size">세로로 놓여진 경우에는 2가지, 대각선 방향으로 놓여진 경우에는 3가지가 있다.</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>



<figure class="wp-block-image size-full"><img decoding="async" width="1195" height="422" src="https://lycos7560.com/wp-content/uploads/2023/05/image-2.png" alt="" class="wp-image-34410" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-2.png 1195w, https://lycos7560.com/wp-content/uploads/2023/05/image-2-300x106.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-2-768x271.png 768w" sizes="(max-width: 1195px) 100vw, 1195px" /></figure>



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



<p class="has-medium-font-size">가로</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1179" height="416" src="https://lycos7560.com/wp-content/uploads/2023/05/image-3.png" alt="" class="wp-image-34411" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-3.png 1179w, https://lycos7560.com/wp-content/uploads/2023/05/image-3-300x106.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-3-768x271.png 768w" sizes="(max-width: 1179px) 100vw, 1179px" /></figure>



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



<p class="has-medium-font-size">세로</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1797" height="421" src="https://lycos7560.com/wp-content/uploads/2023/05/image-4.png" alt="" class="wp-image-34412" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-4.png 1797w, https://lycos7560.com/wp-content/uploads/2023/05/image-4-300x70.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-4-768x180.png 768w, https://lycos7560.com/wp-content/uploads/2023/05/image-4-1536x360.png 1536w" sizes="(max-width: 1797px) 100vw, 1797px" /></figure>



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



<p class="has-medium-font-size">대각선</p>



<p class="has-medium-font-size">가장 처음에 파이프는&nbsp;(1, 1)와 (1, 2)를 차지하고 있고, 방향은 가로이다. </p>



<p class="has-medium-font-size">파이프의 한쪽 끝을 (N, N)로 이동시키는 방법의 개수를 구해보자.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 집의 크기 N(3 ≤ N ≤ 16)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에는 집의 상태가 주어진다. 빈 칸은 0, 벽은 1로 주어진다. </p>



<p class="has-medium-font-size">(1, 1)과 (1, 2)는 항상 빈 칸이다.</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, N)으로 이동시키는 방법의 수를 출력한다. </p>



<p class="has-medium-font-size">이동시킬 수 없는 경우에는 0을 출력한다. </p>



<p class="has-medium-font-size">방법의 수는 항상 1,000,000보다 작거나 같다.</p>



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



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



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



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



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



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



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



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



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



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



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



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



<div style="height:100px" 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="">5
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0</pre>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>



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



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



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



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



<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/05/KakaoTalk_20230503_203812154.jpg" alt="" class="wp-image-34417" width="1200" height="473" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154-300x118.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154-768x302.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_203812154-1536x605.jpg 1536w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



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



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;queue>
#include &lt;tuple>
using namespace std;
// 우측, 하단, 대각선
int _DxDy[3][2] = { { 0, 1},{ 1, 0},{ 1, 1} };
bool _MapArr[17][17];
// x좌표, y좌표, 파이프의 상태
// 0 = 가로 , 1 = 세로 , 2 = 대각선
queue&lt;tuple&lt;int, int, int>> _BFSQ;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

    int _N, _Res = 0;
	cin >> _N;
	for (int i = 1; i &lt;= _N; i++) {
		for (int j = 1; j &lt;= _N; j++) {
			cin >> _MapArr[i][j];
		}
	}

	tuple&lt;int, int, int> _Temp = make_tuple(1, 2, 0);
	_BFSQ.push(_Temp);
	while (!_BFSQ.empty()) {
		_Temp = _BFSQ.front();
		_BFSQ.pop();
		for (int i = 0; i &lt; 3; i++) {
			if (get&lt;2>(_Temp) == 0 &amp;&amp; i == 1 || get&lt;2>(_Temp) == 1 &amp;&amp; i == 0) continue;
			int _dx = get&lt;0>(_Temp) + _DxDy[i][0];
			int _dy = get&lt;1>(_Temp) + _DxDy[i][1];
			if (_dx > _N || _dy > _N || _dx &lt;= 0 || _dy &lt;= 0 || _MapArr[_dx][_dy]) continue;
			if (i == 2) { // 대각선 방향 우측, 하단부 확인
				if (_MapArr[get&lt;0>(_Temp) + _DxDy[0][0]][get&lt;1>(_Temp) + _DxDy[0][1]] ||
					_MapArr[get&lt;0>(_Temp) + _DxDy[1][0]][get&lt;1>(_Temp) + _DxDy[1][1]]) continue;
			}
			if (_dx == _N &amp;&amp; _dy == _N) {
				_Res++;
				continue;
			}
			tuple&lt;int, int, int> _Temp2 = make_tuple(_dx, _dy, i);
			_BFSQ.push(_Temp2);
		}
	}
	cout &lt;&lt; _Res;

    return 0;
}
</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/image-5.png" alt="" class="wp-image-34414" width="1160" height="94" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-5.png 965w, https://lycos7560.com/wp-content/uploads/2023/05/image-5-300x24.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-5-768x62.png 768w" sizes="(max-width: 1160px) 100vw, 1160px" /></figure>



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



<p class="has-medium-font-size">BFS 탐색을 이용한 결과 생각보다 시간이 많이 걸리고 메모리도 많이 사용한다.</p>



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



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



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



<p class="has-medium-font-size">DP 알고리즘을 이용한 해결법이 더 효율적</p>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963.jpg" alt="" class="wp-image-34424" width="1200" height="1410" srcset="https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963-255x300.jpg 255w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963-768x902.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/05/KakaoTalk_20230503_212725963-1307x1536.jpg 1307w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



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



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
using namespace std;
// 0 가로, 1 세로, 2 대각선
int _DpArr[3][17][17];
bool _MapArr[17][17];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int _N;
    cin >> _N;  
    for (int i = 1; i &lt;= _N; ++i)
        for (int j = 1; j &lt;= _N; ++j)
            cin >> _MapArr[i][j];
    // 파이프의 상태, (1, 2) 시작
    _DpArr[0][1][2] = 1;
    // Tabulation: Bottom Up(표, 상향식) DP
    for (int i = 1; i &lt;= _N; ++i) {
        for (int j = 1; j &lt;= _N; ++j) {
            if (_MapArr[i][j]) continue; // 움직일 위치가 벽이 라면 넘어간다.
            // 가로 상태로 이동이 가능한 경우 => 전 상태가 우측 or 대각선인 경우
            _DpArr[0][i][j] += _DpArr[0][i][j - 1] + _DpArr[2][i][j - 1];
            // 세로 상태로 이동이 가능한 경우 => 전 상태가 하단 or 대각선인 경우
            _DpArr[1][i][j] += _DpArr[1][i - 1][j] + _DpArr[2][i - 1][j];
            // 대각선 상태로 이동이 가능한 조건 체크 => 우측 + 하단에 벽이 있는지 확인이 필요
            if (_MapArr[i][j - 1] || _MapArr[i - 1][j]) continue;
            // 대각선 상태로 이동이 가능한 경우 => 모든 경우 가능
            _DpArr[2][i][j] += _DpArr[0][i - 1][j - 1] + _DpArr[1][i - 1][j - 1] + _DpArr[2][i - 1][j - 1];
        }
    }
    // DP연산을 마친후에 결과 종합
    // _N,_N 에 도착한 상태가 가로, 세로, 대각선 상태를 전부 더해준다.
    cout &lt;&lt; _DpArr[0][_N][_N] + _DpArr[1][_N][_N] + _DpArr[2][_N][_N];
    return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/05/image-6.png" alt="" class="wp-image-34421" width="1165" height="114" srcset="https://lycos7560.com/wp-content/uploads/2023/05/image-6.png 829w, https://lycos7560.com/wp-content/uploads/2023/05/image-6-300x29.png 300w, https://lycos7560.com/wp-content/uploads/2023/05/image-6-768x75.png 768w" sizes="(max-width: 1165px) 100vw, 1165px" /></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-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/">백준 17070번 (파이프 옮기기 1, 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-17070%eb%b2%88-%ed%8c%8c%ec%9d%b4%ed%94%84-%ec%98%ae%ea%b8%b0%ea%b8%b0-1-c-baekjoon/34406/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 60057 문자열 압축 [2020 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-60057-%eb%ac%b8%ec%9e%90%ec%97%b4-%ec%95%95%ec%b6%95-2020-kakao-blind-recruitment/34347/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-60057-%eb%ac%b8%ec%9e%90%ec%97%b4-%ec%95%95%ec%b6%95-2020-kakao-blind-recruitment/34347/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 20 Apr 2023 02:36:22 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[2020 KAKAO BLIND RECRUITMENT]]]></category>
		<category><![CDATA[<string>]]></category>
		<category><![CDATA[2020 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[60057]]></category>
		<category><![CDATA[60057번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Programmers 60057]]></category>
		<category><![CDATA[Programmers 60057 문자열 압축]]></category>
		<category><![CDATA[Programmers 60057번]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[문자열 압축]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34347</guid>

					<description><![CDATA[<p>Programmers 60057번 '문자열 압축' 문제에 대한 글입니다. (This article is about the 'string compression' problem in Programmers 60057. [2020 KAKAO BLIND RECRUITMENT])</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-60057-%eb%ac%b8%ec%9e%90%ec%97%b4-%ec%95%95%ec%b6%95-2020-kakao-blind-recruitment/34347/">Programmers 60057 문자열 압축 [2020 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: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-54756f60      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#문자열-압축" class="uagb-toc-link__trigger">문자열 압축</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ol>					</div>
									</div>
				</div>
			


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



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



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



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



<p class="has-medium-font-size">데이터 처리 전문가가 되고 싶은&nbsp;<strong>&#8220;어피치&#8221;</strong>는 문자열을 압축하는 방법에 대해 공부를 하고 있습니다. </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;aabbaccc&#8221;의 경우 &#8220;2a2ba3c&#8221;(문자가 반복되지 않아 한번만 나타난 경우 1은 생략함)와 같이 표현할 수 있는데, </p>



<p class="has-medium-font-size">이러한 방식은 반복되는 문자가 적은 경우 압축률이 낮다는 단점이 있습니다. </p>



<p class="has-medium-font-size">예를 들면, &#8220;abcabcdede&#8221;와 같은 문자열은 전혀 압축되지 않습니다. </p>



<p class="has-medium-font-size">&#8220;어피치&#8221;는 이러한 단점을 해결하기 위해 문자열을 1개 이상의 단위로 잘라서 압축하여 </p>



<p class="has-medium-font-size">더 짧은 문자열로 표현할 수 있는지 방법을 찾아보려고 합니다.</p>



<p class="has-medium-font-size">예를 들어, &#8220;ababcdcdababcdcd&#8221;의 경우 문자를 1개 단위로 자르면 전혀 압축되지 않지만,</p>



<p class="has-medium-font-size"> 2개 단위로 잘라서 압축한다면 &#8220;2ab2cd2ab2cd&#8221;로 표현할 수 있습니다. </p>



<p class="has-medium-font-size">다른 방법으로 8개 단위로 잘라서 압축한다면 &#8220;2ababcdcd&#8221;로 표현할 수 있으며, </p>



<p class="has-medium-font-size">이때가 가장 짧게 압축하여 표현할 수 있는 방법입니다.</p>



<p class="has-medium-font-size">다른 예로, &#8220;abcabcdede&#8221;와 같은 경우, 문자를 2개 단위로 잘라서 압축하면 &#8220;abcabc2de&#8221;가 되지만, </p>



<p class="has-medium-font-size">3개 단위로 자른다면 &#8220;2abcdede&#8221;가 되어 3개 단위가 가장 짧은 압축 방법이 됩니다. </p>



<p class="has-medium-font-size">이때 3개 단위로 자르고 마지막에 남는 문자열은 그대로 붙여주면 됩니다.</p>



<p class="has-medium-font-size">압축할 문자열 s가 매개변수로 주어질 때, </p>



<p class="has-medium-font-size">위에 설명한 방법으로 1개 이상 단위로 문자열을 잘라 압축하여 </p>



<p class="has-medium-font-size">표현한 문자열 중 가장 짧은 것의 길이를 return 하도록 solution 함수를 완성해주세요.</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">s의 길이는 1 이상 1,000 이하입니다.</p>



<p class="has-medium-font-size">s는 알파벳 소문자로만 이루어져 있습니다.</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">s</th><th class="has-text-align-left" data-align="left">result</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left"><code>"aabbaccc"</code></td><td class="has-text-align-left" data-align="left">7</td></tr><tr><td class="has-text-align-left" data-align="left"><code>"ababcdcdababcdcd"</code></td><td class="has-text-align-left" data-align="left">9</td></tr><tr><td class="has-text-align-left" data-align="left"><code>"abcabcdede"</code></td><td class="has-text-align-left" data-align="left">8</td></tr><tr><td class="has-text-align-left" data-align="left"><code>"abcabcabcabcdededededede"</code></td><td class="has-text-align-left" data-align="left">14</td></tr><tr><td class="has-text-align-left" data-align="left"><code>"xababcdcdababcdcd"</code></td><td class="has-text-align-left" data-align="left">17</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"><strong>입출력 예 #1</strong></p>



<p>문자열을 1개 단위로 잘라 압축했을 때 가장 짧습니다.</p>



<p class="has-medium-font-size"><strong>입출력 예 #2</strong></p>



<p>문자열을 8개 단위로 잘라 압축했을 때 가장 짧습니다.</p>



<p class="has-medium-font-size"><strong>입출력 예 #3</strong></p>



<p>문자열을 3개 단위로 잘라 압축했을 때 가장 짧습니다.</p>



<p class="has-medium-font-size"><strong>입출력 예 #4</strong></p>



<p>문자열을 2개 단위로 자르면 &#8220;abcabcabcabc6de&#8221; 가 됩니다.<br>문자열을 3개 단위로 자르면 &#8220;4abcdededededede&#8221; 가 됩니다.<br>문자열을 4개 단위로 자르면 &#8220;abcabcabcabc3dede&#8221; 가 됩니다.<br>문자열을 6개 단위로 자를 경우 &#8220;2abcabc2dedede&#8221;가 되며, 이때의 길이가 14로 가장 짧습니다.</p>



<p class="has-medium-font-size"><strong>입출력 예 #5</strong></p>



<p>문자열은 제일 앞부터 정해진 길이만큼 잘라야 합니다.<br>따라서 주어진 문자열을 x / ababcdcd / ababcdcd 로 자르는 것은 불가능 합니다.<br>이 경우 어떻게 문자열을 잘라도 압축되지 않으므로 가장 짧은 길이는 17이 됩니다.</p>



<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;vector>
#include &lt;string>
using namespace std;
int solution(string s)
{
	if (s.length() == 1) return 1; // 길이 '1' 예외 처리
	int answer = INT32_MAX;
	for (int i = 1; i &lt;= s.length() / 2; i++) {
		vector&lt;string> _ResV;
		int _AnsT = 0;
		for (int j = 0; ; j += i) {
			if (j + i > s.length()) {
				_AnsT = s.length() - j;
				break;
			}
			string _Temp = s.substr(j, i);
			_ResV.push_back(_Temp);
		}
		string _DupStr = "";
		int _DupInt = 1;
		for (int i = 0; i &lt; _ResV.size(); i++) {
			if (_ResV[i] == _DupStr) _DupInt++;	
			else {
				_AnsT += _DupStr.size();
				if (_DupInt > 1) _AnsT += to_string(_DupInt).length();
				_DupStr = _ResV[i];
				_DupInt = 1;
			}
		}
		_AnsT += _DupStr.size();
		if (_DupInt > 1) _AnsT += to_string(_DupInt).length();
		answer = min(answer, _AnsT);
	}

	return answer;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="656" height="736" src="https://lycos7560.com/wp-content/uploads/2023/04/image-16.png" alt="" class="wp-image-34350" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-16.png 656w, https://lycos7560.com/wp-content/uploads/2023/04/image-16-267x300.png 267w" sizes="(max-width: 656px) 100vw, 656px" /></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/programmers/programmers-60057-%eb%ac%b8%ec%9e%90%ec%97%b4-%ec%95%95%ec%b6%95-2020-kakao-blind-recruitment/34347/">Programmers 60057 문자열 압축 [2020 KAKAO BLIND RECRUITMENT]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/programmers/programmers-60057-%eb%ac%b8%ec%9e%90%ec%97%b4-%ec%95%95%ec%b6%95-2020-kakao-blind-recruitment/34347/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1149번 (RGB거리, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1149%eb%b2%88-rgb%ea%b1%b0%eb%a6%ac-c-baekjoon/34286/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1149%eb%b2%88-rgb%ea%b1%b0%eb%a6%ac-c-baekjoon/34286/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 04 Apr 2023 06:19:05 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1149]]></category>
		<category><![CDATA[1149번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[RGB거리]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 1149]]></category>
		<category><![CDATA[백준 1149번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34286</guid>

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



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


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-5bea3463      "
					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="#rgb거리" class="uagb-toc-link__trigger">RGB거리</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">RGB거리</h1>



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



<div style="height:30px" 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">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">0.5 초 (추가 시간 없음)</td><td class="has-text-align-left" data-align="left">128 MB</td><td class="has-text-align-left" data-align="left">95166</td><td class="has-text-align-left" data-align="left">51392</td><td class="has-text-align-left" data-align="left">38281</td><td class="has-text-align-left" data-align="left">53.315%</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">RGB거리에는 집이 N개 있다. </p>



<p class="has-medium-font-size">거리는 선분으로 나타낼 수 있고, 1번 집부터 N번 집이 순서대로&nbsp;있다.</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>



<p>1번 집의 색은 2번 집의 색과 같지 않아야 한다.</p>



<p>N번 집의 색은 N-1번 집의 색과 같지 않아야 한다.</p>



<p>i(2 ≤ i ≤ N-1)번 집의 색은 i-1번, i+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">첫째 줄에 집의 수 N(2 ≤ N ≤ 1,000)이 주어진다. </p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에는 각 집을 빨강, 초록, 파랑으로 칠하는 비용이 1번 집부터 한 줄에 하나씩 주어진다. </p>



<p class="has-medium-font-size">집을 칠하는 비용은 1,000보다 작거나 같은 자연수이다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 모든 집을 칠하는 비용의 최솟값을 출력한다.</p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3
26 40 83
49 60 57
13 89 99</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="">96</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
1 100 100
100 1 100
100 100 1</pre>



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



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



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



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">6
30 19 5
64 77 64
15 19 97
4 71 57
90 86 84
93 32 91</pre>



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



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



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



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">8
71 39 44
32 83 55
51 37 63
89 29 100
83 58 11
65 13 15
47 25 29
60 66 19</pre>



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



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



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



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



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



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



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



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



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



<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/problem/tag/25" target="_blank" rel="noreferrer noopener">다이나믹 프로그래밍</a></li>
</ul>



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



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



<p> Tuple 자료구조를 사용한 것이 생각보다 비효율적??</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;tuple>

using namespace std;

vector&lt;tuple&lt;int, int, int>> _ColorCost; // 0 - 빨강, 1 - 초록, 2 - 파랑

int N, _Co0, _Co1, _Co2;;

int dp[3][10001];

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

	cin >> N;
	for (int i = 0; i &lt; N; i++) {
		cin >> _Co0 >> _Co1 >> _Co2;
		_ColorCost.push_back(make_tuple(_Co0, _Co1, _Co2));
	}

	// 처음을 어떤 색으로 시작하는 가?
	dp[0][1] = get&lt;0>(_ColorCost[0]);
	dp[1][1] = get&lt;1>(_ColorCost[0]);
	dp[2][1] = get&lt;2>(_ColorCost[0]);
	
	// 시작 값을 최소값으로 정한다고 결과가 최소라는 것은 아니다.
	for (int i = 2; i &lt;= N; i++) { 
		dp[0][i] = min(dp[1][i - 1], dp[2][i - 1]) + get&lt;0>(_ColorCost[i - 1]);
		dp[1][i] = min(dp[0][i - 1], dp[2][i - 1]) + get&lt;1>(_ColorCost[i - 1]);
		dp[2][i] = min(dp[0][i - 1], dp[1][i - 1]) + get&lt;2>(_ColorCost[i - 1]);
	}

	// 시작 색이 어떤 색인지에 따라서 3가지의 결과가 나온다.
	cout &lt;&lt; min(dp[0][N], min(dp[1][N], dp[2][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/04/image-5.png" alt="" class="wp-image-34288" width="935" height="105" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-5.png 908w, https://lycos7560.com/wp-content/uploads/2023/04/image-5-300x34.png 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-5-768x86.png 768w" sizes="(max-width: 935px) 100vw, 935px" /></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-1149%eb%b2%88-rgb%ea%b1%b0%eb%a6%ac-c-baekjoon/34286/">백준 1149번 (RGB거리, 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-1149%eb%b2%88-rgb%ea%b1%b0%eb%a6%ac-c-baekjoon/34286/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 17682 [1차] 다트 게임 [2018 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-17682-1%ec%b0%a8-%eb%8b%a4%ed%8a%b8-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/34054/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-17682-1%ec%b0%a8-%eb%8b%a4%ed%8a%b8-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/34054/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 15 Mar 2023 18:18:37 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[1차] 다트 게임]]></category>
		<category><![CDATA[17682]]></category>
		<category><![CDATA[17682번]]></category>
		<category><![CDATA[2018 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Programmers 17682]]></category>
		<category><![CDATA[Programmers 17682번]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다트 게임]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34054</guid>

					<description><![CDATA[<p>Programmers 17682 '[1차] 다트 게임' 문제에 대한 글입니다.<br />
단순 구현 문제입니다. (This article is about the programmers 17682 '[1st] Dart Game' problem.<br />
It's a simple implementation problem.)</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-17682-1%ec%b0%a8-%eb%8b%a4%ed%8a%b8-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/34054/">Programmers 17682 [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-457c7091      "
					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/17682" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/17682</a></p>



<div style="height:40px" 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="520" height="695" src="https://lycos7560.com/wp-content/uploads/2023/03/image-58.jpg" alt="" class="wp-image-34057" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-58.jpg 520w, https://lycos7560.com/wp-content/uploads/2023/03/image-58-224x300.jpg 224w" sizes="(max-width: 520px) 100vw, 520px" /></figure>



<div style="height:22px" 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>



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



<p class="has-medium-font-size">1. 다트 게임은 총 3번의 기회로 구성된다.</p>



<p class="has-medium-font-size">2. 각 기회마다 얻을 수 있는 점수는 0점에서 10점까지이다.</p>



<p class="has-medium-font-size">3. 점수와 함께 Single(S), Double(D), Triple(T) 영역이 존재하고 각 영역 당첨 시 점수에서 1제곱, 2제곱, 3제곱 (점수1&nbsp;, 점수2&nbsp;, 점수3&nbsp;)으로 계산된다.</p>



<p class="has-medium-font-size">4. 옵션으로 스타상(<em>) , 아차상(#)이 존재하며 스타상(</em>) 당첨 시 해당 점수와 바로 전에 얻은 점수를 각 2배로 만든다. 아차상(#) 당첨 시 해당 점수는 마이너스된다.</p>



<p class="has-medium-font-size">5. 스타상(<em>)은 첫 번째 기회에서도 나올 수 있다. 이 경우 첫 번째 스타상(</em>)의 점수만 2배가 된다. (예제 4번 참고)</p>



<p class="has-medium-font-size">6. 스타상(<em>)의 효과는 다른 스타상(</em>)의 효과와 중첩될 수 있다. 이 경우 중첩된 스타상(*) 점수는 4배가 된다. (예제 4번 참고)</p>



<p class="has-medium-font-size">7. 스타상(*)의 효과는 아차상(#)의 효과와 중첩될 수 있다. 이 경우 중첩된 아차상(#)의 점수는 -2배가 된다. (예제 5번 참고)</p>



<p class="has-medium-font-size">8. Single(S), Double(D), Triple(T)은 점수마다 하나씩 존재한다.</p>



<p class="has-medium-font-size">9. 스타상(*), 아차상(#)은 점수마다 둘 중 하나만 존재할 수 있으며, 존재하지 않을 수도 있다.</p>



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



<p class="has-medium-font-size">0~10의 정수와 문자 S, D, T, *, #로 구성된 문자열이 입력될 시 총점수를 반환하는 함수를 작성하라.</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">&#8220;점수|보너스|[옵션]&#8221;으로 이루어진 문자열 3세트.</p>



<p class="has-medium-font-size">예)&nbsp;<code>1S2D*3T</code></p>



<ul class="wp-block-list">
<li>점수는 0에서 10 사이의 정수이다.</li>



<li>보너스는 S, D, T 중 하나이다.</li>



<li>옵선은 *이나 # 중 하나이며, 없을 수도 있다.</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">3번의 기회에서 얻은 점수 합계에 해당하는 정수값을 출력한다.</p>



<p class="has-medium-font-size">예) 37</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">예제</th><th class="has-text-align-left" data-align="left">dartResult</th><th class="has-text-align-left" data-align="left">answer</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"><code>1S2D*3T</code></td><td class="has-text-align-left" data-align="left">37</td><td class="has-text-align-left" data-align="left">1<sup>1</sup>&nbsp;* 2 + 2<sup>2</sup>&nbsp;* 2 + 3<sup>3</sup></td></tr><tr><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left"><code>1D2S#10S</code></td><td class="has-text-align-left" data-align="left">9</td><td class="has-text-align-left" data-align="left">1<sup>2</sup>&nbsp;+ 2<sup>1</sup>&nbsp;* (-1) + 10<sup>1</sup></td></tr><tr><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left"><code>1D2S0T</code></td><td class="has-text-align-left" data-align="left">3</td><td class="has-text-align-left" data-align="left">1<sup>2</sup>&nbsp;+ 2<sup>1</sup>&nbsp;+ 0<sup>3</sup></td></tr><tr><td class="has-text-align-left" data-align="left">4</td><td class="has-text-align-left" data-align="left"><code>1S*2T*3S</code></td><td class="has-text-align-left" data-align="left">23</td><td class="has-text-align-left" data-align="left">1<sup>1</sup>&nbsp;* 2 * 2 + 2<sup>3</sup>&nbsp;* 2 + 3<sup>1</sup></td></tr><tr><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left"><code>1D#2S*3S</code></td><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">1<sup>2</sup>&nbsp;* (-1) * 2 + 2<sup>1</sup>&nbsp;* 2 + 3<sup>1</sup></td></tr><tr><td class="has-text-align-left" data-align="left">6</td><td class="has-text-align-left" data-align="left"><code>1T2D3D#</code></td><td class="has-text-align-left" data-align="left">-4</td><td class="has-text-align-left" data-align="left">1<sup>3</sup>&nbsp;+ 2<sup>2</sup>&nbsp;+ 3<sup>2</sup>&nbsp;* (-1)</td></tr><tr><td class="has-text-align-left" data-align="left">7</td><td class="has-text-align-left" data-align="left"><code>1D2S3T*</code></td><td class="has-text-align-left" data-align="left">59</td><td class="has-text-align-left" data-align="left">1<sup>2</sup>&nbsp;+ 2<sup>1</sup>&nbsp;* 2 + 3<sup>3</sup>&nbsp;* 2</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>



<figure class="wp-block-image size-full"><img decoding="async" width="1600" height="1432" src="https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230316_032048465.jpg" alt="" class="wp-image-34061" srcset="https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230316_032048465.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230316_032048465-300x269.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230316_032048465-768x687.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230316_032048465-1536x1375.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;string>
#include &lt;cstdlib>
#include &lt;cmath>

using namespace std;

struct RoundResult // 라운드 결과 구조체
{
    int score;
    int bonus;
    int option;
    int Sum;
    RoundResult() {
        score = 0;
        bonus = 1;
        option = 1;
        Sum = 0;
    }
} RoundResult[3]; // 인덱스 0 ~ 2 선언

int solution(string dartResult) {
    int answer = 0;
    int pivot = 0;
    string str = "";
    for (int i = 0; i &lt; 3; i++) { // 파싱(parsing)
        for (pivot &lt; dartResult.length();;) {
            if (dartResult[pivot] >= 48 &amp;&amp; dartResult[pivot] &lt;= 57) { // 0 ~ 9
                str.push_back(dartResult[pivot]);
                pivot++;
            }
            else {
                RoundResult[i].score = atoi(str.c_str());
                str = "";
                break;
            }
        }

        switch (dartResult[pivot]) {
            case 'S':
                RoundResult[i].bonus = 1;
                pivot++;
                break;
            case 'D':
                RoundResult[i].bonus = 2;
                pivot++;
                break;
            case 'T':
                RoundResult[i].bonus = 3;
                pivot++;
                break;
        }

        switch (dartResult[pivot]) {
            case '*':
                RoundResult[i].option = 2;
                pivot++;
                break;
            case '#':
                RoundResult[i].option = -1;
                pivot++;
                break;
            default:
                break;
        }
    }

    for (int i = 0; i &lt; 3; i++) { // 결과 처리
        RoundResult[i].Sum = pow(RoundResult[i].score, RoundResult[i].bonus) * RoundResult[i].option;
        if (RoundResult[i].option == 2 &amp;&amp; i - 1 >= 0)RoundResult[i - 1].Sum *= RoundResult[i].option;    
    }

    for (int i = 0; i &lt; 3; i++) answer += RoundResult[i].Sum;
    
    return answer;
}
</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="557" height="925" src="https://lycos7560.com/wp-content/uploads/2023/03/image-58.png" alt="" class="wp-image-34058" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-58.png 557w, https://lycos7560.com/wp-content/uploads/2023/03/image-58-181x300.png 181w" sizes="(max-width: 557px) 100vw, 557px" /></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/programmers/programmers-17682-1%ec%b0%a8-%eb%8b%a4%ed%8a%b8-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/34054/">Programmers 17682 [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-17682-1%ec%b0%a8-%eb%8b%a4%ed%8a%b8-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/34054/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 17685 [3차] 자동완성 [2018 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-17685-3%ec%b0%a8-%ec%9e%90%eb%8f%99%ec%99%84%ec%84%b1-2018-kakao-blind-recruitment/33995/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-17685-3%ec%b0%a8-%ec%9e%90%eb%8f%99%ec%99%84%ec%84%b1-2018-kakao-blind-recruitment/33995/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 14 Mar 2023 18:14:09 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[3차] 자동완성]]></category>
		<category><![CDATA[17685]]></category>
		<category><![CDATA[17685번]]></category>
		<category><![CDATA[2018 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Programmers 17685]]></category>
		<category><![CDATA[Programmers 17685번]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Trie]]></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[트라이(Trie)]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33995</guid>

					<description><![CDATA[<p>Programmers 17685 '[3차] 자동완성' 문제에 대한 글입니다.  'Trie' 자료구조를 이용하여 해결하였습니다. (This article is about the programmers 17685 '[3rd] AutoComplete' problem. We solved it using the 'Trie' data structure.)</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-17685-3%ec%b0%a8-%ec%9e%90%eb%8f%99%ec%99%84%ec%84%b1-2018-kakao-blind-recruitment/33995/">Programmers 17685 [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-81dc97a8      "
					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><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#접근-방법" class="uagb-toc-link__trigger">접근 방법</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a></ul></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/17685#" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/17685#</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">예를 들어,&nbsp;<code>go</code>&nbsp;가 한 번 입력되었다면, 다음 사용자는&nbsp;<code>g</code>&nbsp;만 입력해도&nbsp;<code>go</code>를 추천해주므로&nbsp;<code>o</code>를 입력할 필요가 없어진다! </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>



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



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



<ul class="wp-block-list">
<li><code>go</code>를 찾을 때&nbsp;<code>go</code>를 모두 입력해야 한다.</li>



<li><code>gone</code>을 찾을 때&nbsp;<code>gon</code>&nbsp;까지 입력해야 한다. (<code>gon</code>이 입력되기 전까지는&nbsp;<code>go</code>&nbsp;인지&nbsp;<code>gone</code>인지 확신할 수 없다.)</li>



<li><code>guild</code>를 찾을 때는&nbsp;<code>gu</code>&nbsp;까지만 입력하면&nbsp;<code>guild</code>가 완성된다.</li>
</ul>



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



<p class="has-medium-font-size">이 경우 총 입력해야 할 문자의 수는&nbsp;<code>7</code>이다.</p>



<p class="has-medium-font-size">라이언을 도와 위와 같이 문자열이 입력으로 주어지면 학습을 시킨 후, </p>



<p class="has-medium-font-size">학습된 단어들을 순서대로 찾을 때 몇 개의 문자를 입력하면 되는지 계산하는 프로그램을 만들어보자.</p>



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



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



<p class="has-medium-font-size">학습과 검색에 사용될 중복 없는 단어&nbsp;<code>N</code>개가 주어진다.</p>



<p class="has-medium-font-size">모든 단어는 알파벳 소문자로 구성되며 단어의 수&nbsp;<code>N</code>과 단어들의 길이의 총합&nbsp;<code>L</code>의 범위는 다음과 같다.</p>



<ul class="wp-block-list">
<li>2 &lt;=&nbsp;<code>N</code>&nbsp;&lt;= 100,000</li>



<li>2 &lt;=&nbsp;<code>L</code>&nbsp;&lt;= 1,000,000</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>



<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">words</th><th class="has-text-align-left" data-align="left">result</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">[&#8220;go&#8221;,&#8221;gone&#8221;,&#8221;guild&#8221;]</td><td class="has-text-align-left" data-align="left">7</td></tr><tr><td class="has-text-align-left" data-align="left">[&#8220;abc&#8221;,&#8221;def&#8221;,&#8221;ghi&#8221;,&#8221;jklm&#8221;]</td><td class="has-text-align-left" data-align="left">4</td></tr><tr><td class="has-text-align-left" data-align="left">[&#8220;word&#8221;,&#8221;war&#8221;,&#8221;warrior&#8221;,&#8221;world&#8221;]</td><td class="has-text-align-left" data-align="left">15</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading">입출력 설명</h3>



<ul class="wp-block-list">
<li>첫 번째 예제는 본문 설명과 같다.</li>



<li>두 번째 예제에서는 모든 단어들이 공통된 부분이 없으므로, 가장 앞글자만 입력하면 된다.</li>



<li>세 번째 예제는 총&nbsp;<code>15</code>&nbsp;자를 입력해야 하고 설명은 아래와 같다.
<ul class="wp-block-list">
<li><code>word</code>는&nbsp;<code>word</code>모두 입력해야 한다.</li>



<li><code>war</code>는&nbsp;<code>war</code>&nbsp;까지 모두 입력해야 한다.</li>



<li><code>warrior</code>는&nbsp;<code>warr</code>&nbsp;까지만 입력하면 된다.</li>



<li><code>world</code>는&nbsp;<code>worl</code>까지 입력해야 한다. (<code>word</code>와 구분되어야 함을 명심하자)</li>
</ul>
</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)"/>



<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="1548" height="1920" src="https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230315_025902657.jpg" alt="" class="wp-image-34005" srcset="https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230315_025902657.jpg 1548w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230315_025902657-242x300.jpg 242w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230315_025902657-768x953.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/03/KakaoTalk_20230315_025902657-1238x1536.jpg 1238w" sizes="(max-width: 1548px) 100vw, 1548px" /></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;string>
#include &lt;vector>
#include &lt;unordered_map>

using namespace std;

// TrieNode클래스를 사용하여 Trie의 각 노드를 표현
class TrieNode {
public:
    unordered_map&lt;char, TrieNode*> children;
    int num; // 연관된 단어의 개수를 저장
    TrieNode() {
        num = 0;
    }
};

// Trie 클래스
class Trie {

private: // Trie의 루트 노드에 대한 포인터인 Trie개인 멤버 변수
    TrieNode* root; // 루트 노드


public:
    Trie() { // 생성자새 인스턴스를 만들고 Trie를 초기화
        root = new TrieNode();
    }

    // 문자열을 받아 Trie에 추가합니다. 
    // 루트 노드에서 시작하여 Trie 아래로 이동하여 단어의 각 문자에 필요한 새 노드를 만듭니다.
    void insert(string word) {
        TrieNode* curr = root; // 시작
        for (char c : word) {
            if (curr->children.find(c) == curr->children.end()) {
                // Trie에 없다면 새 노드 생성
                curr->children[c] = new TrieNode();
            }

            // Trie에 이미 존재하는 경우 기존 노드로 이동
            curr = curr->children[c];
            curr->num++; // 연관된 단어의 개수 추가
        }
    }

    // 단어를 검색합니다.
    // 연관된 단어의 개수가 1이라면 글자수 반환
    int search(string word) {
        TrieNode* curr = root;
        int cnt = 0;
        for (char c : word) {
            curr = curr->children[c];
            cnt++;
            if (curr->num == 1) {
                // 연관된 단어의 개수가 1이라면 
                // 자동완성
                return cnt;
            }
        }
        return 9999; // 문제에서 나올 수 없는 경우 
    }

    // prefix(접두사)로 시작하는 단어가 Trie에 있는지 확인
    int startsWith(string prefix) {
        TrieNode* curr = root;
        for (char c : prefix) {
            if (curr->children.find(c) == curr->children.end()) {
                return false;
            }
            curr = curr->children[c];
        }
        return curr->children.size();
    }

};

int solution(vector&lt;string> words) {
    int answer = 0;
    Trie trie;
    for (auto&amp; it : words) {
        trie.insert(it);
    }

    for (auto&amp; it : words) {
        if (trie.startsWith(it) >= 1) {
            // 접두사로 시작하는 단어가 있다면 
            // 단어 전체를 입력해야한다.
            answer += it.length();
            continue;
        }

        // 자동완성 확인
        answer += trie.search(it);
    }

    return answer;
}</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/03/image-54.png" alt="" class="wp-image-34000" width="651" height="600" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-54.png 639w, https://lycos7560.com/wp-content/uploads/2023/03/image-54-300x277.png 300w" sizes="(max-width: 651px) 100vw, 651px" /></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-17685-3%ec%b0%a8-%ec%9e%90%eb%8f%99%ec%99%84%ec%84%b1-2018-kakao-blind-recruitment/33995/">Programmers 17685 [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-17685-3%ec%b0%a8-%ec%9e%90%eb%8f%99%ec%99%84%ec%84%b1-2018-kakao-blind-recruitment/33995/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 17683 [3차] 방금그곡 [2018 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-17683-3%ec%b0%a8-%eb%b0%a9%ea%b8%88%ea%b7%b8%ea%b3%a1-2018-kakao-blind-recruitment/33916/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-17683-3%ec%b0%a8-%eb%b0%a9%ea%b8%88%ea%b7%b8%ea%b3%a1-2018-kakao-blind-recruitment/33916/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 12 Mar 2023 16:52:00 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[3차] 방금그곡]]></category>
		<category><![CDATA[17683]]></category>
		<category><![CDATA[17683번]]></category>
		<category><![CDATA[2018 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[cstdlib]]></category>
		<category><![CDATA[Programmers 17683]]></category>
		<category><![CDATA[Programmers 17683번]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[tuple]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[문자열]]></category>
		<category><![CDATA[방금그곡]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33916</guid>

					<description><![CDATA[<p>Programmers 17683 '[3차] 방금그곡' 문제에 대한 글입니다. (Programmers 17683 This article is about the '[Third] Just Now Song' problem. ) [2018 KAKAO BLIND RECRUITMENT]</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-17683-3%ec%b0%a8-%eb%b0%a9%ea%b8%88%ea%b7%b8%ea%b3%a1-2018-kakao-blind-recruitment/33916/">Programmers 17683 [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-7d914654      "
					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/17683" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/17683</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">그럴 때 네오는 다음 포털의 &#8216;방금그곡&#8217; 서비스를 이용하곤 한다. </p>



<p class="has-medium-font-size">방금그곡에서는 TV, 라디오 등에서 나온 음악에 관해 제목 등의 정보를 제공하는 서비스이다.</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>



<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">네오가 기억한 멜로디와 악보에 사용되는 음은 C, C#, D, D#, E, F, F#, G, G#, A, A#, B 12개이다.</p>



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



<p class="has-medium-font-size">각 음은 1분에 1개씩 재생된다. 음악은 반드시 처음부터 재생되며 음악 길이보다 재생된 시간이 길 때는 <br>음악이 끊김 없이 처음부터 반복해서 재생된다. 음악 길이보다 재생된 시간이 짧을 때는 처음부터 재생 시간만큼만 재생된다.</p>



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



<p class="has-medium-font-size">음악이 00:00를 넘겨서까지 재생되는 일은 없다.</p>



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



<p class="has-medium-font-size">조건이 일치하는 음악이 여러 개일 때에는 라디오에서 재생된 시간이 제일 긴 음악 제목을 반환한다. <br>재생된 시간도 같을 경우 먼저 입력된 음악 제목을 반환한다.</p>



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



<p class="has-medium-font-size">조건이 일치하는 음악이 없을 때에는 “(None)”을 반환한다.</p>



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



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



<p class="has-medium-font-size">입력으로 네오가 기억한 멜로디를 담은 문자열&nbsp;<code>m</code>과 방송된 곡의 정보를 담고 있는 배열&nbsp;<code>musicinfos</code>가 주어진다.</p>



<ul class="wp-block-list">
<li><code>m</code>은 음&nbsp;<code>1</code>개 이상&nbsp;<code>1439</code>개 이하로 구성되어 있다.</li>



<li><code>musicinfos</code>는&nbsp;<code>100</code>개 이하의 곡 정보를 담고 있는 배열로, 각각의 곡 정보는 음악이 시작한 시각, 끝난 시각, 음악 제목, 악보 정보가 &#8216;<code>,</code>&#8216;로 구분된 문자열이다.
<ul class="wp-block-list">
<li>음악의 시작 시각과 끝난 시각은 24시간&nbsp;<code>HH:MM</code>&nbsp;형식이다.</li>



<li>음악 제목은 &#8216;<code>,</code>&#8216; 이외의 출력 가능한 문자로 표현된 길이&nbsp;<code>1</code>&nbsp;이상&nbsp;<code>64</code>&nbsp;이하의 문자열이다.</li>



<li>악보 정보는 음&nbsp;<code>1</code>개 이상&nbsp;<code>1439</code>개 이하로 구성되어 있다.</li>
</ul>
</li>
</ul>



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



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



<p class="has-medium-font-size">조건과 일치하는 음악 제목을 출력한다.</p>



<div style="height:62px" 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">m</th><th class="has-text-align-left" data-align="left">musicinfos</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">&#8220;ABCDEFG&#8221;</td><td class="has-text-align-left" data-align="left">[&#8220;12:00,12:14,HELLO,CDEFGAB&#8221;, &#8220;13:00,13:05,WORLD,ABCDEF&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;HELLO&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">&#8220;CC#BCC#BCC#BCC#B&#8221;</td><td class="has-text-align-left" data-align="left">[&#8220;03:00,03:30,FOO,CC#B&#8221;, &#8220;04:00,04:08,BAR,CC#BCC#BCC#B&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;FOO&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">&#8220;ABC&#8221;</td><td class="has-text-align-left" data-align="left">[&#8220;12:00,12:14,HELLO,C#DEFGAB&#8221;, &#8220;13:00,13:05,WORLD,ABCDEF&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;WORLD&#8221;</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading">설명</h3>



<p>첫 번째 예시에서 HELLO는 길이가 7분이지만 12:00부터 12:14까지 재생되었으므로 실제로 CDEFGABCDEFGAB로 재생되었고, 이 중에 기억한 멜로디인 ABCDEFG가 들어있다.<br>세 번째 예시에서 HELLO는 C#DEFGABC#DEFGAB로, WORLD는 ABCDE로 재생되었다. HELLO 안에 있는 ABC#은 기억한 멜로디인 ABC와 일치하지 않고, WORLD 안에 있는 ABC가 기억한 멜로디와 일치한다.</p>



<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;vector>
#include &lt;algorithm>
#include &lt;tuple>


using namespace std;

string DistinguishMelody(string m) // # 부분을 처리
{
    string str;
    for (int i = m.length() - 1; i >= 0; i--) {
        if (m[i] == '#') {
            str.push_back(m[i - 1] + 32);
            i--;
        }
        else str.push_back(m[i]);
    }
    reverse(str.begin(), str.end());
    return str;
}

tuple&lt;string, string, int> Slicing(string str)
{
    int startH = atoi(str.substr(0, 2).c_str());
    int endH = atoi(str.substr(6, 2).c_str());
    int startM = atoi(str.substr(3, 2).c_str());
    int endM = atoi(str.substr(9, 2).c_str());
    int resInt = (endH - startH) * 60 + (endM - startM);
    string str2 = str.substr(12, str.length() - 1);
    int pv = 0;
    for (int i = 0; i &lt; str2.length(); i++) {
        if (str2[i] == ',') {
            pv = i;
            break;
        }
    }
    string name = str2.substr(0, pv);
    string melody = DistinguishMelody(str2.substr(pv + 1, str.length() - 1));
    int cnt = melody.length();
    for (int i = melody.length(); i &lt; resInt; i++) {
        melody.push_back(melody[i % cnt]);
    }
    melody = melody.substr(0, resInt);

    tuple&lt;string, string, int> res = make_tuple(name, melody, resInt);
    return res;
}

string solution(string m, vector&lt;string> musicinfos) {
    string answer = "";
    m = DistinguishMelody(m);
    int answerlength = 0;
    for (auto &amp;it : musicinfos) {
        tuple&lt;string, string, int> res = Slicing(it);
        string str = get&lt;1>(res);

        for (int i = 0; i &lt; str.length(); i++) {
           for (int j = 0; j &lt; m.length(); j++) {
              if (str[j + i] != m[j]) break;
              if (j == m.length() - 1) {
                  if (get&lt;2>(res) > answerlength) {
                      answerlength = get&lt;2>(res);
                      answer = get&lt;0>(res);
                  }
              }
           }
        }
    }
    
    if (answerlength == 0) answer = "(None)";

    return answer;
}</pre>



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



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



<figure class="wp-block-image size-full"><img decoding="async" width="709" height="785" src="https://lycos7560.com/wp-content/uploads/2023/03/image-46.png" alt="" class="wp-image-33918" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-46.png 709w, https://lycos7560.com/wp-content/uploads/2023/03/image-46-271x300.png 271w" sizes="(max-width: 709px) 100vw, 709px" /></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/programmers/programmers-17683-3%ec%b0%a8-%eb%b0%a9%ea%b8%88%ea%b7%b8%ea%b3%a1-2018-kakao-blind-recruitment/33916/">Programmers 17683 [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-17683-3%ec%b0%a8-%eb%b0%a9%ea%b8%88%ea%b7%b8%ea%b3%a1-2018-kakao-blind-recruitment/33916/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 17687 [3차] n진수 게임 [2018 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-17687-3%ec%b0%a8-n%ec%a7%84%ec%88%98-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/33817/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-17687-3%ec%b0%a8-n%ec%a7%84%ec%88%98-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/33817/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 09 Mar 2023 16:37:35 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[3차] n진수 게임]]></category>
		<category><![CDATA[<algorithm>]]></category>
		<category><![CDATA[<cstdlib>]]></category>
		<category><![CDATA[<string>]]></category>
		<category><![CDATA[17687]]></category>
		<category><![CDATA[17687번]]></category>
		<category><![CDATA[2018 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[cstdlib]]></category>
		<category><![CDATA[n진수]]></category>
		<category><![CDATA[n진수 게임]]></category>
		<category><![CDATA[Programmers 17687]]></category>
		<category><![CDATA[Programmers 17687번]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[문자열]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33817</guid>

					<description><![CDATA[<p>Programmers 17687 '[3차] n진수 게임' 문제에 대한 글입니다. [2018 KAKAO BLIND RECRUITMENT] (This is an article about the problem of Programmers 17687 '[3rd] n-digit game'. [2018 KAKAO BLIND RECRUITMENT])</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-17687-3%ec%b0%a8-n%ec%a7%84%ec%88%98-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/33817/">Programmers 17687 [3차] n진수 게임 [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-e372bf42      "
					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="#n진수-게임" class="uagb-toc-link__trigger">n진수 게임</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">n진수 게임</h1>



<p class="has-medium-font-size"><a href="https://school.programmers.co.kr/learn/courses/30/lessons/17687" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/17687</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">1. 숫자를 0부터 시작해서 차례대로 말한다. </p>



<p class="has-medium-font-size">첫 번째 사람은 0, 두 번째 사람은 1, … 열 번째 사람은 9를 말한다.</p>



<p class="has-medium-font-size">2. 10 이상의 숫자부터는 한 자리씩 끊어서 말한다. </p>



<p class="has-medium-font-size">즉 열한 번째 사람은 10의 첫 자리인 1, 열두 번째 사람은 둘째 자리인 0을 말한다.</p>



<p class="has-medium-font-size">이렇게 게임을 진행할 경우,<br><code>0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, …</code><br>순으로 숫자를 말하면 된다.</p>



<p class="has-medium-font-size">한편 코딩 동아리 일원들은 컴퓨터를 다루는 사람답게 이진수로 이 게임을 진행하기도 하는데, 이 경우에는<br><code>0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, …</code><br>순으로 숫자를 말하면 된다.</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>



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



<p class="has-medium-font-size">진법&nbsp;<code>n</code>, 미리 구할 숫자의 갯수&nbsp;<code>t</code>, 게임에 참가하는 인원&nbsp;<code>m</code>, 튜브의 순서&nbsp;<code>p</code>&nbsp;가 주어진다.</p>



<ul class="wp-block-list">
<li>2 ≦&nbsp;<code>n</code>&nbsp;≦ 16</li>



<li>0 ＜&nbsp;<code>t</code>&nbsp;≦ 1000</li>



<li>2 ≦&nbsp;<code>m</code>&nbsp;≦ 100</li>



<li>1 ≦&nbsp;<code>p</code>&nbsp;≦&nbsp;<code>m</code></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">튜브가 말해야 하는 숫자&nbsp;<code>t</code>개를 공백 없이 차례대로 나타낸 문자열. </p>



<p class="has-medium-font-size">단,&nbsp;<code>10</code>~<code>15</code>는 각각 대문자&nbsp;<code>A</code>~<code>F</code>로 출력한다.</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><thead><tr><th class="has-text-align-left" data-align="left">n</th><th class="has-text-align-left" data-align="left">t</th><th class="has-text-align-left" data-align="left">m</th><th class="has-text-align-left" data-align="left">p</th><th class="has-text-align-left" data-align="left">result</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">4</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">&#8220;0111&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">16</td><td class="has-text-align-left" data-align="left">16</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">&#8220;02468ACE11111111&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">16</td><td class="has-text-align-left" data-align="left">16</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">&#8220;13579BDF01234567&#8221;</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;vector>
#include &lt;algorithm> 

using namespace std;

string decimalToN(int decimalNum, int n) { // N진수로 변환
    if (decimalNum == 0) return "0";
    string str;
    while (decimalNum != 0) {
        int remainder = decimalNum % n;
        if (remainder &lt; 10) str.push_back(remainder + 48); // 숫자
        else str.push_back(remainder + 55); // 알파벳
        decimalNum /= n;
    }
    reverse(str.begin(), str.end()); // 뒤집기
    return str;
}

string solution(int n, int t, int m, int p) {
    string answer = "";
    int cnt = 1;
    for (int i = 0; answer.length() &lt;= t; i++) {
        string str = decimalToN(i, n);
        for (int j = 0; j &lt; str.length(); j++) {
            if (cnt == p) answer.push_back(str[j]);
            cnt++;
            if (cnt == m + 1) cnt = 1;
        }
    }

    return answer.substr(0, t);
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="661" height="692" src="https://lycos7560.com/wp-content/uploads/2023/03/image-30.png" alt="" class="wp-image-33825" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-30.png 661w, https://lycos7560.com/wp-content/uploads/2023/03/image-30-287x300.png 287w" sizes="(max-width: 661px) 100vw, 661px" /></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-17687-3%ec%b0%a8-n%ec%a7%84%ec%88%98-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/33817/">Programmers 17687 [3차] n진수 게임 [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-17687-3%ec%b0%a8-n%ec%a7%84%ec%88%98-%ea%b2%8c%ec%9e%84-2018-kakao-blind-recruitment/33817/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Programmers 17678 [1차] 셔틀버스 [2018 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-17678-1%ec%b0%a8-%ec%85%94%ed%8b%80%eb%b2%84%ec%8a%a4-2018-kakao-blind-recruitment/33806/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-17678-1%ec%b0%a8-%ec%85%94%ed%8b%80%eb%b2%84%ec%8a%a4-2018-kakao-blind-recruitment/33806/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 09 Mar 2023 14:48:41 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[1차] 셔틀버스]]></category>
		<category><![CDATA[<algorithm>]]></category>
		<category><![CDATA[<cstdlib>]]></category>
		<category><![CDATA[<string>]]></category>
		<category><![CDATA[17678]]></category>
		<category><![CDATA[17678번]]></category>
		<category><![CDATA[2018 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[cstdlib]]></category>
		<category><![CDATA[Programmers 17678]]></category>
		<category><![CDATA[Programmers 17678번]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[문자열]]></category>
		<category><![CDATA[셔틀버스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=33806</guid>

					<description><![CDATA[<p>Programmers 17678 '셔틀버스' 문제에 대한 글입니다. [2018 KAKAO BLIND RECRUITMENT]</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-17678-1%ec%b0%a8-%ec%85%94%ed%8b%80%eb%b2%84%ec%8a%a4-2018-kakao-blind-recruitment/33806/">Programmers 17678 [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-ec3e18c9      "
					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/17678" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/learn/courses/30/lessons/17678</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">카카오의 직원은 서로를 &#8216;크루&#8217;라고 부르는데, 아침마다 많은 크루들이 이 셔틀을 이용하여 출근한다.</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. 셔틀은&nbsp;<code>09:00</code>부터 총&nbsp;<code>n</code>회&nbsp;<code>t</code>분 간격으로 역에 도착하며, 하나의 셔틀에는 최대&nbsp;<code>m</code>명의 승객이 탈 수 있다.</p>



<p class="has-medium-font-size">2. 셔틀은 도착했을 때 도착한 순간에 대기열에 선 크루까지 포함해서 대기 순서대로 태우고 바로 출발한다. <br>예를 들어&nbsp;<code>09:00</code>에 도착한 셔틀은 자리가 있다면&nbsp;<code>09:00</code>에 줄을 선 크루도 탈 수 있다.</p>



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



<p class="has-medium-font-size">일찍 나와서 셔틀을 기다리는 것이 귀찮았던 콘은, 일주일간의 집요한 관찰 끝에 어떤 크루가 몇 시에 셔틀 대기열에 도착하는지 알아냈다. </p>



<p class="has-medium-font-size">콘이 셔틀을 타고 사무실로 갈 수 있는 도착 시각 중 제일 늦은 시각을 구하여라.</p>



<p class="has-medium-font-size">단, 콘은 게으르기 때문에 같은 시각에 도착한 크루 중 대기열에서 제일 뒤에 선다. </p>



<p class="has-medium-font-size">또한, 모든 크루는 잠을 자야 하므로&nbsp;<code>23:59</code>에 집에 돌아간다. </p>



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



<p class="has-medium-font-size">셔틀 운행 횟수&nbsp;<code>n</code>, 셔틀 운행 간격&nbsp;<code>t</code>, 한 셔틀에 탈 수 있는 최대 크루 수&nbsp;<code>m</code>, </p>



<p class="has-medium-font-size">크루가 대기열에 도착하는 시각을 모은 배열&nbsp;<code>timetable</code>이 입력으로 주어진다.</p>



<ul class="wp-block-list">
<li>0 ＜&nbsp;<code>n</code>&nbsp;≦ 10</li>



<li>0 ＜&nbsp;<code>t</code>&nbsp;≦ 60</li>



<li>0 ＜&nbsp;<code>m</code>&nbsp;≦ 45</li>



<li><code>timetable</code>은 최소 길이 1이고 최대 길이 2000인 배열로, 하루 동안 크루가 대기열에 도착하는 시각이&nbsp;<code>HH:MM</code>&nbsp;형식으로 이루어져 있다.</li>



<li>크루의 도착 시각&nbsp;<code>HH:MM</code>은&nbsp;<code>00:01</code>에서&nbsp;<code>23:59</code>&nbsp;사이이다.</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">도착 시각은&nbsp;<code>HH:MM</code>&nbsp;형식이며,&nbsp;<code>00:00</code>에서&nbsp;<code>23:59</code>&nbsp;사이의 값이 될 수 있다.</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><thead><tr><th class="has-text-align-left" data-align="left">n</th><th class="has-text-align-left" data-align="left">t</th><th class="has-text-align-left" data-align="left">m</th><th class="has-text-align-left" data-align="left">timetable</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">1</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">[&#8220;08:00&#8221;, &#8220;08:01&#8221;, &#8220;08:02&#8221;, &#8220;08:03&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;09:00&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">10</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">[&#8220;09:10&#8221;, &#8220;09:09&#8221;, &#8220;08:00&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;09:09&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">2</td><td class="has-text-align-left" data-align="left">[&#8220;09:00&#8221;, &#8220;09:00&#8221;, &#8220;09:00&#8221;, &#8220;09:00&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;08:59&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">5</td><td class="has-text-align-left" data-align="left">[&#8220;00:01&#8221;, &#8220;00:01&#8221;, &#8220;00:01&#8221;, &#8220;00:01&#8221;, &#8220;00:01&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;00:00&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">1</td><td class="has-text-align-left" data-align="left">[&#8220;23:59&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;09:00&#8221;</td></tr><tr><td class="has-text-align-left" data-align="left">10</td><td class="has-text-align-left" data-align="left">60</td><td class="has-text-align-left" data-align="left">45</td><td class="has-text-align-left" data-align="left">[&#8220;23:59&#8243;,&#8221;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;, &#8220;23:59&#8221;]</td><td class="has-text-align-left" data-align="left">&#8220;18:00&#8221;</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;vector>
#include &lt;map>
#include &lt;cstdlib>
#include &lt;algorithm>

using namespace std;

map&lt;int, int> timeMap;


string solution(int n, int t, int m, vector&lt;string> timetable) {
    string answer = "";
	int result = 0;
	for (auto &amp;it : timetable) {
		int ch = atoi(it.substr(0, 2).c_str());
		int cm = atoi(it.substr(3, 2).c_str());
		auto it2 = timeMap.find(ch * 100 + cm);
		if (it2 != timeMap.end()) it2->second++;
		else timeMap.insert(make_pair(ch * 100 + cm, 1));
	}

	int nTime = 900;
	auto it = timeMap.begin();

	for (int i = 0; i &lt; n; i++) {
		int tempN = m;
		while (tempN > 0 &amp;&amp; nTime >= it->first) {
			if (it == timeMap.end()) { break; }
			else {
				int ch = it->first / 100;
				int cm = it->first % 100;
				if (cm == 0) {
					cm = 59;
					ch--;
				}
				else cm--;
				result = ch * 100 + cm;

				it->second--;
				tempN--;
				if (it->second == 0) it++;
			}
		}

		if (tempN > 0) result = nTime;

		nTime += t;
		while (nTime % 100 >= 60) {
			nTime -= 60;
			nTime += 100;
		}
	}

	string strH, strM;
	strH = to_string(result / 100);
	if (strH.length() == 1) strH.insert(0, "0");
	strM = to_string(result % 100);
	if (strM.length() == 1) strM.insert(0, "0");

	answer = strH + ":" + strM;

    return answer;
}
</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/03/image-29.png" alt="" class="wp-image-33812" width="440" height="492" srcset="https://lycos7560.com/wp-content/uploads/2023/03/image-29.png 372w, https://lycos7560.com/wp-content/uploads/2023/03/image-29-268x300.png 268w" sizes="(max-width: 440px) 100vw, 440px" /></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-17678-1%ec%b0%a8-%ec%85%94%ed%8b%80%eb%b2%84%ec%8a%a4-2018-kakao-blind-recruitment/33806/">Programmers 17678 [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-17678-1%ec%b0%a8-%ec%85%94%ed%8b%80%eb%b2%84%ec%8a%a4-2018-kakao-blind-recruitment/33806/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
