<?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>tuple Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/tuple/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Tue, 25 Nov 2025 15:17:43 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>tuple Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>C# Switch 식(Expression)</title>
		<link>https://lycos7560.com/c/c-switch-%ec%8b%9dexpression/40362/</link>
					<comments>https://lycos7560.com/c/c-switch-%ec%8b%9dexpression/40362/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Tue, 11 Nov 2025 15:02:40 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[!=]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[.NET 5]]></category>
		<category><![CDATA[.NET 6]]></category>
		<category><![CDATA[.Net Core]]></category>
		<category><![CDATA[>=]]></category>
		<category><![CDATA[<=]]></category>
		<category><![CDATA[==]]></category>
		<category><![CDATA[2019]]></category>
		<category><![CDATA[2020]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[Admin]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Arrow Operator]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Authorization]]></category>
		<category><![CDATA[Boolean]]></category>
		<category><![CDATA[Branch]]></category>
		<category><![CDATA[Branching]]></category>
		<category><![CDATA[C#7]]></category>
		<category><![CDATA[C#8]]></category>
		<category><![CDATA[C#9]]></category>
		<category><![CDATA[Case]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[Clean Code]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Comparison]]></category>
		<category><![CDATA[Compile]]></category>
		<category><![CDATA[Concise]]></category>
		<category><![CDATA[Condition]]></category>
		<category><![CDATA[Conditional]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Control Flow]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Declarative]]></category>
		<category><![CDATA[Declarative Style]]></category>
		<category><![CDATA[Default]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[Developer]]></category>
		<category><![CDATA[Developer Guide]]></category>
		<category><![CDATA[Docs]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[Error Handling]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[Execution]]></category>
		<category><![CDATA[Expression]]></category>
		<category><![CDATA[Expression Body]]></category>
		<category><![CDATA[Expression Tree]]></category>
		<category><![CDATA[False]]></category>
		<category><![CDATA[Feature]]></category>
		<category><![CDATA[Flow]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Function Pointer]]></category>
		<category><![CDATA[Functional]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Grammar]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[History]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Imperative]]></category>
		<category><![CDATA[Intuitive]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Language Evolution]]></category>
		<category><![CDATA[Language Feature]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Logical Pattern]]></category>
		<category><![CDATA[Maintainable]]></category>
		<category><![CDATA[Mapping]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Migration]]></category>
		<category><![CDATA[Modern C#]]></category>
		<category><![CDATA[Modern Programming]]></category>
		<category><![CDATA[New Feature]]></category>
		<category><![CDATA[November]]></category>
		<category><![CDATA[Null]]></category>
		<category><![CDATA[Null Check]]></category>
		<category><![CDATA[Nullable]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Object-Oriented]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Operator]]></category>
		<category><![CDATA[Pattern Matching]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Property]]></category>
		<category><![CDATA[Property Pattern]]></category>
		<category><![CDATA[Range]]></category>
		<category><![CDATA[Readable]]></category>
		<category><![CDATA[Refactor]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Relational Pattern]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[Return Value]]></category>
		<category><![CDATA[Role]]></category>
		<category><![CDATA[Running]]></category>
		<category><![CDATA[Runtime]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[September]]></category>
		<category><![CDATA[Simplify]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[State]]></category>
		<category><![CDATA[Statement]]></category>
		<category><![CDATA[Stopped]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Switch Action]]></category>
		<category><![CDATA[Switch Branch]]></category>
		<category><![CDATA[Switch Case]]></category>
		<category><![CDATA[Switch Clean]]></category>
		<category><![CDATA[Switch Default]]></category>
		<category><![CDATA[Switch Delegate]]></category>
		<category><![CDATA[Switch Docs]]></category>
		<category><![CDATA[Switch Evolution]]></category>
		<category><![CDATA[Switch Example]]></category>
		<category><![CDATA[Switch Expression]]></category>
		<category><![CDATA[Switch Expression Action]]></category>
		<category><![CDATA[Switch Expression C#]]></category>
		<category><![CDATA[Switch Expression Clean]]></category>
		<category><![CDATA[Switch Expression Default]]></category>
		<category><![CDATA[Switch Expression Delegate]]></category>
		<category><![CDATA[Switch Expression Docs]]></category>
		<category><![CDATA[Switch Expression Education]]></category>
		<category><![CDATA[Switch Expression Evolution]]></category>
		<category><![CDATA[Switch Expression Example]]></category>
		<category><![CDATA[Switch Expression Guide]]></category>
		<category><![CDATA[Switch Expression History]]></category>
		<category><![CDATA[Switch Expression Lambda]]></category>
		<category><![CDATA[Switch Expression Learning]]></category>
		<category><![CDATA[Switch Expression Logical]]></category>
		<category><![CDATA[Switch Expression Migration]]></category>
		<category><![CDATA[Switch Expression Modern]]></category>
		<category><![CDATA[Switch Expression Null]]></category>
		<category><![CDATA[Switch Expression Pattern]]></category>
		<category><![CDATA[Switch Expression Property]]></category>
		<category><![CDATA[Switch Expression Relational]]></category>
		<category><![CDATA[Switch Expression Sample]]></category>
		<category><![CDATA[Switch Expression Simplify]]></category>
		<category><![CDATA[Switch Expression Snippet]]></category>
		<category><![CDATA[Switch Expression Study]]></category>
		<category><![CDATA[Switch Expression Tuple]]></category>
		<category><![CDATA[Switch Expression Tutorial]]></category>
		<category><![CDATA[Switch Expression Upgrade]]></category>
		<category><![CDATA[Switch Expression Version]]></category>
		<category><![CDATA[Switch Expression Wildcard]]></category>
		<category><![CDATA[Switch Feature]]></category>
		<category><![CDATA[Switch Flow]]></category>
		<category><![CDATA[Switch Function]]></category>
		<category><![CDATA[Switch Guide]]></category>
		<category><![CDATA[Switch Keyword]]></category>
		<category><![CDATA[Switch Lambda]]></category>
		<category><![CDATA[Switch Logical]]></category>
		<category><![CDATA[Switch Mapping]]></category>
		<category><![CDATA[Switch Modern]]></category>
		<category><![CDATA[Switch Null]]></category>
		<category><![CDATA[Switch Operator]]></category>
		<category><![CDATA[Switch Pattern]]></category>
		<category><![CDATA[Switch Property]]></category>
		<category><![CDATA[Switch Relational]]></category>
		<category><![CDATA[Switch Simplify]]></category>
		<category><![CDATA[Switch Statement]]></category>
		<category><![CDATA[Switch Syntax]]></category>
		<category><![CDATA[Switch Tuple]]></category>
		<category><![CDATA[Switch Tutorial]]></category>
		<category><![CDATA[Switch Wildcard]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[True]]></category>
		<category><![CDATA[tuple]]></category>
		<category><![CDATA[Tuple Pattern]]></category>
		<category><![CDATA[TUTORIAL]]></category>
		<category><![CDATA[Upgrade]]></category>
		<category><![CDATA[User]]></category>
		<category><![CDATA[Value]]></category>
		<category><![CDATA[Variable]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[Visual studio]]></category>
		<category><![CDATA[VS Code]]></category>
		<category><![CDATA[Wildcard]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40362</guid>

					<description><![CDATA[<p>C# Switch 식(Expression) C# 8.0(2019년 9월)부터 도입된 Switch 식(Switch Expression)은 기존의 switch-case 문을 획기적으로 줄여주는 강력한 기능 람다 표현식(=>)을 쓰는 것처럼 간결하고 직관적인 분기 처리가 가능 기존 방식 (Statement) 새로운 방식 (Expression) 강력한 활용 패턴 C# 9.0(2020년 11월)부터 Switch 식이 단순 매핑이 아니라 패턴 매칭(Pattern Matching)과 결합됨 범위 비교 (Relational Pattern) C# 9.0부터는 when 키워드 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/c/c-switch-%ec%8b%9dexpression/40362/">C# Switch 식(Expression)</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-1bf84b0a      "
					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="#c-switch-식expression" class="uagb-toc-link__trigger">C# Switch 식(Expression)</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#기존-방식-statement" class="uagb-toc-link__trigger">기존 방식 (Statement)</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#새로운-방식-expression" class="uagb-toc-link__trigger">새로운 방식 (Expression)</a></li></ul></li><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="#범위-비교-relational-pattern" class="uagb-toc-link__trigger">범위 비교 (Relational Pattern)</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#여러-변수-동시에-비교-tuple-pattern" class="uagb-toc-link__trigger">여러 변수 동시에 비교 (Tuple Pattern)</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#객체-속성-비교-property-pattern" class="uagb-toc-link__trigger">객체 속성 비교 (Property Pattern)</a></li></ul></li></ul></li><li class="uagb-toc__list"><a href="#리턴값이-없는-메서드action-실행" class="uagb-toc-link__trigger">리턴값이 없는 메서드(Action) 실행</a></ul></ul></ol>					</div>
									</div>
				</div>
			


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



<h2 class="wp-block-heading">C# Switch 식(Expression)</h2>



<p class="wp-block-paragraph">C# 8.0(2019년 9월)부터 도입된 <strong>Switch 식(Switch Expression)</strong>은 기존의 <code><strong>switch-case</strong></code> 문을 획기적으로 줄여주는 강력한 기능</p>



<p class="wp-block-paragraph">람다 표현식(<code>=></code>)을 쓰는 것처럼 간결하고 직관적인 분기 처리가 가능</p>



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



<h3 class="wp-block-heading">기존 방식 (Statement)</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public string GetGrade(int score)
{
    string grade;
    switch (score)
    {
        case 90:
            grade = "A";
            break;
        case 80:
            grade = "B";
            break;
        default:
            grade = "C";
            break;
    }
    return grade;
}</pre>



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



<h3 class="wp-block-heading">새로운 방식 (Expression)</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">public string GetGrade(int score) => score switch
{
    90 => "A",
    80 => "B",
    _  => "C"
};


또는 다른 범위 방식으로 (결과는 다름) 
score switch
{
    >= 90 => "A",
    >= 80 => "B",
    >= 70 => "C",
    _     => "D"
};
</pre>



<ul class="wp-block-list">
<li><strong>위치 이동:</strong> <code>switch</code> 키워드가 변수 <strong>뒤</strong>로 이동 (<code>score switch</code>)</li>



<li><strong>화살표 사용:</strong> <code>case ... :</code> 대신 람다 화살표 <code>=></code>를 사용</li>



<li><strong>Default 처리:</strong> <code>default:</code> 대신 와일드카드 <code>_</code>를 사용</li>



<li><strong>식(Expression):</strong> 그 자체가 &#8216;값&#8217;을 반환하므로 메서드의 리턴값으로 바로 사용할 수 있음</li>
</ul>



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



<h2 class="wp-block-heading">강력한 활용 패턴</h2>



<p class="wp-block-paragraph">C# 9.0(2020년 11월)부터 Switch 식이 단순 매핑이 아니라 <strong>패턴 매칭(Pattern Matching)</strong>과 결합됨</p>



<ul class="wp-block-list">
<li><strong>Switch Expression 자체는 C# 8에서 처음 도입</strong></li>



<li><strong>Pattern Matching 자체는 C# 7부터 지원</strong></li>



<li><strong>Relational Pattern, Logical Pattern 등이 C# 9에서 추가</strong></li>
</ul>



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



<h3 class="wp-block-heading">범위 비교 (Relational Pattern)</h3>



<p class="wp-block-paragraph">C# 9.0부터는 <code>when</code> 키워드 없이도 관계 연산자를 직접 사용</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">int temperature = 28;

string weather = temperature switch
{
    >= 30 => "폭염",
    >= 20 => "쾌적함",
    >= 10 => "쌀쌀함",
    _     => "추움"
};</pre>



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



<h3 class="wp-block-heading">여러 변수 동시에 비교 (Tuple Pattern)</h3>



<p class="wp-block-paragraph">두 개 이상의 상태를 조합해서 분기해야 할 때, <code>if-else</code> 중첩 없이 튜플 패턴으로 깔끔하게 해결</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">string state = "Running";
bool hasError = true;

// (상태, 에러여부)를 한 번에 검사
string message = (state, hasError) switch
{
    ("Running", false) => "정상 작동 중",
    ("Running", true)  => "작동 중이나 오류 발생",
    ("Stopped", _)     => "시스템 중지됨", // _는 true/false 상관없음
    _                  => "알 수 없는 상태"
};</pre>



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



<h3 class="wp-block-heading">객체 속성 비교 (Property Pattern)</h3>



<p class="wp-block-paragraph">객체 내부의 특정 프로퍼티 값에 따라 분기할 수도 있음 </p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">var user = new User { Role = "Admin", IsDeleted = false };

string accessLevel = user switch
{
    { Role: "Admin", IsDeleted: false } => "관리자 권한",
    { Role: "User", IsDeleted: false }  => "일반 사용자",
    { IsDeleted: true }                 => "삭제된 계정",
    _                                   => "접근 불가" // null 포함
};

// 객체가 null인 경우도 자동으로 _</pre>



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



<h2 class="wp-block-heading">리턴값이 없는 메서드(Action) 실행</h2>



<p class="wp-block-paragraph"><code>Action</code> 델리게이트를 반환받아 즉시 실행</p>



<p class="wp-block-paragraph">switch expression은 &#8220;값&#8221;을 반환하므로 델리게이트(함수 포인터)를 반환하는 것도 가능</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">int command = 1;

// 1. 각 조건에 맞는 Action(행동)을 선택하고
// 2. 마지막의 ()로 즉시 실행합니다.
(command switch
{
    1 => (Action)(() => SaveData()),
    2 => () => LoadData(),
    _ => () => Console.WriteLine("대기")
})(); 
// 마지막 ()는 "반환된 델리게이트 실행"</pre>



<p class="wp-block-paragraph"></p>
<p>The post <a href="https://lycos7560.com/c/c-switch-%ec%8b%9dexpression/40362/">C# Switch 식(Expression)</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/c/c-switch-%ec%8b%9dexpression/40362/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 wp-block-paragraph"><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 wp-block-paragraph">라디오를 자주 듣는 네오는 라디오에서 방금 나왔던 음악이 무슨 음악인지 궁금해질 때가 많다. </p>



<p class="has-medium-font-size wp-block-paragraph">그럴 때 네오는 다음 포털의 &#8216;방금그곡&#8217; 서비스를 이용하곤 한다. </p>



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



<p class="has-medium-font-size wp-block-paragraph">네오는 자신이 기억한 멜로디를 가지고 방금그곡을 이용해 음악을 찾는다. </p>



<p class="has-medium-font-size wp-block-paragraph">그런데 라디오 방송에서는 한 음악을 반복해서 재생할 때도 있어서 네오가 기억하고 있는 멜로디는 </p>



<p class="has-medium-font-size wp-block-paragraph">음악 끝부분과 처음 부분이 이어서 재생된 멜로디일 수도 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">반대로, 한 음악을 중간에 끊을 경우 원본 음악에는 네오가 기억한 멜로디가 들어있다 해도 그 곡이 네오가 들은 곡이 아닐 수도 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">그렇기 때문에 네오는 기억한 멜로디를 재생 시간과 제공된 악보를 직접 보면서 비교하려고 한다. </p>



<p class="has-medium-font-size wp-block-paragraph">다음과 같은 가정을 할 때 네오가 찾으려는 음악의 제목을 구하여라.</p>



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



<p class="has-medium-font-size wp-block-paragraph">방금그곡 서비스에서는 음악 제목, 재생이 시작되고 끝난 시각, 악보를 제공한다.</p>



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



<p class="has-medium-font-size wp-block-paragraph">네오가 기억한 멜로디와 악보에 사용되는 음은 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 wp-block-paragraph">각 음은 1분에 1개씩 재생된다. 음악은 반드시 처음부터 재생되며 음악 길이보다 재생된 시간이 길 때는 <br>음악이 끊김 없이 처음부터 반복해서 재생된다. 음악 길이보다 재생된 시간이 짧을 때는 처음부터 재생 시간만큼만 재생된다.</p>



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



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



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



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



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



<p class="has-medium-font-size wp-block-paragraph">조건이 일치하는 음악이 없을 때에는 “(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 wp-block-paragraph">입력으로 네오가 기억한 멜로디를 담은 문자열&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 wp-block-paragraph">조건과 일치하는 음악 제목을 출력한다.</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 class="wp-block-paragraph">첫 번째 예시에서 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 fetchpriority="high" 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>백준 16236번 (아기 상어, C++, Simulation) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 28 Jan 2023 11:23:16 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[16236]]></category>
		<category><![CDATA[16236번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[tuple]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 16236]]></category>
		<category><![CDATA[백준 16236번]]></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=5687</guid>

					<description><![CDATA[<p>백준 16236번 '아기 상어' 문제에 대한 글입니다. 'BFS 탐색'을 이용하여 해결하였습니다. (This is Baekjun 16236 about the 'Baby Shark' problem. Resolved using 'BFS Search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/">백준 16236번 (아기 상어, C++, Simulation) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



<h1 class="wp-block-heading">아기 상어</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">52413</td><td class="has-text-align-left" data-align="left">23961</td><td class="has-text-align-left" data-align="left">14308</td><td class="has-text-align-left" data-align="left">42.311%</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 wp-block-paragraph">N×N 크기의 공간에 물고기 M마리와 아기 상어 1마리가 있다. </p>



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



<p class="has-medium-font-size wp-block-paragraph">한 칸에는 물고기가 최대 1마리 존재한다.</p>



<p class="has-medium-font-size wp-block-paragraph">아기 상어와 물고기는 모두 크기를 가지고 있고, 이 크기는 자연수이다. </p>



<p class="has-medium-font-size wp-block-paragraph">가장 처음에 아기 상어의 크기는 2이고, 아기 상어는 1초에 상하좌우로 인접한 한 칸씩 이동한다.</p>



<p class="has-medium-font-size wp-block-paragraph">아기 상어는 자신의 크기보다 큰 물고기가 있는 칸은 지나갈 수 없고, 나머지 칸은 모두 지나갈 수 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">아기 상어는 자신의 크기보다 작은 물고기만 먹을 수 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">따라서, 크기가 같은 물고기는 먹을 수 없지만, 그 물고기가 있는 칸은 지나갈 수 있다.</p>



<p class="has-medium-font-size wp-block-paragraph">아기 상어가 어디로 이동할지 결정하는 방법은 아래와 같다.</p>



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



<p class="has-medium-font-size wp-block-paragraph"><strong>더 이상 먹을 수 있는 물고기가 공간에 없다면 아기 상어는 엄마 상어에게 도움을 요청한다.</strong></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>먹을 수 있는 물고기가 1마리라면, 그 물고기를 먹으러 간다.</strong></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>먹을 수 있는 물고기가 1마리보다 많다면, 거리가 가장 가까운 물고기를 먹으러 간다.</strong></p>



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



<p class="has-medium-font-size wp-block-paragraph"><strong>&#8211; 거리는 아기 상어가 있는 칸에서 물고기가 있는 칸으로 이동할 때, 지나야하는 칸의 개수의 최솟값이다.</strong></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>&#8211; 거리가 가까운 물고기가 많다면, 가장&nbsp;위에 있는 물고기, 그러한 물고기가 여러마리라면, 가장 왼쪽에 있는 물고기를 먹는다.</strong></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>&#8211; 아기 상어의 이동은 1초 걸리고, 물고기를 먹는데 걸리는 시간은 없다고 가정한다. </strong></p>



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



<p class="has-medium-font-size wp-block-paragraph">즉, 아기 상어가 먹을 수 있는 물고기가 있는 칸으로 이동했다면, 이동과 동시에 물고기를 먹는다. 물고기를 먹으면, 그 칸은 빈 칸이 된다.</p>



<p class="has-medium-font-size wp-block-paragraph">아기 상어는 자신의 크기와 같은 수의 물고기를 먹을 때 마다 크기가 1 증가한다. 예를 들어, 크기가 2인 아기 상어는 물고기를 2마리 먹으면 크기가 3이 된다.</p>



<p class="has-medium-font-size wp-block-paragraph">공간의 상태가 주어졌을 때, 아기 상어가 몇 초 동안 엄마 상어에게 도움을 요청하지 않고 물고기를 잡아먹을 수&nbsp;있는지 구하는 프로그램을 작성하시오.</p>



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



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



<p class="has-medium-font-size wp-block-paragraph">첫째 줄에 공간의 크기 N(2&nbsp;≤ N ≤ 20)이 주어진다.</p>



<p class="has-medium-font-size wp-block-paragraph">둘째 줄부터 N개의 줄에 공간의 상태가 주어진다. </p>



<p class="has-medium-font-size wp-block-paragraph">공간의 상태는 0, 1, 2, 3, 4, 5, 6, 9로 이루어져 있고, 아래와 같은 의미를 가진다.</p>



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



<p class="has-medium-font-size wp-block-paragraph"><strong>0: 빈 칸</strong></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>1, 2, 3, 4, 5, 6: 칸에 있는 물고기의 크기</strong></p>



<p class="has-medium-font-size wp-block-paragraph"><strong>9: 아기 상어의 위치</strong></p>



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



<p class="has-medium-font-size wp-block-paragraph">아기 상어는 공간에 한 마리 있다.</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 wp-block-paragraph">첫째 줄에 아기 상어가 엄마 상어에게 도움을 요청하지 않고 물고기를 잡아먹을 수 있는 시간을 출력한다.</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 9 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="">0</pre>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">3
0 0 1
0 0 0
0 9 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:60px" aria-hidden="true" class="wp-block-spacer"></div>



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



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



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



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



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



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



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



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



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



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



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



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



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



<ul class="wp-block-list">
<li><a href="https://www.acmicpc.net/problem/tag/102" target="_blank" rel="noreferrer noopener">구현</a></li>



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



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



<li><a href="https://www.acmicpc.net/problem/tag/126" target="_blank" rel="noreferrer noopener">너비 우선 탐색</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/141" target="_blank" rel="noreferrer noopener">시뮬레이션</a></li>
</ul>



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



<p class="has-medium-font-size wp-block-paragraph">문제의 조건을 이해 못해서 해결하는데 엄청 시간이 걸렸다.</p>



<p class="has-medium-font-size wp-block-paragraph">특히 맵에 먹을 수 있는 물고기가 여러 마리 일때 조건에서 막혔는데</p>



<p class="has-medium-font-size wp-block-paragraph">예제와 글을 계속 읽어보면서 겨우 이해했다.</p>



<p class="has-medium-font-size wp-block-paragraph">결론은 <strong>거리가 가장 가까운 물고기들 중에서  가장 위쪽에 있으면서 좌측에 있는 물고기를 픽</strong>하는 것</p>



<p class="has-medium-font-size wp-block-paragraph">이 문제의 설명이 너무 잘되어있는 글이 있어서 첨부한다.</p>



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



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/board/view/100687" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/view/100687</a></p>



<figure class="wp-block-image size-full"><img decoding="async" width="1599" height="962" src="https://lycos7560.com/wp-content/uploads/2023/01/image-32.png" alt="" class="wp-image-5689" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-32.png 1599w, https://lycos7560.com/wp-content/uploads/2023/01/image-32-300x180.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-32-768x462.png 768w, https://lycos7560.com/wp-content/uploads/2023/01/image-32-1536x924.png 1536w" sizes="(max-width: 1599px) 100vw, 1599px" /></figure>



<p class="wp-block-paragraph"> </p>



<figure class="wp-block-image size-full"><img decoding="async" width="1643" height="1140" src="https://lycos7560.com/wp-content/uploads/2023/01/image-33.png" alt="" class="wp-image-5690" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-33.png 1643w, https://lycos7560.com/wp-content/uploads/2023/01/image-33-300x208.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-33-768x533.png 768w, https://lycos7560.com/wp-content/uploads/2023/01/image-33-1536x1066.png 1536w" sizes="(max-width: 1643px) 100vw, 1643px" /></figure>



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



<p class="has-medium-font-size wp-block-paragraph">위의 설명을 구현하기 위해서</p>



<p class="has-medium-font-size wp-block-paragraph">1. 상어의 위치에서 BFS 탐색을 통하여 상어가 먹을 수 있는 가장 가까운 물고기의 위치를 저장한다. </p>



<p class="has-medium-font-size wp-block-paragraph">(탐색의 방향은 <strong>상/좌/우/하</strong>)</p>



<p class="has-medium-font-size wp-block-paragraph">2.  상어가 먹을 수 있는 물고기의 위치에서 <strong>가장 위쪽에 있으면서 좌측에 있는 물고기</strong>를 선택한다.</p>



<p class="has-medium-font-size wp-block-paragraph">3. 해당 물고기의 위치로 상어를 옮기고 물고기를 제거하며 상어의 크기를 업데이트 해준다.</p>



<p class="has-medium-font-size wp-block-paragraph">4. 해당 위치까지 얼마나 걸렸는지 카운트 해준다.</p>



<p class="has-medium-font-size wp-block-paragraph">5. <strong>상어가 먹을 수 있는 물고기가 없을 때까지</strong> 1 &#8211; 4 를 반복한다.</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)"/>



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



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



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

using namespace std;

// 최대 범위 
constexpr int MAX = 20;

// 상/좌/우/하
int dxdy[4][2] = { {-1, 0}, {0, -1}, {0, 1}, {1, 0} };

pair&lt;int, int> Shark; // 상어 크기, 경험치?

tuple&lt;int, int, int> posShark; // 상어의 x, y위치 / 시간

tuple&lt;int, int, int> tempT;

int N, dx, dy;

int map[MAX][MAX]; // 맵

bool eatMap[MAX][MAX]; // 먹을 수 있는 물고기 체크

bool mapCheck[MAX][MAX]; // BFS 방문 체크에 사용

// BFS 탐색, 반환값음 상어의 위치와 시간
tuple&lt;int, int, int> SharkBFS()
{
    queue&lt;tuple&lt;int, int, int>> myQ;

    // 방문처리 초기화
    fill(&amp;mapCheck[0][0], &amp;mapCheck[N - 1][N], false);
    fill(&amp;eatMap[0][0], &amp;eatMap[N - 1][N], false);

    myQ.push(posShark);
    mapCheck[get&lt;0>(posShark)][get&lt;1>(posShark)] = true;

    int dis = 99999;
    while (!myQ.empty()) {
        tempT = myQ.front();
        myQ.pop();

        // 상/하/좌/우를 탐색하기 위한 반복문
        for (int i = 0; i &lt; 4; i++) {
            dx = get&lt;0>(tempT) + dxdy[i][0];
            dy = get&lt;1>(tempT) + dxdy[i][1];

            // 문제의 범위를 벗어나는 경우 => 넘어간다.
            if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= N) continue;
            // 이미 방문한 곳 일 경우와 해당 칸의 물고기가 상어보다 클 경우 => 넘어간다.
            if (mapCheck[dx][dy] == true || map[dx][dy] > Shark.first) continue;

            // 상어가 더 크고, 빈 공간이 아니라면 
            if (map[dx][dy] &lt; Shark.first &amp;&amp; map[dx][dy] != 0 ) {

                if (get&lt;2>(tempT) + 1 &lt;= dis) {
                    eatMap[dx][dy] = true;
                    dis = get&lt;2>(tempT) + 1;
                }
            }

            mapCheck[dx][dy] = true; // 방문처리
            myQ.push(make_tuple(dx, dy, get&lt;2>(tempT) + 1)); // 탐색 Q에 넣기
        }
    }

    // 먹을 수 있는 물고기들 중에서 
    // 가장 위, 좌측에 있는 물고기를 선택한다.
    for (int i = 0; i &lt; N; i++) {
        for (int j = 0; j &lt; N; j++) {
            if (eatMap[i][j] == true) {
                Shark.second++;
                map[i][j] = 0;
                if (Shark.first == Shark.second) {
                    Shark.first++;
                    Shark.second = 0;
                }

                return make_tuple(i, j, dis);
            }
        }
    }
    
    // 없다면 기존 상어의 위치를 반환한다.
    return posShark;
}


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

    Shark = make_pair(2, 0);

    cin >> N;
    for (int i = 0; i &lt; N; i++) {
        for (int j = 0; j &lt; N; j++) {
            cin >> map[i][j];
            if (map[i][j] == 9) { // 상어의 위치를 저장
                posShark = make_tuple(i, j, 0);
                map[i][j] = 0;
            }
        }
    }

    bool check = true;
    while (check) {
        check = false;
        for (int i = 0; i &lt; N &amp;&amp; !check; i++) {
            for (int j = 0; j &lt; N &amp;&amp; !check; i++) {
                if (map[i][j] >= 1) check = true;
            }
        }

        tempT = SharkBFS();
        
        // BFS 탐색 후에도 상어의 움직임이 없다면 먹을 수 있는 물고기가 없다.
        if (get&lt;2>(tempT) == get&lt;2>(posShark)) break;
        else posShark = tempT;
  
    }

    cout &lt;&lt; get&lt;2>(posShark);

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1250" height="114" src="https://lycos7560.com/wp-content/uploads/2023/01/image-31.png" alt="" class="wp-image-5688" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-31.png 1250w, https://lycos7560.com/wp-content/uploads/2023/01/image-31-300x27.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-31-768x70.png 768w" sizes="(max-width: 1250px) 100vw, 1250px" /></figure>



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



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



<p class="has-medium-font-size wp-block-paragraph"><strong>디버깅</strong> </p>



<p class="has-small-font-size wp-block-paragraph"><a href="https://www.acmicpc.net/board/view/100687" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/board/view/100687</a></p>



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



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



<p class="has-medium-font-size wp-block-paragraph">여기서부터는 시뮬레이션이 매우 길기 때문에 디버깅 출력으로 대신하겠습니다.</p>



<p class="has-medium-font-size wp-block-paragraph">또한, 가독성을 위해 상어의 위치는 9 대신 &#8220;■&#8221;, 물고기가 없는 위치는 0 대신 &#8220;.&#8221; 로 표기했습니다.</p>



<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 4 3 2 3 4
4 3 2 3 4 5
3 2 ■ 5 6 6
2 1 2 3 4 5
3 2 1 6 5 4
6 6 6 6 6 6
0s / Lv. 2 (Exp 0 / 2)


5 4 3 2 3 4 
4 3 2 3 4 5 
3 2 . 5 6 6 
2 ■ 2 3 4 5 
3 2 1 6 5 4 
6 6 6 6 6 6 
2s / Lv. 2 (Exp 1 / 2)


5 4 3 2 3 4 
4 3 2 3 4 5 
3 2 . 5 6 6 
2 . 2 3 4 5 
3 2 ■ 6 5 4 
6 6 6 6 6 6 
4s / Lv. 3 (Exp 0 / 3)


5 4 3 2 3 4 
4 3 2 3 4 5 
3 2 . 5 6 6 
2 . ■ 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
5s / Lv. 3 (Exp 1 / 3)


5 4 3 2 3 4 
4 3 ■ 3 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
7s / Lv. 3 (Exp 2 / 3)


5 4 3 ■ 3 4 
4 3 . 3 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
9s / Lv. 4 (Exp 0 / 4)


5 4 ■ . 3 4 
4 3 . 3 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
10s / Lv. 4 (Exp 1 / 4)


5 4 . . ■ 4 
4 3 . 3 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
12s / Lv. 4 (Exp 2 / 4)


5 4 . . . 4 
4 3 . ■ 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
14s / Lv. 4 (Exp 3 / 4)


5 4 . . . 4 
4 ■ . . 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
16s / Lv. 5 (Exp 0 / 5)


5 ■ . . . 4 
4 . . . 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
17s / Lv. 5 (Exp 1 / 5)


5 . . . . 4 
■ . . . 4 5 
3 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
19s / Lv. 5 (Exp 2 / 5)


5 . . . . 4 
. . . . 4 5 
■ 2 . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
20s / Lv. 5 (Exp 3 / 5)


5 . . . . 4 
. . . . 4 5 
. ■ . 5 6 6 
2 . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
21s / Lv. 5 (Exp 4 / 5)


5 . . . . 4 
. . . . 4 5 
. . . 5 6 6 
■ . . 3 4 5 
3 2 . 6 5 4 
6 6 6 6 6 6 
23s / Lv. 6 (Exp 0 / 6)


5 . . . . 4 
. . . . 4 5 
. . . 5 6 6 
. . . 3 4 5 
■ 2 . 6 5 4 
6 6 6 6 6 6 
24s / Lv. 6 (Exp 1 / 6)


5 . . . . 4 
. . . . 4 5 
. . . 5 6 6 
. . . 3 4 5 
. ■ . 6 5 4 
6 6 6 6 6 6 
25s / Lv. 6 (Exp 2 / 6)


5 . . . . 4 
. . . . 4 5 
. . . 5 6 6 
. . . ■ 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
28s / Lv. 6 (Exp 3 / 6)


5 . . . . 4 
. . . . 4 5 
. . . ■ 6 6 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
29s / Lv. 6 (Exp 4 / 6)


5 . . . . 4 
. . . . ■ 5 
. . . . 6 6 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
31s / Lv. 6 (Exp 5 / 6)


5 . . . . 4 
. . . . . ■ 
. . . . 6 6 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
32s / Lv. 7 (Exp 0 / 7)


5 . . . . ■ 
. . . . . . 
. . . . 6 6 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
33s / Lv. 7 (Exp 1 / 7)


5 . . . . . 
. . . . . . 
. . . . 6 ■ 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
35s / Lv. 7 (Exp 2 / 7)


5 . . . . . 
. . . . . . 
. . . . ■ . 
. . . . 4 5 
. . . 6 5 4 
6 6 6 6 6 6 
36s / Lv. 7 (Exp 3 / 7)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . ■ 5 
. . . 6 5 4 
6 6 6 6 6 6 
37s / Lv. 7 (Exp 4 / 7)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . ■ 
. . . 6 5 4 
6 6 6 6 6 6 
38s / Lv. 7 (Exp 5 / 7)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . 6 5 ■ 
6 6 6 6 6 6 
39s / Lv. 7 (Exp 6 / 7)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . 6 ■ . 
6 6 6 6 6 6 
40s / Lv. 8 (Exp 0 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . ■ . . 
6 6 6 6 6 6 
41s / Lv. 8 (Exp 1 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
6 6 6 ■ 6 6 
42s / Lv. 8 (Exp 2 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
6 6 ■ . 6 6 
43s / Lv. 8 (Exp 3 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
6 ■ . . 6 6 
44s / Lv. 8 (Exp 4 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
■ . . . 6 6 
45s / Lv. 8 (Exp 5 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . ■ 6 
49s / Lv. 8 (Exp 6 / 8)


5 . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . ■ 
50s / Lv. 8 (Exp 7 / 8)


■ . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
60s / Lv. 9 (Exp 0 / 9)</pre>



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



<p class="has-medium-font-size wp-block-paragraph">따라서 답은 60초입니다.</p>



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



<h3 class="wp-block-heading">예제 입력 5</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 . 6 . 6 1
. . . . . 2
2 3 4 5 6 6
. . . . . 2
. 2 . . . .
3 ■ 3 . . 1
0s / Lv. 2 (Exp 0 / 2)


6 . 6 . 6 1 
. . . . . 2 
2 3 4 5 6 6 
. . . . . 2 
. 2 . . . . 
3 . 3 . . ■ 
6s / Lv. 2 (Exp 1 / 2)


6 . 6 . 6 ■ 
. . . . . 2 
2 3 4 5 6 6 
. . . . . 2 
. 2 . . . . 
3 . 3 . . . 
21s / Lv. 3 (Exp 0 / 3)


6 . 6 . 6 . 
. . . . . ■ 
2 3 4 5 6 6 
. . . . . 2 
. 2 . . . . 
3 . 3 . . . 
22s / Lv. 3 (Exp 1 / 3)


6 . 6 . 6 . 
. . . . . . 
■ 3 4 5 6 6 
. . . . . 2 
. 2 . . . . 
3 . 3 . . . 
28s / Lv. 3 (Exp 2 / 3)


6 . 6 . 6 . 
. . . . . . 
. 3 4 5 6 6 
. . . . . 2 
. ■ . . . . 
3 . 3 . . . 
31s / Lv. 4 (Exp 0 / 4)


6 . 6 . 6 . 
. . . . . . 
. ■ 4 5 6 6 
. . . . . 2 
. . . . . . 
3 . 3 . . . 
33s / Lv. 4 (Exp 1 / 4)


6 . 6 . 6 . 
. . . . . . 
. . 4 5 6 6 
. . . . . 2 
. . . . . . 
■ . 3 . . . 
37s / Lv. 4 (Exp 2 / 4)


6 . 6 . 6 . 
. . . . . . 
. . 4 5 6 6 
. . . . . 2 
. . . . . . 
. . ■ . . . 
39s / Lv. 4 (Exp 3 / 4)


6 . 6 . 6 . 
. . . . . . 
. . 4 5 6 6 
. . . . . ■ 
. . . . . . 
. . . . . . 
44s / Lv. 5 (Exp 0 / 5)


6 . 6 . 6 . 
. . . . . . 
. . ■ 5 6 6 
. . . . . . 
. . . . . . 
. . . . . . 
48s / Lv. 5 (Exp 1 / 5)</pre>



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



<p class="has-medium-font-size wp-block-paragraph">따라서 답은 48초입니다.</p>



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



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



<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="">1 1 1 1 1 1 
2 2 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . ■ 
0s / Lv. 2 (Exp 0 / 2)


1 ■ 1 1 1 1 
2 2 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
9s / Lv. 2 (Exp 1 / 2)


■ . 1 1 1 1 
2 2 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
10s / Lv. 3 (Exp 0 / 3)


. . 1 1 1 1 
■ 2 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
11s / Lv. 3 (Exp 1 / 3)


. . 1 1 1 1 
. ■ 6 2 2 3 
2 2 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
12s / Lv. 3 (Exp 2 / 3)


. . 1 1 1 1 
. . 6 2 2 3 
2 ■ 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
13s / Lv. 4 (Exp 0 / 4)


. . 1 1 1 1 
. . 6 2 2 3 
■ . 5 2 2 3 
2 2 2 4 6 3 
. . . . . 6 
. . . . . . 
14s / Lv. 4 (Exp 1 / 4)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 2 2 3 
■ 2 2 4 6 3 
. . . . . 6 
. . . . . . 
15s / Lv. 4 (Exp 2 / 4)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 2 2 3 
. ■ 2 4 6 3 
. . . . . 6 
. . . . . . 
16s / Lv. 4 (Exp 3 / 4)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 2 2 3 
. . ■ 4 6 3 
. . . . . 6 
. . . . . . 
17s / Lv. 5 (Exp 0 / 5)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 2 2 3 
. . . ■ 6 3 
. . . . . 6 
. . . . . . 
18s / Lv. 5 (Exp 1 / 5)


. . 1 1 1 1 
. . 6 2 2 3 
. . 5 ■ 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
19s / Lv. 5 (Exp 2 / 5)


. . 1 1 1 1 
. . 6 ■ 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
20s / Lv. 5 (Exp 3 / 5)


. . 1 ■ 1 1 
. . 6 . 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
21s / Lv. 5 (Exp 4 / 5)


. . ■ . 1 1 
. . 6 . 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
22s / Lv. 6 (Exp 0 / 6)


. . . . ■ 1 
. . 6 . 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
24s / Lv. 6 (Exp 1 / 6)


. . . . . ■ 
. . 6 . 2 3 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
25s / Lv. 6 (Exp 2 / 6)


. . . . . . 
. . 6 . 2 ■ 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
26s / Lv. 6 (Exp 3 / 6)


. . . . . . 
. . 6 . ■ . 
. . 5 . 2 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
27s / Lv. 6 (Exp 4 / 6)


. . . . . . 
. . 6 . . . 
. . 5 . ■ 3 
. . . . 6 3 
. . . . . 6 
. . . . . . 
28s / Lv. 6 (Exp 5 / 6)


. . . . . . 
. . 6 . . . 
. . 5 . . ■ 
. . . . 6 3 
. . . . . 6 
. . . . . . 
29s / Lv. 7 (Exp 0 / 7)


. . . . . . 
. . 6 . . . 
. . 5 . . . 
. . . . 6 ■ 
. . . . . 6 
. . . . . . 
30s / Lv. 7 (Exp 1 / 7)


. . . . . . 
. . 6 . . . 
. . 5 . . . 
. . . . ■ . 
. . . . . 6 
. . . . . . 
31s / Lv. 7 (Exp 2 / 7)


. . . . . . 
. . 6 . . . 
. . 5 . . . 
. . . . . . 
. . . . . ■ 
. . . . . . 
33s / Lv. 7 (Exp 3 / 7)


. . . . . . 
. . 6 . . . 
. . ■ . . . 
. . . . . . 
. . . . . . 
. . . . . . 
38s / Lv. 7 (Exp 4 / 7)


. . . . . . 
. . ■ . . . 
. . . . . . 
. . . . . . 
. . . . . . 
. . . . . . 
39s / Lv. 7 (Exp 5 / 7)</pre>



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



<p class="has-medium-font-size wp-block-paragraph">따라서 답은 39초입니다.</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-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/">백준 16236번 (아기 상어, C++, Simulation) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-16236%eb%b2%88-%ec%95%84%ea%b8%b0-%ec%83%81%ec%96%b4-c-simulation-baekjoon/5687/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 7569번 (토마토, C++, BFS) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 27 Jan 2023 12:18:40 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[3차원]]></category>
		<category><![CDATA[7569]]></category>
		<category><![CDATA[7569번]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cin]]></category>
		<category><![CDATA[cin.tie(NULL)]]></category>
		<category><![CDATA[cout]]></category>
		<category><![CDATA[cout.tie(NULL)]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false)]]></category>
		<category><![CDATA[ios_base::sync_with_stdio(false);]]></category>
		<category><![CDATA[Queue]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[tuple]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[배열]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 7569]]></category>
		<category><![CDATA[백준 7569번]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[토마토]]></category>
		<category><![CDATA[튜플]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5667</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 7569번 '토마토' 문제에 대한 글입니다. 'BFS Search' 을 사용하여 해결하였습니다. (This is an article about the 'Tomato' problem in BAEKJOON 7569. Resolved using 'BFS Search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/">백준 7569번 (토마토, C++, BFS) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



<h1 class="wp-block-heading">토마토</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">1 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">63015</td><td class="has-text-align-left" data-align="left">25996</td><td class="has-text-align-left" data-align="left">19053</td><td class="has-text-align-left" data-align="left">41.355%</td></tr></tbody></table></figure>



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



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



<p class="has-medium-font-size wp-block-paragraph">철수의 토마토 농장에서는 토마토를 보관하는 큰 창고를 가지고 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">토마토는 아래의 그림과 같이 격자모양 상자의 칸에 하나씩 넣은 다음, 상자들을 수직으로 쌓아 올려서 창고에 보관한다.</p>



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



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



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



<p class="has-medium-font-size wp-block-paragraph">창고에 보관되는 토마토들 중에는 잘 익은 것도 있지만, 아직 익지 않은 토마토들도 있을 수 있다. </p>



<p class="has-medium-font-size wp-block-paragraph">보관 후 하루가 지나면, 익은 토마토들의 인접한 곳에 있는 익지 않은 토마토들은 익은 토마토의 영향을 받아 익게 된다. </p>



<p class="has-medium-font-size wp-block-paragraph">하나의 토마토에 인접한 곳은 위, 아래, 왼쪽, 오른쪽, 앞, 뒤 여섯 방향에 있는 토마토를 의미한다. </p>



<p class="has-medium-font-size wp-block-paragraph">대각선 방향에 있는 토마토들에게는 영향을 주지 못하며, 토마토가 혼자 저절로 익는 경우는 없다고 가정한다. </p>



<p class="has-medium-font-size wp-block-paragraph">철수는 창고에 보관된 토마토들이 며칠이 지나면 다 익게 되는지 그 최소 일수를 알고 싶어 한다.</p>



<p class="has-medium-font-size wp-block-paragraph">토마토를 창고에 보관하는 격자모양의 상자들의 크기와 익은 토마토들과 익지 않은 토마토들의 정보가 주어졌을 때, </p>



<p class="has-medium-font-size wp-block-paragraph">며칠이 지나면 토마토들이 모두 익는지, 그 최소 일수를 구하는 프로그램을 작성하라. </p>



<p class="has-medium-font-size wp-block-paragraph">단, 상자의 일부 칸에는 토마토가 들어있지 않을 수도 있다.</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 wp-block-paragraph">첫 줄에는 상자의 크기를 나타내는 두 정수 M,N과 쌓아올려지는 상자의 수를 나타내는 H가 주어진다. </p>



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



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



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



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



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



<p class="has-medium-font-size wp-block-paragraph">이러한 N개의 줄이 H번 반복하여 주어진다.</p>



<p class="has-medium-font-size wp-block-paragraph">토마토가 하나 이상 있는 경우만 입력으로 주어진다.</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 wp-block-paragraph">여러분은 토마토가 모두 익을 때까지 최소 며칠이 걸리는지를 계산해서 출력해야 한다. </p>



<p class="has-medium-font-size wp-block-paragraph">만약, 저장될 때부터 모든 토마토가 익어있는 상태이면 0을 출력해야 하고, </p>



<p class="has-medium-font-size wp-block-paragraph">토마토가 모두 익지는 못하는 상황이면 -1을 출력해야 한다.</p>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<p class="wp-block-paragraph"><a href="https://www.acmicpc.net/category/2" target="_blank" rel="noreferrer noopener">Olympiad</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/55" target="_blank" rel="noreferrer noopener">한국정보올림피아드</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/57" target="_blank" rel="noreferrer noopener">한국정보올림피아드시․도지역본선</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/214" target="_blank" rel="noreferrer noopener">지역본선 2013</a>&nbsp;&gt;&nbsp;<a href="https://www.acmicpc.net/category/detail/912" target="_blank" rel="noreferrer noopener">초등부</a>&nbsp;3번</p>



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



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



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



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



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/126" target="_blank" rel="noreferrer noopener">너비 우선 탐색</a></li>
</ul>



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



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



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



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



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



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



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



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

using namespace std;

constexpr int MAX = 100;

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

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

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

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

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

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

bool falseCheck = true;

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

    cin >> M >> N >> H;


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

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


    while (!myQueue.empty()) {

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


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

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

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

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

    return 0;
}</pre>



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



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



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



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-5698326622209671" data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/">백준 7569번 (토마토, C++, BFS) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-7569%eb%b2%88-%ed%86%a0%eb%a7%88%ed%86%a0-c-bfs-baekjoon/5667/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
