<?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>브루트 포스 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/tag/%EB%B8%8C%EB%A3%A8%ED%8A%B8-%ED%8F%AC%EC%8A%A4/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Wed, 06 Aug 2025 09:52:23 +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>브루트 포스 Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>ASP.NET Core IdentityOptions 기본 예제</title>
		<link>https://lycos7560.com/c/asp-net/asp-net-core-identityoptions-%ec%a0%95%eb%a6%ac/40232/</link>
					<comments>https://lycos7560.com/c/asp-net/asp-net-core-identityoptions-%ec%a0%95%eb%a6%ac/40232/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 06 Aug 2025 09:44:34 +0000</pubDate>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[2FA]]></category>
		<category><![CDATA[2단계 인증]]></category>
		<category><![CDATA[Admin]]></category>
		<category><![CDATA[appsettings.json]]></category>
		<category><![CDATA[ASP.NET Core]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Authorization]]></category>
		<category><![CDATA[BCrypt]]></category>
		<category><![CDATA[Bearer Token]]></category>
		<category><![CDATA[Claim]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[DI]]></category>
		<category><![CDATA[EF Core]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[GDPR]]></category>
		<category><![CDATA[Guest]]></category>
		<category><![CDATA[Identity]]></category>
		<category><![CDATA[IdentityOptions]]></category>
		<category><![CDATA[ILogger]]></category>
		<category><![CDATA[IP 차단]]></category>
		<category><![CDATA[IPasswordValidator]]></category>
		<category><![CDATA[IUserValidator]]></category>
		<category><![CDATA[JWT]]></category>
		<category><![CDATA[Lockout]]></category>
		<category><![CDATA[MFA]]></category>
		<category><![CDATA[Middleware]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[PasswordOptions]]></category>
		<category><![CDATA[Policy]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Recovery Code]]></category>
		<category><![CDATA[Role]]></category>
		<category><![CDATA[Salt]]></category>
		<category><![CDATA[Seed Data]]></category>
		<category><![CDATA[SignIn]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[Stores]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[Token]]></category>
		<category><![CDATA[User]]></category>
		<category><![CDATA[감사]]></category>
		<category><![CDATA[개인정보 보호]]></category>
		<category><![CDATA[개인정보처리방침]]></category>
		<category><![CDATA[계정 보안]]></category>
		<category><![CDATA[계정 잠금]]></category>
		<category><![CDATA[계정 활성화]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[관리자]]></category>
		<category><![CDATA[권한 부여]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다단계 인증]]></category>
		<category><![CDATA[데이터 보호]]></category>
		<category><![CDATA[데이터베이스]]></category>
		<category><![CDATA[레이트 리미팅]]></category>
		<category><![CDATA[로그인]]></category>
		<category><![CDATA[로깅]]></category>
		<category><![CDATA[마이그레이션]]></category>
		<category><![CDATA[모니터링]]></category>
		<category><![CDATA[미들웨어]]></category>
		<category><![CDATA[보안]]></category>
		<category><![CDATA[보안 이벤트]]></category>
		<category><![CDATA[보안 질문]]></category>
		<category><![CDATA[보안 토큰]]></category>
		<category><![CDATA[복구 코드]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[비밀번호 재설정]]></category>
		<category><![CDATA[사용자 검증]]></category>
		<category><![CDATA[사용자 관리]]></category>
		<category><![CDATA[사용자 역할]]></category>
		<category><![CDATA[사용자 정보]]></category>
		<category><![CDATA[세션 관리]]></category>
		<category><![CDATA[소셜 로그인]]></category>
		<category><![CDATA[실패 시도]]></category>
		<category><![CDATA[암호화]]></category>
		<category><![CDATA[역할 기반 접근]]></category>
		<category><![CDATA[외부 로그인]]></category>
		<category><![CDATA[의존성 주입]]></category>
		<category><![CDATA[이메일 인증]]></category>
		<category><![CDATA[이메일 확인]]></category>
		<category><![CDATA[익명 사용자]]></category>
		<category><![CDATA[인증]]></category>
		<category><![CDATA[인증 토큰]]></category>
		<category><![CDATA[일반 사용자]]></category>
		<category><![CDATA[전화번호 인증]]></category>
		<category><![CDATA[정책 기반 인증]]></category>
		<category><![CDATA[초기 데이터]]></category>
		<category><![CDATA[커스텀 검증]]></category>
		<category><![CDATA[쿠키 인증]]></category>
		<category><![CDATA[토큰]]></category>
		<category><![CDATA[패스워드 복잡성]]></category>
		<category><![CDATA[패스워드 정책]]></category>
		<category><![CDATA[패스워드 찾기]]></category>
		<category><![CDATA[프로필 관리]]></category>
		<category><![CDATA[해싱]]></category>
		<category><![CDATA[환경 설정]]></category>
		<category><![CDATA[회원가입]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=40232</guid>

					<description><![CDATA[<p>✨ ASP.NET Core IdentityOptions 개요 https://github.com/dotnet/aspnetcore/blob/3f1acb59718cadf111a0a796681e3d3509bb3381/src/Identity/Extensions.Core/src/IdentityOptions.cs#L17C65-L65C66 ASP.NET Core의 IdentityOptions는 시스템의 설정을 한 곳에 몰아서 관리하는 클래스입니다. (중앙 집중식 구성) 이를 통해 패스워드 정책, 사용자 설정, 로그인 정책, 잠금 정책 등을 세밀하게 제어할 수 있습니다. 🔥 주요 구성 요소 1️⃣ Password 옵션 (PasswordOptions) 패스워드 복잡성 요구사항을 설정합니다. 2️⃣ Lockout 옵션 (LockoutOptions) 계정 잠금 정책을 설정합니다. 3️⃣ [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/c/asp-net/asp-net-core-identityoptions-%ec%a0%95%eb%a6%ac/40232/">ASP.NET Core IdentityOptions 기본 예제</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-346b5c77      "
					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="#aspnet-core-identityoptions-개요" class="uagb-toc-link__trigger"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2728.png" alt="✨" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ASP.NET Core IdentityOptions 개요</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#주요-구성-요소" class="uagb-toc-link__trigger"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f525.png" alt="🔥" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 주요 구성 요소</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#1-password-옵션-passwordoptions" class="uagb-toc-link__trigger">1&#x20e3; Password 옵션 (PasswordOptions)</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#2-lockout-옵션-lockoutoptions" class="uagb-toc-link__trigger">2&#x20e3; Lockout 옵션 (LockoutOptions)</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#3-signin-옵션-signinoptions" class="uagb-toc-link__trigger">3&#x20e3; SignIn 옵션 (SignInOptions)</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#4-user-옵션-useroptions" class="uagb-toc-link__trigger">4&#x20e3; User 옵션 (UserOptions)</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#5-stores-옵션-storeoptions" class="uagb-toc-link__trigger">5&#x20e3; Stores 옵션 (StoreOptions)</a></li></ul><li class="uagb-toc__list"><a href="#실제-활용-시나리오" class="uagb-toc-link__trigger"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f431.png" alt="🐱" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 실제 활용 시나리오</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#1-다단계-인증-설정" class="uagb-toc-link__trigger">1&#x20e3; 다단계 인증 설정</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#2-소셜-로그인과-연계" class="uagb-toc-link__trigger">2&#x20e3; 소셜 로그인과 연계</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#3-커스텀-검증-규칙-적용" class="uagb-toc-link__trigger">3&#x20e3; 커스텀 검증 규칙 적용</a></li></ul><li class="uagb-toc__list"><a href="#참고-사항" class="uagb-toc-link__trigger"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2747.png" alt="❇" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 참고 사항</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#1-모니터링-및-로깅" class="uagb-toc-link__trigger">1&#x20e3; 모니터링 및 로깅</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#2-환경별-설정-관리" class="uagb-toc-link__trigger">2&#x20e3; 환경별 설정 관리</a></ul></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2728.png" alt="✨" class="wp-smiley" style="height: 1em; max-height: 1em;" /> ASP.NET Core IdentityOptions 개요</h1>



<p><a href="https://github.com/dotnet/aspnetcore/blob/3f1acb59718cadf111a0a796681e3d3509bb3381/src/Identity/Extensions.Core/src/IdentityOptions.cs#L17C65-L65C66" target="_blank" rel="noreferrer noopener">https://github.com/dotnet/aspnetcore/blob/3f1acb59718cadf111a0a796681e3d3509bb3381/src/Identity/Extensions.Core/src/IdentityOptions.cs#L17C65-L65C66</a></p>



<p>ASP.NET Core의 IdentityOptions는 시스템의 설정을 한 곳에 몰아서 관리하는 클래스입니다. (중앙 집중식 구성)</p>



<p>이를 통해 <strong>패스워드 정책, 사용자 설정, 로그인 정책, 잠금 정책 등</strong>을 세밀하게 제어할 수 있습니다.</p>



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



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f525.png" alt="🔥" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 주요 구성 요소</h2>



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



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="872" height="287" src="https://lycos7560.com/wp-content/uploads/2025/08/image-12.png" alt="" class="wp-image-40235" srcset="https://lycos7560.com/wp-content/uploads/2025/08/image-12.png 872w, https://lycos7560.com/wp-content/uploads/2025/08/image-12-300x99.png 300w, https://lycos7560.com/wp-content/uploads/2025/08/image-12-768x253.png 768w" sizes="(max-width: 872px) 100vw, 872px" /><figcaption class="wp-element-caption"><a href="https://learn.microsoft.com/ko-kr/dotnet/api/microsoft.aspnetcore.identity.identityoptions?view=aspnetcore-8.0" target="_blank" rel="noreferrer noopener">https://learn.microsoft.com/ko-kr/dotnet/api/microsoft.aspnetcore.identity.identityoptions?view=aspnetcore-8.0</a></figcaption></figure>



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



<h3 class="wp-block-heading">1&#x20e3; Password 옵션 (PasswordOptions)</h3>



<p>패스워드 복잡성 요구사항을 설정합니다.</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="">// Program.cs 또는 Startup.cs

// 개발 환경용 - 간단한 패스워드
public void ConfigureDevelopmentPassword(IdentityOptions options)
{
    options.Password.RequireDigit = false;
    options.Password.RequireLowercase = false;
    options.Password.RequireUppercase = false;
    options.Password.RequireNonAlphanumeric = false;
    options.Password.RequiredLength = 4;
}

// 프로덕션 환경용 - 강력한 패스워드
public void ConfigureProductionPassword(IdentityOptions options)
{
    options.Password.RequireDigit = true;
    options.Password.RequireLowercase = true;
    options.Password.RequireUppercase = true;
    options.Password.RequireNonAlphanumeric = true;
    options.Password.RequiredLength = 12;
    options.Password.RequiredUniqueChars = 4;
}</pre>



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



<h3 class="wp-block-heading">2&#x20e3; Lockout 옵션 (LockoutOptions)</h3>



<p>계정 잠금 정책을 설정합니다.</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="">public void ConfigureProgressiveLockout(IdentityOptions options)
{
    options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(1);   // 1분부터 시작
    options.Lockout.MaxFailedAccessAttempts = 3;                        // 3회 실패시 잠금
    options.Lockout.AllowedForNewUsers = true;
}

// 커스텀 잠금 시간 증가 로직 (서비스에서 구현)
public class CustomLockoutService
{
    public TimeSpan CalculateLockoutDuration(int failedAttempts)
    {
        return failedAttempts switch
        {
            &lt;= 3 => TimeSpan.FromMinutes(5),
            &lt;= 6 => TimeSpan.FromMinutes(15),
            &lt;= 10 => TimeSpan.FromHours(1),
            _ => TimeSpan.FromHours(24)
        };
    }
}

public void ConfigureProgressiveLockout(IdentityOptions options)
{
    options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(1);   // 1분부터 시작
    options.Lockout.MaxFailedAccessAttempts = 3;                        // 3회 실패시 잠금
    options.Lockout.AllowedForNewUsers = true;
}

// 커스텀 잠금 시간 증가 로직 (서비스에서 구현)
public class CustomLockoutService
{
    public TimeSpan CalculateLockoutDuration(int failedAttempts)
    {
        return failedAttempts switch
        {
            &lt;= 3 => TimeSpan.FromMinutes(5),
            &lt;= 6 => TimeSpan.FromMinutes(15),
            &lt;= 10 => TimeSpan.FromHours(1),
            _ => TimeSpan.FromHours(24)
        };
    }
}</pre>



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



<h3 class="wp-block-heading">3&#x20e3; SignIn 옵션 (SignInOptions)</h3>



<p>로그인 관련 설정을 구성합니다.</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="">// 이메일 인증 필수 설정
public void ConfigureEmailConfirmation(IdentityOptions options)
{
    options.SignIn.RequireConfirmedEmail = true;
}

// 회원가입 컨트롤러
[HttpPost]
public async Task&lt;IActionResult> Register(RegisterViewModel model)
{
    var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
    var result = await _userManager.CreateAsync(user, model.Password);
    
    if (result.Succeeded)
    {
        // 이메일 인증 토큰 생성
        var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
        var confirmationLink = Url.Action("ConfirmEmail", "Account", 
            new { userId = user.Id, token = token }, Request.Scheme);
        
        // 이메일 발송
        await _emailSender.SendEmailAsync(model.Email, "이메일 인증", 
            $"다음 링크를 클릭하여 계정을 활성화하세요: {confirmationLink}");
        
        return View("EmailConfirmationSent");
    }
    
    return View(model);
}

// 이메일 인증 필수 설정
public void ConfigureEmailConfirmation(IdentityOptions options)
{
    options.SignIn.RequireConfirmedEmail = true;
}

// 회원가입 컨트롤러
[HttpPost]
public async Task&lt;IActionResult> Register(RegisterViewModel model)
{
    var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
    var result = await _userManager.CreateAsync(user, model.Password);
    
    if (result.Succeeded)
    {
        // 이메일 인증 토큰 생성
        var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
        var confirmationLink = Url.Action("ConfirmEmail", "Account", 
            new { userId = user.Id, token = token }, Request.Scheme);
        
        // 이메일 발송
        await _emailSender.SendEmailAsync(model.Email, "이메일 인증", 
            $"다음 링크를 클릭하여 계정을 활성화하세요: {confirmationLink}");
        
        return View("EmailConfirmationSent");
    }
    
    return View(model);
}
</pre>



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



<h3 class="wp-block-heading">4&#x20e3; User 옵션 (UserOptions)</h3>



<p>사용자 계정 관련 설정을 구성합니다.</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="">builder.Services.Configure&lt;IdentityOptions>(options =>
{
    // 사용자 설정
    options.User.AllowedUserNameCharacters = 
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
    options.User.RequireUniqueEmail = true;  // 중복 이메일 방지
});


사용자명 정책 예제:
public void ConfigureUserPolicies(IdentityOptions options)
{
    // 한국어 사용자명 허용
    options.User.AllowedUserNameCharacters = 
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+가-힣";
    
    // 이메일을 고유하게 설정
    options.User.RequireUniqueEmail = true;
}

// 커스텀 사용자명 검증
public class CustomUserValidator&lt;TUser> : IUserValidator&lt;TUser> 
    where TUser : class
{
    public Task&lt;IdentityResult> ValidateAsync(UserManager&lt;TUser> manager, TUser user)
    {
        var userName = manager.GetUserNameAsync(user).Result;
        
        // 사용자명이 숫자로만 구성되면 안됨
        if (userName.All(char.IsDigit))
        {
            return Task.FromResult(
                IdentityResult.Failed(new IdentityError
                {
                    Code = "NumericUserName",
                    Description = "사용자명은 숫자로만 구성될 수 없습니다."
                }));
        }
        
        return Task.FromResult(IdentityResult.Success);
    }
}</pre>



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



<h3 class="wp-block-heading">5&#x20e3; Stores 옵션 (StoreOptions)</h3>



<p>사용자 계정 관련 설정을 구성합니다.</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="">builder.Services.Configure&lt;IdentityOptions>(options =>
{
    // 저장소 설정
    options.Stores.MaxLengthForKeys = 128;              // 키 최대 길이
    options.Stores.ProtectPersonalData = false;         // 개인정보 암호화 여부
});</pre>



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



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f431.png" alt="🐱" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 실제 활용 시나리오</h2>



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



<h3 class="wp-block-heading">1&#x20e3; 다단계 인증 설정</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 void ConfigureTwoFactorAuthentication(IdentityOptions options)
{
    options.SignIn.RequireConfirmedPhoneNumber = true;  // 전화번호 인증 필수
    options.Tokens.AuthenticatorTokenProvider = TokenOptions.DefaultAuthenticatorProvider;
}

// 2FA 활성화 코드
[HttpPost]
public async Task&lt;IActionResult> EnableTwoFactorAuthentication()
{
    var user = await _userManager.GetUserAsync(User);
    await _userManager.SetTwoFactorEnabledAsync(user, true);
    
    return RedirectToAction("ShowRecoveryCodes");
}</pre>



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



<h3 class="wp-block-heading">2&#x20e3; 소셜 로그인과 연계</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 void ConfigureExternalLogins(IdentityOptions options)
{
    // 외부 로그인 시에는 이메일 인증 건너뛰기
    options.SignIn.RequireConfirmedEmail = false;
    
    // 하지만 고유 이메일은 필수
    options.User.RequireUniqueEmail = true;
}

// 외부 로그인 처리
[HttpPost]
public IActionResult ExternalLogin(string provider)
{
    var redirectUrl = Url.Action("ExternalLoginCallback");
    var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
    return Challenge(properties, provider);
}</pre>



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



<h3 class="wp-block-heading">3&#x20e3; 커스텀 검증 규칙 적용</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 class CustomPasswordValidator : IPasswordValidator&lt;ApplicationUser>
{
    public Task&lt;IdentityResult> ValidateAsync(UserManager&lt;ApplicationUser> manager, 
        ApplicationUser user, string password)
    {
        // 사용자명과 패스워드가 너무 유사하면 안됨
        if (password.Contains(user.UserName, StringComparison.OrdinalIgnoreCase))
        {
            return Task.FromResult(IdentityResult.Failed(new IdentityError
            {
                Code = "PasswordContainsUserName",
                Description = "패스워드에 사용자명이 포함될 수 없습니다."
            }));
        }
        
        return Task.FromResult(IdentityResult.Success);
    }
}

// 서비스 등록
builder.Services.AddTransient&lt;IPasswordValidator&lt;ApplicationUser>, CustomPasswordValidator>();</pre>



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



<h2 class="wp-block-heading"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2747.png" alt="❇" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 참고 사항</h2>



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



<h3 class="wp-block-heading">1&#x20e3; 모니터링 및 로깅</h3>



<p>보안 이벤트 로깅</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="">public class SecurityEventLogger
{
    private readonly ILogger&lt;SecurityEventLogger> _logger;
    
    public SecurityEventLogger(ILogger&lt;SecurityEventLogger> logger)
    {
        _logger = logger;
    }
    
    public void LogFailedLogin(string userName, string ipAddress)
    {
        _logger.LogWarning("Failed login attempt for user {UserName} from IP {IpAddress}", 
            userName, ipAddress);
    }
    
    public void LogAccountLocked(string userName)
    {
        _logger.LogWarning("Account locked for user {UserName}", userName);
    }
}</pre>



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



<h3 class="wp-block-heading">2&#x20e3; 환경별 설정 관리</h3>



<p>appsettings.json을 활용한 설정</p>



<pre class="EnlighterJSRAW" data-enlighter-language="json" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">{
  "Identity": {
    "Password": {
      "RequiredLength": 8,
      "RequireDigit": true,
      "RequireUppercase": true,
      "RequireNonAlphanumeric": false
    },
    "Lockout": {
      "MaxFailedAccessAttempts": 5,
      "DefaultLockoutTimeSpanMinutes": 15
    },
    "SignIn": {
      "RequireConfirmedEmail": true
    }
  }
}</pre>



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



<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 class IdentityConfig
{
    public PasswordConfig Password { get; set; }
    public LockoutConfig Lockout { get; set; }
    public SignInConfig SignIn { get; set; }
}

// Program.cs에서 적용
var identityConfig = builder.Configuration.GetSection("Identity").Get&lt;IdentityConfig>();

builder.Services.Configure&lt;IdentityOptions>(options =>
{
    options.Password.RequiredLength = identityConfig.Password.RequiredLength;
    options.Password.RequireDigit = identityConfig.Password.RequireDigit;
    // ... 기타 설정
});</pre>
<p>The post <a href="https://lycos7560.com/c/asp-net/asp-net-core-identityoptions-%ec%a0%95%eb%a6%ac/40232/">ASP.NET Core IdentityOptions 기본 예제</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/c/asp-net/asp-net-core-identityoptions-%ec%a0%95%eb%a6%ac/40232/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 30804번 (과일 탕후루, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-30804%eb%b2%88-%ea%b3%bc%ec%9d%bc-%ed%83%95%ed%9b%84%eb%a3%a8-c-baekjoon/39911/</link>
					<comments>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-30804%eb%b2%88-%ea%b3%bc%ec%9d%bc-%ed%83%95%ed%9b%84%eb%a3%a8-c-baekjoon/39911/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sun, 05 Jan 2025 05:16:08 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[30804]]></category>
		<category><![CDATA[30804번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></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[백준 30804]]></category>
		<category><![CDATA[백준 30804번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=39911</guid>

					<description><![CDATA[<p>과일 탕후루 https://www.acmicpc.net/problem/30804 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 2 초 1024 MB 13648 4768 3826 33.976% 문제 은하는 긴 막대에 N개의 과일이 꽂혀있는 과일 탕후루를 만들었습니다. 과일의 각 종류에는 1부터 9까지의 번호가 붙어있고, 앞쪽부터 차례로  번 과일이 꽂혀있습니다. 과일 탕후루를 다 만든 은하가 주문을 다시 확인해보니 과일을 두 종류 이하로 사용해 달라는 요청이 [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-30804%eb%b2%88-%ea%b3%bc%ec%9d%bc-%ed%83%95%ed%9b%84%eb%a3%a8-c-baekjoon/39911/">백준 30804번 (과일 탕후루, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">과일 탕후루 <img decoding="async" width="30" height="38" class="wp-image-37910" style="width: 30px;" src="https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2.jpg" alt="" srcset="https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2.jpg 400w, https://lycos7560.com/wp-content/uploads/2024/03/Sliver_2-234x300.jpg 234w" sizes="(max-width: 30px) 100vw, 30px" /></h2>



<p><a href="https://www.acmicpc.net/problem/30804" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/30804</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">2 초</td><td class="has-text-align-left" data-align="left">1024 MB</td><td class="has-text-align-left" data-align="left">13648</td><td class="has-text-align-left" data-align="left">4768</td><td class="has-text-align-left" data-align="left">3826</td><td class="has-text-align-left" data-align="left">33.976%</td></tr></tbody></table></figure>



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



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



<p>은하는 긴 막대에 N개의 과일이 꽂혀있는 과일 탕후루를 만들었습니다. </p>



<p>과일의 각 종류에는 1부터 9까지의 번호가 붙어있고, 앞쪽부터 차례로 <img decoding="async" width="104" height="22" class="wp-image-39912" style="width: 104px;" src="https://lycos7560.com/wp-content/uploads/2025/03/image-1.png" alt=""> 번 과일이 꽂혀있습니다. </p>



<p>과일 탕후루를 다 만든 은하가 주문을 다시 확인해보니 과일을 두 종류 이하로 사용해 달라는 요청이 있었습니다.</p>



<p>탕후루를 다시 만들 시간이 없었던 은하는, 막대의 앞쪽과 뒤쪽에서 몇 개의 과일을 빼서 두 종류 이하의 과일만 남기기로 했습니다. </p>



<p>앞에서 a개, 뒤에서 b개의 과일을 빼면 <img decoding="async" width="200" height="17" class="wp-image-39913" style="width: 200px;" src="https://lycos7560.com/wp-content/uploads/2025/03/image-2.png" alt=""> 번 과일, 총 N &#8211; (a + b)개가 꽂혀있는 탕후루가 됩니다. <img decoding="async" width="150" height="27" class="wp-image-39914" style="width: 150px;" src="https://lycos7560.com/wp-content/uploads/2025/03/image-3.png" alt=""></p>



<p>이렇게 만들 수 있는 과일을 두 종류 이하로 사용한 탕후루 중에서, 과일의 개수가 가장 많은 탕후루의 과일 개수를 구하세요.</p>



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



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



<p>첫 줄에 과일의 개수 N이 주어집니다. <img decoding="async" width="145" height="23" class="wp-image-39915" style="width: 145px;" src="https://lycos7560.com/wp-content/uploads/2025/03/image-4.png" alt=""></p>



<p>둘째 줄에 탕후루에 꽂힌 과일을 의미하는 N개의 정수 <img decoding="async" width="78" height="24" class="wp-image-39917" style="width: 78px;" src="https://lycos7560.com/wp-content/uploads/2025/03/image-6.png" alt=""> 이 공백으로 구분되어 주어집니다. <img decoding="async" width="98" height="22" class="wp-image-39916" style="width: 98px;" src="https://lycos7560.com/wp-content/uploads/2025/03/image-5.png" alt=""></p>



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



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



<p>문제의 방법대로 만들 수 있는 과일을 두 종류 이하로 사용한 탕후루 중에서, 과일의 개수가 가장 많은 탕후루의 과일 개수를 첫째 줄에 출력하세요.</p>



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



<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="">5
5 1 1 2 1</pre>



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



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



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



<p>과일을 앞에서 1개, 뒤에서 0개의 과일을 빼면 남은 과일은 1, 1, 2, 1번 과일이 꽂혀있는 탕후루가 됩니다. </p>



<p>과일의 개수는 4개입니다.</p>



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



<h3 class="wp-block-heading">예제 입력 2</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="">3
1 1 1</pre>



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



<h3 class="wp-block-heading">예제 출력 2</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="">3</pre>



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



<p>탕후루가 이미 두 종류 이하의 과일로만 이루어져 있습니다.</p>



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



<h3 class="wp-block-heading">예제 입력 3</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="">9
1 2 3 4 5 6 7 8 9</pre>



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



<h3 class="wp-block-heading">예제 출력 3</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="">2</pre>



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



<p>과일을 앞에서 3개, 뒤에서 4개의 과일을 빼면 남은 과일은 4, 5번 과일이 꽂혀있는 탕후루가 됩니다. </p>



<p>과일의 개수는 2개입니다.</p>



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



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



<p><a href="https://www.acmicpc.net/category/45" target="_blank" rel="noreferrer noopener">Contest</a> > <a href="https://www.acmicpc.net/category/859" target="_blank" rel="noreferrer noopener">solved.ac</a> > <a href="https://www.acmicpc.net/category/1003" target="_blank" rel="noreferrer noopener">solved.ac Grand Arena #3</a> > <a href="https://www.acmicpc.net/category/detail/4059" target="_blank" rel="noreferrer noopener">Division 2</a> C번</p>



<p><a href="https://www.acmicpc.net/category/45" target="_blank" rel="noreferrer noopener">Contest</a> > <a href="https://www.acmicpc.net/category/859" target="_blank" rel="noreferrer noopener">solved.ac</a> > <a href="https://www.acmicpc.net/category/1003" target="_blank" rel="noreferrer noopener">solved.ac Grand Arena #3</a> > <a href="https://www.acmicpc.net/category/detail/4060" target="_blank" rel="noreferrer noopener">Division 1</a> A번</p>



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



<li>문제를 검수한 사람: <a href="https://www.acmicpc.net/user/cologne">cologne</a>, <a href="https://www.acmicpc.net/user/cozyyg">cozyyg</a>, <a href="https://www.acmicpc.net/user/gs18115">gs18115</a>, <a href="https://www.acmicpc.net/user/moonrabbit2">moonrabbit2</a>, <a href="https://www.acmicpc.net/user/seonah">seonah</a></li>
</ul>



<div style="height:40px" 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/102" target="_blank" rel="noreferrer noopener">구현</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>



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



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



<p>map 자료구조, 두 포인터 알고리즘을 이용하여 문제를 해결</p>



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

using namespace std;

int N;
int Arr[200000];

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

    cin >> N;

    for (int i = 0; i &lt; N; i++)
        cin >> Arr[i];

    map&lt;int, int> fruitCount;
    int left = 0, right = 0, maxLen = 0;

    while (right &lt; N) 
    {
        // 오른쪽 과일 추가
        fruitCount[Arr[right]]++;

        while (fruitCount.size() > 2) 
        { 
            // 과일 종류가 2개 초과하면 줄이기
            fruitCount[Arr[left]]--;
            if (fruitCount[Arr[left]] == 0)
                fruitCount.erase(Arr[left]);
            left++;
        }

        // 최대 길이 갱신
        maxLen = max(maxLen, right - left + 1);
        right++;
    }

    cout &lt;&lt; maxLen &lt;&lt; "\n";

    return 0;
}
</pre>



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



<p>Arr[] 범위를 20,000으로 오타를 내고 제출하여 계속 오답을 받았다. (올바른 범위는 200,000) </p>



<figure class="wp-block-image size-full"><img decoding="async" width="961" height="181" src="https://lycos7560.com/wp-content/uploads/2025/03/image-7.png" alt="" class="wp-image-39919" srcset="https://lycos7560.com/wp-content/uploads/2025/03/image-7.png 961w, https://lycos7560.com/wp-content/uploads/2025/03/image-7-300x57.png 300w, https://lycos7560.com/wp-content/uploads/2025/03/image-7-768x145.png 768w" sizes="(max-width: 961px) 100vw, 961px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>
<p>The post <a href="https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-30804%eb%b2%88-%ea%b3%bc%ec%9d%bc-%ed%83%95%ed%9b%84%eb%a3%a8-c-baekjoon/39911/">백준 30804번 (과일 탕후루, C++) [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/cpp/%eb%b0%b1%ec%a4%80-30804%eb%b2%88-%ea%b3%bc%ec%9d%bc-%ed%83%95%ed%9b%84%eb%a3%a8-c-baekjoon/39911/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 12924번 (멋진 쌍, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Wed, 09 Aug 2023 04:47:07 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[12924]]></category>
		<category><![CDATA[12924번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[멋진 쌍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 12924]]></category>
		<category><![CDATA[백준 12924번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[수학]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=36435</guid>

					<description><![CDATA[<p>백준 12924번 '멋진 쌍' 문제에 대한 글입니다. '브루트포스' 알고리즘을 이용하여 문제를 해결하였습니다. (This article is about Baekjoon Number 12924 "Cool Pair" problem. We solved the problem using the 'Brute Force' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/">백준 12924번 (멋진 쌍, 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>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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


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


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



<h1 class="wp-block-heading">멋진 쌍</h1>



<p><a href="https://www.acmicpc.net/problem/12924">https://www.acmicpc.net/problem/12924</a></p>



<div style="height:50px" 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">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">238</td><td class="has-text-align-left" data-align="left">88</td><td class="has-text-align-left" data-align="left">76</td><td class="has-text-align-left" data-align="left">38.191%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>두 자연수 (n, m)이 멋진 쌍일 조건은 다음과 같다.</p>



<ul class="wp-block-list">
<li>n의 뒤에서 몇 자리를 떼서, 앞에 그대로 붙이면 m을 얻을 수 있다.</li>
</ul>



<p>예를 들어, 12345의 뒤에서 345를 떼서 앞에 붙이면 34512가 되므로, (12345, 34512)는 멋진 쌍이다.</p>



<p>같은 개수의 자릿수를 갖는 두 자연수 A와 B가 주어질 때, A ≤ x &lt;&nbsp;y ≤ B 인 멋진 쌍 (x, y)의 개수를 출력하세요.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫 번째 줄에 두 자연수 A, B가 주어진다. A ≤ B ≤ 2,000,000, A와 B의 자릿수 개수는 같다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>멋진 쌍의 개수를 자연수 하나로 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 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="">1 9</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 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="">0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 2</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="">10 40</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 2</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="">3</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 3</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="">100 500</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 3</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="">156</pre>



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



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



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



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



<p>중복을 제거하지 않으면 오답으로 처리됩니다.</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;string>
#include &lt;cmath>
#include &lt;set>
using namespace std;
set&lt;pair&lt;int, int>> _ResSet;
int _A, _B, _Res;
int FindingDigit(int _number)
{
	int dig = 0;
	while (_number) {
		_number /= 10;
		dig++;
	}
	return dig;
}

int main()
{
	cin >> _A >> _B;
	for (int i = _A; i &lt;= _B; i++) {
		int dig = FindingDigit(i);
		_ResSet.clear();
		for (int j = 1; j &lt;= dig - 1; j++) {
			int number = i;
			int _t = pow(10, j);
			int remainder = number % _t;
			int frontpart = number / _t;
			int frontpartDig = FindingDigit(frontpart);
			_t = pow(10, frontpartDig);
			int res = frontpart + (remainder * _t);
			if (dig != FindingDigit(res))
				continue;
			if (res > _B || res &lt; _A || res &lt;= number)
				continue;
			_ResSet.insert({ number, res });
		}
		_Res += _ResSet.size();
	}
	cout &lt;&lt; _Res;
	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1207" height="99" src="https://lycos7560.com/wp-content/uploads/2023/08/image-3.png" alt="" class="wp-image-36447" srcset="https://lycos7560.com/wp-content/uploads/2023/08/image-3.png 1207w, https://lycos7560.com/wp-content/uploads/2023/08/image-3-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/08/image-3-768x63.png 768w" sizes="(max-width: 1207px) 100vw, 1207px" /></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="4386247858"></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-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/">백준 12924번 (멋진 쌍, 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-12924%eb%b2%88-%eb%a9%8b%ec%a7%84-%ec%8c%8d-c-baekjoon/36435/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 20529번 (가장 가까운 세 사람의 심리적 거리, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-20529%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b0%80%ea%b9%8c%ec%9a%b4-%ec%84%b8-%ec%82%ac%eb%9e%8c%ec%9d%98-%ec%8b%ac%eb%a6%ac%ec%a0%81-%ea%b1%b0%eb%a6%ac-c-baekjoon/36060/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-20529%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b0%80%ea%b9%8c%ec%9a%b4-%ec%84%b8-%ec%82%ac%eb%9e%8c%ec%9d%98-%ec%8b%ac%eb%a6%ac%ec%a0%81-%ea%b1%b0%eb%a6%ac-c-baekjoon/36060/#comments</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 14 Jul 2023 22:16:16 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[20529]]></category>
		<category><![CDATA[20529번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[bit]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[MBTI]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[가장 가까운 세 사람의 심리적 거리]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 20529]]></category>
		<category><![CDATA[백준 20529번]]></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=36060</guid>

					<description><![CDATA[<p>가장 가까운 세 사람의 심리적 거리 https://www.acmicpc.net/problem/20529 시간 제한 메모리 제한 제출 정답 맞힌 사람 정답 비율 2 초 1536 MB 4043 1550 1185 36.744% 문제 여러분은 요즘 유행하는 심리검사인 MBTI에 대해 들어보았는가? MBTI(Myers-Briggs Type Indicator)는&#160;C.G.Jung의 심리유형론을 근거로 하여 Katharine Cook Briggs와 Isabel Briggs Myers가 보다 쉽고 일상생활에 유용하게 활용할 수 있도록 고안한 자기보고식 성격유형지표이다. [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-20529%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b0%80%ea%b9%8c%ec%9a%b4-%ec%84%b8-%ec%82%ac%eb%9e%8c%ec%9d%98-%ec%8b%ac%eb%a6%ac%ec%a0%81-%ea%b1%b0%eb%a6%ac-c-baekjoon/36060/">백준 20529번 (가장 가까운 세 사람의 심리적 거리, 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-b726977e      "
					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><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></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">가장 가까운 세 사람의 심리적 거리</h1>



<p><a href="https://www.acmicpc.net/problem/20529" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/20529</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">2 초</td><td class="has-text-align-left" data-align="left">1536 MB</td><td class="has-text-align-left" data-align="left">4043</td><td class="has-text-align-left" data-align="left">1550</td><td class="has-text-align-left" data-align="left">1185</td><td class="has-text-align-left" data-align="left">36.744%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>여러분은 요즘 유행하는 심리검사인 MBTI에 대해 들어보았는가?</p>



<p>MBTI(Myers-Briggs Type Indicator)는&nbsp;C.G.Jung의 심리유형론을 근거로 하여 Katharine Cook Briggs와 Isabel Briggs Myers가 보다 쉽고 </p>



<p>일상생활에 유용하게 활용할 수 있도록 고안한 자기보고식 성격유형지표이다. (출처: 위키백과)</p>



<p>MBTI는 아래와 같이 네 가지 척도로 사람들의 성격을 구분한다.</p>



<ul class="wp-block-list">
<li>외향(E) / 내향(I)</li>



<li>감각(S) / 직관(N)</li>



<li>사고(T) / 감정(F)</li>



<li>판단(J) / 인식(P)</li>
</ul>



<p>각 척도마다 두 가지 분류가 존재하므로, MBTI는 총&nbsp;2^4 = 16가지 유형이 있음을 알 수 있다. </p>



<p>일반적으로&nbsp;MBTI의 유형들은 각 분류를 나타내는 알파벳 한 글자씩을 따 네 글자로 표시하게 된다. </p>



<p>모든 유형의 목록은 다음과 같다.</p>



<ul class="wp-block-list">
<li>ISTJ, ISFJ, INFJ, INTJ, ISTP, ISFP, INFP, INTP, ESTP, ESFP, ENFP, ENTP, ESTJ, ESFJ, ENFJ, ENTJ</li>
</ul>



<p>MBTI 성격 유형을 이용하면&nbsp;두 사람 사이의 심리적인 거리를 정의할 수 있다. </p>



<p>이는&nbsp;두 사람의 MBTI 유형에서&nbsp;서로 다른 분류에 속하는 척도의 수로 정의된다. </p>



<p>예를 들어, MBTI 유형이 ISTJ인 사람과 ISFJ인 사람 사이의 거리는 1이며, INTP인 사람과 ENTJ인 사람 사이의 거리는 2이다.</p>



<p>이 정의를 확장해서 세&nbsp;사람 사이의 심리적인 거리도 정의할 수 있다.&nbsp;</p>



<p>세 사람&nbsp;A, B, C가 있을 때 이들의 심리적인 거리는</p>



<p>(A와&nbsp;B&nbsp;사이의 심리적인&nbsp;거리)&nbsp;+ (B와&nbsp;C&nbsp;사이의 심리적인&nbsp;거리)&nbsp;+ (A와&nbsp;C&nbsp;사이의 심리적인&nbsp;거리)로 정의한다.</p>



<p>대학교에서 심리학 교수로&nbsp;일하는 종서는 자신이 가르치는 학생들의 심리적인 특성을 분석하고 싶어한다.</p>



<p>오늘이 생일인 종서를 위해&nbsp;N명의 학생들의 MBTI 유형이 주어질 때, </p>



<p>가장 가까운 세&nbsp;학생 사이의 심리적인 거리를 구해보자.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫 줄에는 테스트 케이스의 수를 나타내는 정수&nbsp;T가 주어진다.</p>



<p>각 테스트 케이스의 첫 줄에는 학생의 수를 나타내는 하나의 정수&nbsp;N이 주어지며, </p>



<p>두 번째 줄에는 각 학생의 MBTI 성격 유형을 나타내는 문자열들이 사이에 공백을 두고 주어진다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>각 테스트 케이스에 대한 답을 정수 형태로 한 줄에 하나씩 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">제한</h3>



<ul class="wp-block-list">
<li> 1≤ T ≤50 </li>



<li> 3≤ N ≤100000</li>



<li>각 테스트 케이스의 N의 합은 100,000을 넘지 않는다.</li>
</ul>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 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="">3
3
ENTJ INTP ESFJ
4
ESFP ESFP ESFP ESFP
5
INFP INFP ESTP ESTJ ISTJ</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 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="">8
0
4</pre>



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



<ul class="wp-block-list">
<li>첫 번째 테스트 케이스의 경우, ENTJ와 INTP의 심리적인 거리는 2, <br>ENTJ와 ESFJ의 심리적인 거리는 2, INTP와 ESFJ의 심리적인 거리는 4이므로 세 사람의 심리적인 거리는 2+2+4=8이다.</li>



<li>두 번째 테스트 케이스의 경우, 어떤 사람 둘을 골라도 심리적인 거리가 0이므로 가장 가까운 세 사람의 심리적인 거리는 0이다.</li>



<li>세 번째 테스트 케이스의 경우, 심리적인 거리를 최소화하려면 MBTI가 ESTP, ESTJ, ISTJ인 세 사람을 골라야 한다. <br>ESTP와 ESTJ의 심리적인 거리는 1, ESTP와 ISTJ의 심리적인 거리는 2, ESTJ와 ISTJ의 심리적인 거리는 1이므로 세 사람의 심리적인 거리는 1+2+1=4이다.</li>
</ul>



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



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



<p><a href="https://www.acmicpc.net/category/45" target="_blank" rel="noreferrer noopener">Contest</a> > <a href="https://www.acmicpc.net/category/469" target="_blank" rel="noreferrer noopener">Good Bye, BOJ</a> > <a href="https://www.acmicpc.net/category/detail/2379" target="_blank" rel="noreferrer noopener">Good Bye, BOJ 2020!</a> B번</p>



<ul class="wp-block-list">
<li>문제를 검수한 사람: <a href="https://www.acmicpc.net/user/ahgus89" target="_blank" rel="noreferrer noopener">ahgus89</a>, <a href="https://www.acmicpc.net/user/cgiosy" target="_blank" rel="noreferrer noopener">cgiosy</a>, <a href="https://www.acmicpc.net/user/cheetose" target="_blank" rel="noreferrer noopener">cheetose</a>, <a href="https://www.acmicpc.net/user/cs71107" target="_blank" rel="noreferrer noopener">cs71107</a>, <a href="https://www.acmicpc.net/user/evenharder" target="_blank" rel="noreferrer noopener">evenharder</a>, <a href="https://www.acmicpc.net/user/gravekper" target="_blank" rel="noreferrer noopener">gravekper</a>, <a href="https://www.acmicpc.net/user/jhnah917" target="_blank" rel="noreferrer noopener">jhnah917</a>, <a href="https://www.acmicpc.net/user/junseo" target="_blank" rel="noreferrer noopener">junseo</a>, <a href="https://www.acmicpc.net/user/kdh9949" target="_blank" rel="noreferrer noopener">kdh9949</a>, <a href="https://www.acmicpc.net/user/koosaga">koosaga</a>, <a href="https://www.acmicpc.net/user/queued_q" target="_blank" rel="noreferrer noopener">queued_q</a>, <a href="https://www.acmicpc.net/user/rdd6584" target="_blank" rel="noreferrer noopener">rdd6584</a>, <a href="https://www.acmicpc.net/user/ryute" target="_blank" rel="noreferrer noopener">ryute</a></li>



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



<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/leejseo" target="_blank" rel="noreferrer noopener">leejseo</a>, <a href="https://www.acmicpc.net/user/queued_q" target="_blank" rel="noreferrer noopener">queued_q</a></li>
</ul>



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



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



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



<li><a href="https://www.acmicpc.net/problem/tag/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>



<li><a href="https://www.acmicpc.net/problem/tag/189" 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="8eWN1jIoBu"><a href="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%84%eb%91%98%ea%b8%b0-%ec%a7%91%ec%9d%98-%ec%9b%90%eb%a6%ac-pigeonhole-principle/36080/">알고리즘 – 비둘기 집의 원리 (Pigeonhole Principle)</a></blockquote><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  title="&#8220;알고리즘 – 비둘기 집의 원리 (Pigeonhole Principle)&#8221; &#8212; 어제와 내일의 나 그 사이의 이야기" src="https://lycos7560.com/etc/%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98-%eb%b9%84%eb%91%98%ea%b8%b0-%ec%a7%91%ec%9d%98-%ec%9b%90%eb%a6%ac-pigeonhole-principle/36080/embed/#?secret=t2KQIZOfcp#?secret=8eWN1jIoBu" data-secret="8eWN1jIoBu" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</div></figure>



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



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



<p>비둘기 집의 원리를 이용하여 N &gt; 32 인 경우를 처리해주는 것이 문제의 포인트</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>
using namespace std;
int _T, _N, _Res = INT32_MAX;
string _Str;
int main()
{
	ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	cin >> _T;
	for (int i = 0; i &lt; _T; i++) {
		cin >> _N;
		vector&lt;string> _StrV;
		for (int i = 0; i &lt; _N; i++) {
			cin >> _Str;
			_StrV.push_back(_Str);
		}
		if (_N > 32) {
			std::cout &lt;&lt; 0 &lt;&lt; "\n";
			continue;
		}
		int _Sum;
		_Res = INT32_MAX;
		for (int i = 0; i &lt; _N; i++) {
			for (int j = i + 1; j &lt; _N; j++) {
				for (int k = j + 1; k &lt; _N; k++) {
					_Sum = 0;
					for (int q = 0; q &lt; 4; q++) {
						if (_StrV[i][q] != _StrV[j][q]) _Sum++;
						if (_StrV[j][q] != _StrV[k][q]) _Sum++;
						if (_StrV[k][q] != _StrV[i][q]) _Sum++;
					}
					_Res = min(_Res, _Sum);
				}
			}
		}
		std::cout &lt;&lt; _Res &lt;&lt; "\n";
	}

	return 0;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1061" height="88" src="https://lycos7560.com/wp-content/uploads/2023/07/image-33.png" alt="" class="wp-image-36070" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-33.png 1061w, https://lycos7560.com/wp-content/uploads/2023/07/image-33-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-33-768x64.png 768w" sizes="(max-width: 1061px) 100vw, 1061px" /></figure>



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



<h2 class="wp-block-heading has-large-font-size">더 효율적인 코드 (비트 마스킹)</h2>



<p>비트마스킹을 이용하여 메모리 및 속도를 개선합니다.</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>
using namespace std;
int _T, _N, _Res = INT32_MAX;
vector&lt;int> _bitV;
string _Str;
int main()
{
	ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	cin >> _T;
	for (int i = 0; i &lt; _T; i++) {
		cin >> _N;
		_bitV.clear();
		for (int i = 0; i &lt; _N; i++) {
			cin >> _Str;
			int _bit = 0;
			if (_Str[0] == 'I') _bit += 1 &lt;&lt; 0;
			if (_Str[1] == 'N') _bit += 1 &lt;&lt; 1;
			if (_Str[2] == 'F') _bit += 1 &lt;&lt; 2;
			if (_Str[3] == 'P') _bit += 1 &lt;&lt; 3;
			_bitV.push_back(_bit);
		}
		if (_N > 32) {
			std::cout &lt;&lt; 0 &lt;&lt; "\n";
			continue;
		}
		int _Sum;
		_Res = INT32_MAX;
		for (int i = 0; i &lt; _N; i++) {
			for (int j = i + 1; j &lt; _N; j++) {
				for (int k = j + 1; k &lt; _N; k++) {
					_Sum = 0;
					for (int q = 0; q &lt; 4; q++) {
						if ((_bitV[i] &amp; (1 &lt;&lt; q)) != (_bitV[j] &amp; (1 &lt;&lt; q))) _Sum++;
						if ((_bitV[j] &amp; (1 &lt;&lt; q)) != (_bitV[k] &amp; (1 &lt;&lt; q))) _Sum++;
						if ((_bitV[k] &amp; (1 &lt;&lt; q)) != (_bitV[i] &amp; (1 &lt;&lt; q))) _Sum++;
					}
					_Res = min(_Res, _Sum);
				}
			}
		}
		std::cout &lt;&lt; _Res &lt;&lt; "\n";
	}

	return 0;
}</pre>



<div style="height:50px" 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-20529%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b0%80%ea%b9%8c%ec%9a%b4-%ec%84%b8-%ec%82%ac%eb%9e%8c%ec%9d%98-%ec%8b%ac%eb%a6%ac%ec%a0%81-%ea%b1%b0%eb%a6%ac-c-baekjoon/36060/">백준 20529번 (가장 가까운 세 사람의 심리적 거리, 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-20529%eb%b2%88-%ea%b0%80%ec%9e%a5-%ea%b0%80%ea%b9%8c%ec%9a%b4-%ec%84%b8-%ec%82%ac%eb%9e%8c%ec%9d%98-%ec%8b%ac%eb%a6%ac%ec%a0%81-%ea%b1%b0%eb%a6%ac-c-baekjoon/36060/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>백준 14502번 (연구소, C++) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14502%eb%b2%88-%ec%97%b0%ea%b5%ac%ec%86%8c-c-baekjoon/35759/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14502%eb%b2%88-%ec%97%b0%ea%b5%ac%ec%86%8c-c-baekjoon/35759/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 07 Jul 2023 23:00:51 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[14502]]></category>
		<category><![CDATA[14502번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[lab]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[구현]]></category>
		<category><![CDATA[그래프]]></category>
		<category><![CDATA[그래프 이론]]></category>
		<category><![CDATA[그래프 탐색]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 14502]]></category>
		<category><![CDATA[백준 14502번]]></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=35759</guid>

					<description><![CDATA[<p>백준 14502번 '연구소' 문제에 대한 글입니다. 'BruteForce' 와 'BFS Search' 을 이용하여 문제를 해결하였습니다. (This article is about Baekjoon Number 14502 'Lab' problem. We solved the problem using 'BruteForce' and 'BFS Search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14502%eb%b2%88-%ec%97%b0%ea%b5%ac%ec%86%8c-c-baekjoon/35759/">백준 14502번 (연구소, 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-827569d8      "
					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></ul></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">연구소</h1>



<p><a href="https://www.acmicpc.net/problem/14502" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/14502</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">2 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">83491</td><td class="has-text-align-left" data-align="left">47994</td><td class="has-text-align-left" data-align="left">26670</td><td class="has-text-align-left" data-align="left">54.824%</td></tr></tbody></table></figure>



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



<h3 class="wp-block-heading has-large-font-size">문제</h3>



<p>인체에 치명적인 바이러스를 연구하던 연구소에서 바이러스가 유출되었다. </p>



<p>다행히 바이러스는 아직 퍼지지 않았고, 바이러스의 확산을 막기 위해서 연구소에 벽을 세우려고 한다.</p>



<p>연구소는 크기가 N×M인 직사각형으로 나타낼 수 있으며, 직사각형은 1×1 크기의 정사각형으로 나누어져 있다. </p>



<p>연구소는 빈 칸, 벽으로 이루어져 있으며, 벽은 칸 하나를 가득 차지한다. </p>



<p>일부 칸은 바이러스가 존재하며, 이 바이러스는 상하좌우로 인접한 빈 칸으로 모두 퍼져나갈 수 있다. </p>



<p>새로 세울 수 있는 벽의 개수는 3개이며, 꼭 3개를 세워야 한다.</p>



<p>예를 들어, 아래와 같이 연구소가 생긴 경우를 살펴보자.</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="">2 0 0 0 1 1 0
0 0 1 0 1 2 0
0 1 1 0 1 0 0
0 1 0 0 0 0 0
0 0 0 0 0 1 1
0 1 0 0 0 0 0
0 1 0 0 0 0 0</pre>



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



<p>이때, 0은 빈 칸, 1은 벽, 2는 바이러스가 있는 곳이다. 아무런 벽을 세우지 않는다면, 바이러스는 모든 빈 칸으로 퍼져나갈 수 있다.</p>



<p>2행 1열, 1행 2열, 4행 6열에 벽을 세운다면 지도의 모양은 아래와 같아지게 된다.</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="">2 1 0 0 1 1 0
1 0 1 0 1 2 0
0 1 1 0 1 0 0
0 1 0 0 0 1 0
0 0 0 0 0 1 1
0 1 0 0 0 0 0
0 1 0 0 0 0 0</pre>



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



<p>바이러스가 퍼진 뒤의 모습은 아래와 같아진다.</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="">2 1 0 0 1 1 2
1 0 1 0 1 2 2
0 1 1 0 1 2 2
0 1 0 0 0 1 2
0 0 0 0 0 1 1
0 1 0 0 0 0 0
0 1 0 0 0 0 0</pre>



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



<p>벽을 3개 세운 뒤, 바이러스가 퍼질 수 없는 곳을 안전 영역이라고 한다. </p>



<p>위의 지도에서 안전 영역의 크기는 27이다.</p>



<p>연구소의 지도가 주어졌을 때 얻을 수 있는 안전 영역 크기의 최댓값을 구하는 프로그램을 작성하시오.</p>



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



<h3 class="wp-block-heading has-large-font-size">입력</h3>



<p>첫째 줄에 지도의 세로 크기 N과 가로 크기 M이 주어진다. (3 ≤ N, M ≤ 8)</p>



<p>둘째 줄부터 N개의 줄에 지도의 모양이 주어진다. </p>



<p>0은 빈 칸, 1은 벽, 2는 바이러스가 있는 위치이다. </p>



<p>2의 개수는 2보다 크거나 같고, 10보다 작거나 같은 자연수이다.</p>



<p>빈 칸의 개수는 3개 이상이다.</p>



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



<h3 class="wp-block-heading has-large-font-size">출력</h3>



<p>첫째 줄에 얻을 수 있는 안전 영역의 최대 크기를 출력한다.</p>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 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="">7 7
2 0 0 0 1 1 0
0 0 1 0 1 2 0
0 1 1 0 1 0 0
0 1 0 0 0 0 0
0 0 0 0 0 1 1
0 1 0 0 0 0 0
0 1 0 0 0 0 0</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 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="">27</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 2</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 6
0 0 0 0 0 0
1 0 0 0 0 2
1 1 1 0 0 2
0 0 0 0 0 2</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 출력 2</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="">9</pre>



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



<h3 class="wp-block-heading has-large-font-size">예제 입력 3</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="">8 8
2 0 0 0 0 0 0 2
2 0 0 0 0 0 0 2
2 0 0 0 0 0 0 2
2 0 0 0 0 0 0 2
2 0 0 0 0 0 0 2
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:40px" aria-hidden="true" class="wp-block-spacer"></div>



<h3 class="wp-block-heading has-large-font-size">예제 출력 3</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="">3</pre>



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



<h3 class="wp-block-heading has-large-font-size">출처</h3>



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



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



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



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



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



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



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



<p>N과 M의 범위 (3 ≤ N, M ≤ 8) 와 주어진 시간을 보고 Brute Force 를 사용해도 된다고 생각했다.</p>



<p>모든 칸이 빈칸이라는 가정 하에 나올 수 있는 경우의 수는 64 * 63 * 62 (순열) = 249,984 이므로 주어진 시간내에 연산이 가능할 것이다.</p>



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



<p>바이러스가 퍼지는 것은 BFS 탐색으로 구현하여 탐색이 끝난 후 남은 빈 공간의 개수를 확인하는 방법으로 진행하였다. </p>



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



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



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#include &lt;iostream>
#include &lt;vector>
#include &lt;queue>
using namespace std;
int _N, _M, _MapArr[8][8], _Res = 0, _Temp, _BlankCnt;
// 상, 하, 좌, 우 탐색
int _DxDy[4][2] = { {1,0}, {-1,0}, {0,1}, {0,-1} };
vector&lt;pair&lt;int, int>> _BlankV; // 빈공간의 좌표를 담는 벡터
vector&lt;pair&lt;int, int>> _VirusV; // 바이러스의 좌표를 담는 벡터
queue&lt;pair&lt;int, int>> _MyQueue; // BFS 탐색을 위한 큐
vector&lt;pair&lt;int, int>> _TVirusV; // BFS 탐색 후 맵 초기화를 위한 벡터

int BFS_Search()
{
	// 벽 3개는 무조건 만들어야 한다.
	int _blankCnt = _BlankCnt - 3;
	_TVirusV.clear();
	for (auto&amp; it : _VirusV) 
		_MyQueue.push(it);
	pair&lt;int, int> _CntPos;
	while (!_MyQueue.empty()) {
		_CntPos = _MyQueue.front();
		_MyQueue.pop();
		for (int i = 0; i &lt; 4; i++) {
			int _dx = _CntPos.first + _DxDy[i][0];
			int _dy = _CntPos.second + _DxDy[i][1];
			// 범위를 벗어남
			if (_dx >= _N || _dx &lt; 0 || _dy >= _M || _dy &lt; 0) continue;
			if (_MapArr[_dx][_dy] != 0) continue;
			_MapArr[_dx][_dy] = 2;
			_blankCnt--;
			_TVirusV.push_back(make_pair(_dx, _dy));
			_MyQueue.push(make_pair(_dx,_dy));
		}
	}
	for (auto&amp; it : _TVirusV) // 다음 탐색을 위해서 맵을 초기화
		_MapArr[it.first][it.second] = 0;
	return _blankCnt;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> _N >> _M;
	for (int i = 0; i &lt; _N; i++) 
		for (int j = 0; j &lt; _M; j++) {
			cin >> _Temp;
			if (_Temp == 0) // 빈 공간의 초기 좌표를 담는다
				_BlankV.push_back(make_pair(i, j));
			else if (_Temp == 2) // 바이러스의 초기 좌표를 담는다
				_VirusV.push_back(make_pair(i, j));
			_MapArr[i][j] = _Temp;
		}
	// 초기 빈공간의 개수를 카운팅
	_BlankCnt = _BlankV.size();
	// 순열 조합을 위한 3중 For문
	for (int i = 0; i &lt; _BlankCnt; i++) {
		_MapArr[_BlankV[i].first][_BlankV[i].second] = 1;
		for (int j = i + 1; j &lt; _BlankCnt; j++) {
			_MapArr[_BlankV[j].first][_BlankV[j].second] = 1;
			for (int k = j + 1; k &lt; _BlankCnt; k++) {
				_MapArr[_BlankV[k].first][_BlankV[k].second] = 1;
				// BruteForce 
				// 벽을 추가 할 수 있는 모든 경우의 수를 확인
				_Temp = BFS_Search();
				if (_Temp > _Res)
					_Res = _Temp;
				_MapArr[_BlankV[k].first][_BlankV[k].second] = 0;
			}
			_MapArr[_BlankV[j].first][_BlankV[j].second] = 0;
		}
		_MapArr[_BlankV[i].first][_BlankV[i].second] = 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"><img decoding="async" width="1207" height="99" src="https://lycos7560.com/wp-content/uploads/2023/07/image-16.png" alt="" class="wp-image-35771" srcset="https://lycos7560.com/wp-content/uploads/2023/07/image-16.png 1207w, https://lycos7560.com/wp-content/uploads/2023/07/image-16-300x25.png 300w, https://lycos7560.com/wp-content/uploads/2023/07/image-16-768x63.png 768w" sizes="(max-width: 1207px) 100vw, 1207px" /></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></p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14502%eb%b2%88-%ec%97%b0%ea%b5%ac%ec%86%8c-c-baekjoon/35759/">백준 14502번 (연구소, 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-14502%eb%b2%88-%ec%97%b0%ea%b5%ac%ec%86%8c-c-baekjoon/35759/feed/</wfw:commentRss>
			<slash:comments>0</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>Programmers 60063 블록 이동하기 [2020 KAKAO BLIND RECRUITMENT]</title>
		<link>https://lycos7560.com/cpp/programmers/programmers-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/</link>
					<comments>https://lycos7560.com/cpp/programmers/programmers-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 14 Apr 2023 12:20:12 +0000</pubDate>
				<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[[2020 KAKAO BLIND RECRUITMENT]]]></category>
		<category><![CDATA[2020 KAKAO BLIND RECRUITMENT]]></category>
		<category><![CDATA[60063]]></category>
		<category><![CDATA[60063번]]></category>
		<category><![CDATA[BFS]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[Programmers 60063]]></category>
		<category><![CDATA[Programmers 60063번]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[너비]]></category>
		<category><![CDATA[너비 우선 탐색]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[블록 이동하기]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<category><![CDATA[프로그래머스]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=34310</guid>

					<description><![CDATA[<p>Programmers 60063번 '블록 이동하기' 문제에 대한 글입니다. BFS 탐색 및 브루트포스 알고리즘을 이용하여 해결하였습니다. This article is about Programmers 60063 'Move Block' It was solved using the BFS search and Bruteforce algorithm. [2020 KAKAO BLIND RECRUITMENT]</p>
<p>The post <a href="https://lycos7560.com/cpp/programmers/programmers-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/">Programmers 60063 블록 이동하기 [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-52368673      "
					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><a href="https://school.programmers.co.kr/learn/courses/30/lessons/60063" target="_blank" rel="noreferrer noopener">https://school.programmers.co.kr/lear</a><a href="https://school.programmers.co.kr/learn/courses/30/lessons/60063">n/courses/30/lessons/60063</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>는 한 달 앞으로 다가온 &#8220;카카오배 로봇경진대회&#8221;에 출품할&nbsp;<strong>로봇</strong>을 준비하고 있습니다. </p>



<p class="has-medium-font-size">준비 중인 로봇은&nbsp;<strong><code>2 x 1</code></strong>&nbsp;크기의 로봇으로 &#8220;무지&#8221;는&nbsp;<strong>&#8220;0&#8221;</strong>과&nbsp;<strong>&#8220;1&#8221;</strong>로 이루어진&nbsp;<strong><code>N x N</code></strong>&nbsp;크기의 지도에서&nbsp;<strong><code>2 x 1</code></strong>&nbsp;크기인 로봇을 움직여&nbsp;</p>



<p class="has-medium-font-size"><strong>(N, N)</strong>&nbsp;위치까지 이동 할 수 있도록 프로그래밍을 하려고 합니다. 로봇이 이동하는 지도는 가장 왼쪽, 상단의 좌표를&nbsp;<strong>(1, 1)</strong>로 하며 </p>



<p class="has-medium-font-size">지도 내에 표시된 숫자&nbsp;<strong>&#8220;0&#8221;</strong>은 빈칸을&nbsp;<strong>&#8220;1&#8221;</strong>은 벽을 나타냅니다. 로봇은 벽이 있는 칸 또는 지도 밖으로는 이동할 수 없습니다. </p>



<p class="has-medium-font-size">로봇은 처음에 아래 그림과 같이 좌표&nbsp;<strong>(1, 1)</strong>&nbsp;위치에서 가로방향으로 놓여있는 상태로 시작하며, 앞뒤 구분없이 움직일 수 있습니다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="783" height="787" src="https://lycos7560.com/wp-content/uploads/2023/04/image-10.png" alt="" class="wp-image-34312" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-10.png 783w, https://lycos7560.com/wp-content/uploads/2023/04/image-10-298x300.png 298w, https://lycos7560.com/wp-content/uploads/2023/04/image-10-150x150.png 150w, https://lycos7560.com/wp-content/uploads/2023/04/image-10-768x772.png 768w" sizes="(max-width: 783px) 100vw, 783px" /></figure>



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



<p class="has-medium-font-size">로봇이 움직일 때는 현재 놓여있는 상태를 유지하면서 이동합니다. </p>



<p class="has-medium-font-size">예를 들어, 위 그림에서 오른쪽으로 한 칸 이동한다면&nbsp;<strong>(1, 2), (1, 3)</strong>&nbsp;두 칸을 차지하게 되며, </p>



<p class="has-medium-font-size">아래로 이동한다면&nbsp;<strong>(2, 1), (2, 2)</strong>&nbsp;두 칸을 차지하게 됩니다. </p>



<p class="has-medium-font-size">로봇이 차지하는 두 칸 중 어느 한 칸이라도&nbsp;<strong>(N, N)</strong>&nbsp;위치에 도착하면 됩니다.</p>



<p class="has-medium-font-size">로봇은 다음과 같이 조건에 따라 회전이 가능합니다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="788" height="789" src="https://lycos7560.com/wp-content/uploads/2023/04/image-11.jpg" alt="" class="wp-image-34313" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-11.jpg 788w, https://lycos7560.com/wp-content/uploads/2023/04/image-11-300x300.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/04/image-11-150x150.jpg 150w, https://lycos7560.com/wp-content/uploads/2023/04/image-11-768x769.jpg 768w" sizes="(max-width: 788px) 100vw, 788px" /></figure>



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



<p class="has-medium-font-size">위 그림과 같이 로봇은 90도씩 회전할 수 있습니다. </p>



<p class="has-medium-font-size">단, 로봇이 차지하는 두 칸 중, 어느 칸이든 축이 될 수 있지만, </p>



<p class="has-medium-font-size">회전하는 방향(축이 되는 칸으로부터 대각선 방향에 있는 칸)에는 벽이 없어야 합니다. </p>



<p class="has-medium-font-size">로봇이 한 칸 이동하거나 90도 회전하는 데는 걸리는 시간은 정확히 1초 입니다.</p>



<p class="has-medium-font-size"><strong>&#8220;0&#8221;</strong>과&nbsp;<strong>&#8220;1&#8221;</strong>로 이루어진 지도인 board가 주어질 때, </p>



<p class="has-medium-font-size">로봇이&nbsp;<strong>(N, N)</strong>&nbsp;위치까지 이동하는데 필요한 최소 시간을 return 하도록 solution 함수를 완성해주세요.</p>



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



<h3 class="wp-block-heading">제한사항</h3>



<p class="has-small-font-size">board의 한 변의 길이는 5 이상 100 이하입니다.</p>



<p class="has-small-font-size">board의 원소는 0 또는 1입니다.</p>



<p class="has-small-font-size">로봇이 처음에 놓여 있는 칸 (1, 1), (1, 2)는 항상 0으로 주어집니다.</p>



<p class="has-small-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">board</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">[[0, 0, 0, 1, 1],[0, 0, 0, 1, 0],[0, 1, 0, 1, 1],[1, 1, 0, 0, 1],[0, 0, 0, 0, 0]]</td><td class="has-text-align-left" data-align="left">7</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">문제에 주어진 예시와 같습니다.</p>



<p class="has-medium-font-size">로봇이 오른쪽으로 한 칸 이동 후, (1, 3) 칸을 축으로 반시계 방향으로 90도 회전합니다. </p>



<p class="has-medium-font-size">다시, 아래쪽으로 3칸 이동하면 로봇은 (4, 3), (5, 3) 두 칸을 차지하게 됩니다. </p>



<p class="has-medium-font-size">이제 (5, 3)을 축으로 시계 방향으로 90도 회전 후, 오른쪽으로 한 칸 이동하면 (N, N)에 도착합니다. </p>



<p class="has-medium-font-size">따라서 목적지에 도달하기까지 최소 7초가 걸립니다.</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>



<figure class="wp-block-image size-full"><img decoding="async" width="1125" height="1280" src="https://lycos7560.com/wp-content/uploads/2023/04/Notes_230414_203835-2-2.jpg" alt="" class="wp-image-34336" srcset="https://lycos7560.com/wp-content/uploads/2023/04/Notes_230414_203835-2-2.jpg 1125w, https://lycos7560.com/wp-content/uploads/2023/04/Notes_230414_203835-2-2-264x300.jpg 264w, https://lycos7560.com/wp-content/uploads/2023/04/Notes_230414_203835-2-2-768x874.jpg 768w" sizes="(max-width: 1125px) 100vw, 1125px" /></figure>



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



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

using namespace std;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

bool _MapArr[101][101][2];

// 로봇의 위치 및 현재 시간
tuple&lt;int, int, int, int, int> _RobotPos;
// bfs 탐색을 위한 q
queue&lt;tuple&lt;int, int, int, int, int>> _RobotPosQ;

int solution(vector&lt;vector&lt;int>> board) {
    int answer = 0;
    int _MapMax = board.size();
    pair&lt;int, int> _goal = make_pair(_MapMax - 1, _MapMax - 1); // 목표를 설정

    _RobotPos = make_tuple(0, 0, 0, 1, 0); // 로봇의 위치 초기값
    _RobotPosQ.push(_RobotPos); // 로봇의 시작를 큐에 넣기
    _MapArr[0][0][0] = true; // 방문 마킹
    _MapArr[0][1][0] = true;
    // board 는 0,0 에서 시작
    // 마킹은 1,1에서 시작


    // bfs 탐색 시작
    while (_RobotPosQ.size() > 0) {
        _RobotPos = _RobotPosQ.front();
        _RobotPosQ.pop();
        pair&lt;int, int> _CntPosOne = make_pair(get&lt;0>(_RobotPos), get&lt;1>(_RobotPos)); // 로봇의 현재 x, y 위치 1
        pair&lt;int, int> _CntPosTwo = make_pair(get&lt;2>(_RobotPos), get&lt;3>(_RobotPos)); // 로봇의 현재 x, y 위치 2
        int _cnttime = get&lt;4>(_RobotPos);
        if (_CntPosOne == _goal || _CntPosTwo == _goal) {
            answer = _cnttime;
            break;
        }
        bool _robotstatus; // true 세로, false 가로
        // 상 하 좌 우를 탐색
        for (int i = 0; i &lt; 4; i++) {

            pair&lt;int, int> _TempPosOne, _TempPosTwo;
            _TempPosOne.first = _CntPosOne.first + dxdy[i][0];
            _TempPosOne.second = _CntPosOne.second + dxdy[i][1];
            _TempPosTwo.first = _CntPosTwo.first + dxdy[i][0];
            _TempPosTwo.second = _CntPosTwo.second + dxdy[i][1];

            // 가로 세로 비교
            if (_CntPosOne.first + 1 == _CntPosTwo.first || _CntPosOne.first - 1 == _CntPosTwo.first) _robotstatus = true; // 세로
            else _robotstatus = false;

            // 벽이라면 넘어간다.
            if (_TempPosOne.first &lt; 0 || _TempPosOne.first >= _MapMax || _TempPosOne.second &lt; 0 || _TempPosOne.second >= _MapMax) continue;
            if (_TempPosTwo.first &lt; 0 || _TempPosTwo.first >= _MapMax || _TempPosTwo.second &lt; 0 || _TempPosTwo.second >= _MapMax) continue;
            if (board[_TempPosOne.first][_TempPosOne.second] == 1 || board[_TempPosTwo.first][_TempPosTwo.second] == 1) continue;

            // 두 부분이 방문한 적이 있다면 넘어간다.
            if (_MapArr[_TempPosOne.first][_TempPosOne.second][_robotstatus] == true &amp;&amp; _MapArr[_TempPosTwo.first][_TempPosTwo.second][_robotstatus] == true) continue;

            _RobotPos = make_tuple(_TempPosOne.first, _TempPosOne.second, _TempPosTwo.first, _TempPosTwo.second, _cnttime + 1);
            _RobotPosQ.push(_RobotPos); // 로봇의 시작를 큐에 넣기
            _MapArr[_TempPosOne.first][_TempPosOne.second][_robotstatus] = true; // 방문 마킹
            _MapArr[_TempPosTwo.first][_TempPosTwo.second][_robotstatus] = true;

        }

        // 방향 전환
        if (!_robotstatus) { // 가로
            if (_CntPosOne.first + 1 &lt; _MapMax &amp;&amp; board[_CntPosOne.first + 1][_CntPosOne.second] != 1 &amp;&amp; board[_CntPosTwo.first + 1][_CntPosTwo.second] != 1) {
                if (_MapArr[_CntPosTwo.first + 1][_CntPosTwo.second][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosTwo.first + 1, _CntPosTwo.second, _CntPosTwo.first, _CntPosTwo.second, _cnttime + 1);
                    _MapArr[_CntPosTwo.first + 1][_CntPosTwo.second][!_robotstatus] = true;
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosOne.first - 1 >= 0 &amp;&amp; board[_CntPosOne.first - 1][_CntPosOne.second] != 1 &amp;&amp; board[_CntPosTwo.first - 1][_CntPosTwo.second] != 1) {
                if (_MapArr[_CntPosTwo.first - 1][_CntPosTwo.second][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosTwo.first - 1, _CntPosTwo.second, _CntPosTwo.first, _CntPosTwo.second, _cnttime + 1);
                    _MapArr[_CntPosTwo.first - 1][_CntPosTwo.second][!_robotstatus] = true;
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosTwo.first + 1 &lt; _MapMax &amp;&amp; board[_CntPosTwo.first + 1][_CntPosTwo.second] != 1 &amp;&amp; board[_CntPosOne.first + 1][_CntPosOne.second] != 1) {
                if (_MapArr[_CntPosOne.first + 1][_CntPosOne.second][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosOne.first + 1, _CntPosOne.second, _CntPosOne.first, _CntPosOne.second, _cnttime + 1);
                    _MapArr[_CntPosOne.first + 1][_CntPosOne.second][!_robotstatus] = true;
                    _MapArr[_CntPosOne.first][_CntPosOne.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosTwo.first - 1 >= 0 &amp;&amp; board[_CntPosTwo.first - 1][_CntPosTwo.second] != 1 &amp;&amp; board[_CntPosOne.first - 1][_CntPosOne.second] != 1) {
                if (_MapArr[_CntPosOne.first - 1][_CntPosOne.second][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosOne.first - 1, _CntPosOne.second, _CntPosOne.first, _CntPosOne.second, _cnttime + 1);
                    _MapArr[_CntPosOne.first - 1][_CntPosOne.second][!_robotstatus] = true;
                    _MapArr[_CntPosOne.first][_CntPosOne.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
        }
        else {
            if (_CntPosOne.second + 1 &lt; _MapMax &amp;&amp; board[_CntPosOne.first][_CntPosOne.second + 1] != 1 &amp;&amp; board[_CntPosTwo.first][_CntPosTwo.second + 1] != 1) {
                if (_MapArr[_CntPosTwo.first][_CntPosTwo.second + 1][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosTwo.first, _CntPosTwo.second + 1, _CntPosTwo.first, _CntPosTwo.second, _cnttime + 1);
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second + 1][!_robotstatus] = true;
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosOne.second - 1 >= 0 &amp;&amp; board[_CntPosOne.first][_CntPosOne.second - 1] != 1 &amp;&amp; board[_CntPosTwo.first][_CntPosTwo.second - 1] != 1) {
                if (_MapArr[_CntPosTwo.first][_CntPosTwo.second - 1][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosTwo.first, _CntPosTwo.second - 1, _CntPosTwo.first, _CntPosTwo.second, _cnttime + 1);
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second - 1][!_robotstatus] = true;
                    _MapArr[_CntPosTwo.first][_CntPosTwo.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosTwo.second + 1 &lt; _MapMax &amp;&amp; board[_CntPosTwo.first][_CntPosTwo.second + 1] != 1 &amp;&amp; board[_CntPosOne.first][_CntPosOne.second + 1] != 1) {
                if (_MapArr[_CntPosOne.first][_CntPosOne.second + 1][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosOne.first, _CntPosOne.second + 1, _CntPosOne.first, _CntPosOne.second, _cnttime + 1);
                    _MapArr[_CntPosOne.first][_CntPosOne.second + 1][!_robotstatus] = true;
                    _MapArr[_CntPosOne.first][_CntPosOne.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }
            if (_CntPosTwo.second - 1 >= 0 &amp;&amp; board[_CntPosTwo.first][_CntPosTwo.second - 1] != 1 &amp;&amp; board[_CntPosOne.first][_CntPosOne.second - 1] != 1) {
                if (_MapArr[_CntPosOne.first][_CntPosOne.second - 1][!_robotstatus] == false) {
                    _RobotPos = make_tuple(_CntPosOne.first, _CntPosOne.second - 1, _CntPosOne.first, _CntPosOne.second, _cnttime + 1);
                    _MapArr[_CntPosOne.first][_CntPosOne.second - 1][!_robotstatus] = true;
                    _MapArr[_CntPosOne.first][_CntPosOne.second][!_robotstatus] = true;
                    _RobotPosQ.push(_RobotPos);
                }
            }

        }

    }

    return answer;
}</pre>



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



<figure class="wp-block-image size-full"><img decoding="async" width="686" height="429" src="https://lycos7560.com/wp-content/uploads/2023/04/image-12.png" alt="" class="wp-image-34318" srcset="https://lycos7560.com/wp-content/uploads/2023/04/image-12.png 686w, https://lycos7560.com/wp-content/uploads/2023/04/image-12-300x188.png 300w" sizes="(max-width: 686px) 100vw, 686px" /></figure>



<div style="height:50px" 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-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/">Programmers 60063 블록 이동하기 [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-60063-%eb%b8%94%eb%a1%9d-%ec%9d%b4%eb%8f%99%ed%95%98%ea%b8%b0-2020-kakao-blind-recruitment/34310/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 14500번 (테트로미노, C++) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Thu, 16 Feb 2023 01:53:01 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[14500]]></category>
		<category><![CDATA[14500번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[반례]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 14500]]></category>
		<category><![CDATA[백준 14500번]]></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=33194</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 14500번 '테트로미노' 문제에 대한 글입니다. 'brute force' 알고리즘과 'DFS 탐색'을 이용하여 해결하였습니다. (This is BAEKJOON's 14500 article on the 'Tetromino' problem. It was solved using the 'brute force' algorithm and 'DFS search'.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/">백준 14500번 (테트로미노, 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-6eabfa96      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							목차 테이블						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#테트로미노" class="uagb-toc-link__trigger">테트로미노</a><li class="uagb-toc__list"><a href="#통과된-코드" class="uagb-toc-link__trigger">통과된 코드</a><li class="uagb-toc__list"><a href="#추가-반례" class="uagb-toc-link__trigger">추가 반례</a></ol>					</div>
									</div>
				</div>
			


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



<h1 class="wp-block-heading">테트로미노</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/14500" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/14500</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">69583</td><td class="has-text-align-left" data-align="left">26178</td><td class="has-text-align-left" data-align="left">17011</td><td class="has-text-align-left" data-align="left">35.673%</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">폴리오미노란 크기가 1×1인 정사각형을 여러 개 이어서 붙인 도형이며, 다음과 같은 조건을 만족해야 한다.</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>



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



<p class="has-medium-font-size">정사각형 4개를 이어 붙인 폴리오미노는 테트로미노라고 하며, 다음과 같은 5가지가 있다.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="488" height="308" src="https://lycos7560.com/wp-content/uploads/2023/02/image-73.png" alt="" class="wp-image-33195" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-73.png 488w, https://lycos7560.com/wp-content/uploads/2023/02/image-73-300x189.png 300w" sizes="(max-width: 488px) 100vw, 488px" /></figure>



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



<p class="has-medium-font-size">아름이는 크기가 N×M인 종이 위에 테트로미노 하나를 놓으려고 한다. </p>



<p class="has-medium-font-size">종이는 1×1 크기의 칸으로 나누어져 있으며, 각각의 칸에는 정수가 하나 쓰여 있다.</p>



<p class="has-medium-font-size">테트로미노 하나를 적절히 놓아서 테트로미노가 놓인 칸에 쓰여 있는 수들의 합을 최대로 하는 프로그램을 작성하시오.</p>



<p class="has-medium-font-size">테트로미노는 반드시 한 정사각형이 정확히 하나의 칸을 포함하도록 놓아야 하며, 회전이나 대칭을 시켜도 된다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 종이의 세로 크기 N과 가로 크기 M이 주어진다. (4&nbsp;≤ N, M ≤ 500)</p>



<p class="has-medium-font-size">둘째 줄부터 N개의 줄에 종이에 쓰여 있는 수가 주어진다. </p>



<p class="has-medium-font-size">i번째 줄의 j번째 수는 위에서부터 i번째 칸, 왼쪽에서부터 j번째 칸에 쓰여 있는 수이다. </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="">5 5
1 2 3 4 5
5 4 3 2 1
2 3 4 5 6
6 5 4 3 2
1 2 1 2 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="">19</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="">4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5</pre>



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



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



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



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



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



<ul class="wp-block-list">
<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/appie701" target="_blank" rel="noreferrer noopener">appie701</a>, <a href="https://www.acmicpc.net/user/crookid" target="_blank" rel="noreferrer noopener">crookid</a>, <a href="https://www.acmicpc.net/user/esuperstar" target="_blank" rel="noreferrer noopener">esuperstar</a>, <a href="https://www.acmicpc.net/user/raboribus" target="_blank" rel="noreferrer noopener">raboribus</a>, <a href="https://www.acmicpc.net/user/rlatpwlsdlek" target="_blank" rel="noreferrer noopener">rlatpwlsdlek</a>, <a href="https://www.acmicpc.net/user/stack" target="_blank" rel="noreferrer noopener">stack</a>, <a href="https://www.acmicpc.net/user/vjerksen" target="_blank" rel="noreferrer noopener">vjerksen</a></li>



<li>문제를 만든 사람: <a href="https://www.acmicpc.net/user/baekjoon">baek</a><a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">j</a><a href="https://www.acmicpc.net/user/baekjoon">oon</a></li>



<li>문제의 오타를 찾은 사람: <a href="https://www.acmicpc.net/user/bluebrown" target="_blank" rel="noreferrer noopener">bluebrown</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/125" 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-image size-full"><img decoding="async" width="389" height="284" src="https://lycos7560.com/wp-content/uploads/2023/02/image-75.png" alt="" class="wp-image-33204" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-75.png 389w, https://lycos7560.com/wp-content/uploads/2023/02/image-75-300x219.png 300w" sizes="(max-width: 389px) 100vw, 389px" /></figure>



<p class="has-medium-font-size">DFS 탐색</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="283" height="161" src="https://lycos7560.com/wp-content/uploads/2023/02/image-77.png" alt="" class="wp-image-33206"/></figure>



<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">통과된 코드</h1>



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



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

using namespace std;

constexpr int MAX = 500;

int map[MAX][MAX];

bool checkMap[MAX][MAX];

int N, M, result = 0;

// 탐색하는 방향 설정 =>  상, 하 ,좌 ,우
int dxdy[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

void DFS_Search(int nowX, int nowY, int cnt, int val)
{
	if (cnt == 4) {
		result = max(result, val);
		return;
	}

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

		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];

		// 범위를 벗어나면 넘어간다.
		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) continue;
		// 방문했다면 넘어간다.
		if (checkMap[dx][dy] == true) continue;

		cnt++;
		val += map[dx][dy];
		checkMap[dx][dy] = true;
		DFS_Search(dx, dy, cnt, val);
		checkMap[dx][dy] = false;
		cnt--;
		val -= map[dx][dy];

	}
}

// 'ㅗ' 탐색을 위한 함수
void Exception_Search(int nowX, int nowY, int val)
{
	for (int i = 0; i &lt; 4; i++) {
		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];
		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) continue;
		val += map[dx][dy];
	}

	for (int i = 0; i &lt; 4; i++) {
		int dx = nowX + dxdy[i][0];
		int dy = nowY + dxdy[i][1];

		if (dx &lt; 0 || dy &lt; 0 || dx >= N || dy >= M) {
			result = max(result, val);
			continue;
		}

		val -= map[dx][dy];
		result = max(result, val);
		val += map[dx][dy];
	}

}


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

	cin >> N >> M;

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

	for (int i = 0; i &lt; N; i++) {
		for (int j = 0; j &lt; M; j++) {
			checkMap[i][j] = true;
			DFS_Search(i, j, 1, map[i][j]);
			checkMap[i][j] = false;
			Exception_Search(i, j, map[i][j]);
		}
	}

	cout &lt;&lt; result;

	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/02/image-74.png" alt="" class="wp-image-33198" width="877" height="150" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-74.png 746w, https://lycos7560.com/wp-content/uploads/2023/02/image-74-300x51.png 300w" sizes="(max-width: 877px) 100vw, 877px" /></figure>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1292" height="646" src="https://lycos7560.com/wp-content/uploads/2023/02/image-79.png" alt="" class="wp-image-33209" srcset="https://lycos7560.com/wp-content/uploads/2023/02/image-79.png 1292w, https://lycos7560.com/wp-content/uploads/2023/02/image-79-300x150.png 300w, https://lycos7560.com/wp-content/uploads/2023/02/image-79-768x384.png 768w" sizes="(max-width: 1292px) 100vw, 1292px" /></figure>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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

4 4
0 0 0 1
0 0 0 2
0 0 0 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 0 1 2
0 0 3 4

4 4
0 0 0 0
0 0 1 0
0 0 2 0
0 0 3 4

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 4 0 0

4 4
0 0 0 0
0 0 1 2
0 0 0 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 0 0 1
0 4 3 2

4 4
0 0 0 0
0 0 0 1
0 0 0 2
0 0 4 3

4 4
0 0 0 0
0 0 0 0
0 1 0 0
0 2 3 4

4 4
0 0 0 0
0 0 2 1
0 0 3 0
0 0 4 0

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 0 0 4

4 4
0 0 0 0
0 0 0 1
0 0 2 3
0 0 4 0

4 4
0 0 0 0
0 0 1 0
0 0 2 3
0 0 0 4

4 4
0 0 0 0
0 0 0 0
0 1 2 0
0 0 3 4

4 4
0 0 0 0
0 0 0 0
0 0 3 4
0 1 2 0

4 4
0 0 0 0
0 0 0 1
0 0 2 3
0 0 0 4

4 4
0 0 0 0
0 0 1 0
0 0 2 3
0 0 4 0

4 4
0 0 0 0
0 0 0 0
0 0 1 0
0 2 3 4

4 4
0 0 0 0
0 0 0 0
0 1 2 3
0 0 4 0</pre>



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



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



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



<div style="height:60px" 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-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/">백준 14500번 (테트로미노, 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-14500%eb%b2%88-%ed%85%8c%ed%8a%b8%eb%a1%9c%eb%af%b8%eb%85%b8-c-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/33194/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 17626번 (Four Squares 4, C++, DP) [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Mon, 30 Jan 2023 06:50:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[17626]]></category>
		<category><![CDATA[17626번]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[DP]]></category>
		<category><![CDATA[DynamicProgramming]]></category>
		<category><![CDATA[Four Squares 4]]></category>
		<category><![CDATA[study]]></category>
		<category><![CDATA[공부]]></category>
		<category><![CDATA[기본]]></category>
		<category><![CDATA[기초]]></category>
		<category><![CDATA[다이나믹 프로그래밍]]></category>
		<category><![CDATA[백준]]></category>
		<category><![CDATA[백준 17626]]></category>
		<category><![CDATA[백준 17626번]]></category>
		<category><![CDATA[브루트 포스]]></category>
		<category><![CDATA[알고리즘]]></category>
		<category><![CDATA[코딩테스트]]></category>
		<category><![CDATA[코테]]></category>
		<guid isPermaLink="false">https://lycos7560.com/?p=5731</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 17626번 'Four Squares 4' 문제에 대한 글입니다. '다이나믹 프로그래밍' 알고리즘을 이용하여 해결하였습니다. (This is an article on the question of 'Four Squares 4' in BAEKJOON No. 17626 It was solved using the 'Dynamic Programming' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/">백준 17626번 (Four Squares 4, C++, DP) [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">Four Squares 4</h1>



<p class="has-medium-font-size"><a href="https://www.acmicpc.net/problem/17626" target="_blank" rel="noreferrer noopener">https://www.acmicpc.net/problem/17626</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">0.5 초</td><td class="has-text-align-left" data-align="left">512 MB</td><td class="has-text-align-left" data-align="left">17028</td><td class="has-text-align-left" data-align="left">7537</td><td class="has-text-align-left" data-align="left">5916</td><td class="has-text-align-left" data-align="left">44.794%</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">라그랑주는 1770년에 모든 자연수는 넷 혹은 그 이하의 제곱수의 합으로 표현할 수 있다고 증명하였다. </p>



<p class="has-medium-font-size">어떤 자연수는 복수의 방법으로 표현된다. </p>



<p class="has-medium-font-size">예를 들면, 26은 5<sup>2</sup>과 1<sup>2</sup>의 합이다; 또한 4<sup>2</sup> + 3<sup>2</sup> + 1<sup>2</sup>으로 표현할 수도 있다. </p>



<p class="has-medium-font-size">역사적으로 암산의 명수들에게 공통적으로 주어지는 문제가 </p>



<p class="has-medium-font-size">바로 자연수를 넷 혹은 그 이하의 제곱수 합으로 나타내라는 것이었다. </p>



<p class="has-medium-font-size">1900년대 초반에 한 암산가가 15663 = 125<sup>2</sup> + 6<sup>2</sup> + 1<sup>2</sup> + 1<sup>2</sup>라는 해를 구하는데 8초가 걸렸다는 보고가 있다. </p>



<p class="has-medium-font-size">좀 더 어려운 문제에 대해서는 56초가 걸렸다: 11339 = 105<sup>2</sup> + 15<sup>2</sup> + 8<sup>2</sup> + 5<sup>2</sup>.</p>



<p class="has-medium-font-size">자연수&nbsp;<em>n</em>이 주어질 때,&nbsp;<em>n</em>을 최소 개수의 제곱수 합으로 표현하는 컴퓨터 프로그램을 작성하시오.</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">입력은 표준입력을 사용한다. 입력은 자연수 <em>n</em>을 포함하는 한 줄로 구성된다. </p>



<p class="has-medium-font-size">여기서, 1 ≤ <em>n</em> ≤ 50,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>



<p class="has-medium-font-size">합이 <em>n</em>과 같게 되는 제곱수들의 최소 개수를 한 줄에 출력한다.</p>



<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="">25</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="">26</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="">2</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="">11339</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="">3</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="">34567</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="">4</pre>



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



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



<p><a href="https://www.acmicpc.net/category/1">I</a><a href="https://www.acmicpc.net/category/1" target="_blank" rel="noreferrer noopener">C</a><a href="https://www.acmicpc.net/category/1">PC</a> > <a href="https://www.acmicpc.net/category/7" target="_blank" rel="noreferrer noopener">Regionals</a> > <a href="https://www.acmicpc.net/category/42" target="_blank" rel="noreferrer noopener">Asia Pacific</a> > <a href="https://www.acmicpc.net/category/211" target="_blank" rel="noreferrer noopener">Korea</a> > <a href="https://www.acmicpc.net/category/256" target="_blank" rel="noreferrer noopener">Nationwide Internet Competition</a> > <a href="https://www.acmicpc.net/category/detail/2064" target="_blank" rel="noreferrer noopener">Seoul Nationalwide Internet Competition 2019</a> H번</p>



<ul class="wp-block-list">
<li>데이터를 추가한 사람: <a href="https://www.acmicpc.net/user/tktj12" target="_blank" rel="noreferrer noopener">tktj12</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/125" 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-image size-full"><img decoding="async" width="1600" height="1469" src="https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671.jpg" alt="" class="wp-image-5732" srcset="https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671.jpg 1600w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671-300x275.jpg 300w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671-768x705.jpg 768w, https://lycos7560.com/wp-content/uploads/2023/01/KakaoTalk_20230130_154139671-1536x1410.jpg 1536w" sizes="(max-width: 1600px) 100vw, 1600px" /></figure>



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



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



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



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

using namespace std;

int N;

int dp[50001];

int main()
{
	cin >> N;

	dp[1] = 1;

	for (int i = 2; i &lt;= N; i++) {
		int minN = INT32_MAX;
		for (int j = 1; j * j &lt;= i; j++) { // 모든 경우의 수를 확인
			int tmp = i - j * j;
			minN = min(minN, dp[tmp]);
		}
		dp[i] = minN + 1;
	}

	cout &lt;&lt; dp[N];

	return 0;
}</pre>



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



<figure class="wp-block-image size-full is-resized"><img decoding="async" src="https://lycos7560.com/wp-content/uploads/2023/01/image-39.png" alt="" class="wp-image-5733" width="1326" height="120" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-39.png 1030w, https://lycos7560.com/wp-content/uploads/2023/01/image-39-300x27.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-39-768x69.png 768w" sizes="(max-width: 1326px) 100vw, 1326px" /></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-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/">백준 17626번 (Four Squares 4, C++, DP) [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-17626%eb%b2%88-four-squares-4-c-baekjoon/5731/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [BAEKJOON]</title>
		<link>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/</link>
					<comments>https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Fri, 27 Jan 2023 17:25:46 +0000</pubDate>
				<category><![CDATA[BaekjoonOnlineJudge]]></category>
		<category><![CDATA[C++/CPP]]></category>
		<category><![CDATA[1107]]></category>
		<category><![CDATA[1107번]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Baekjoon]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cpp]]></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[백준 1107]]></category>
		<category><![CDATA[백준 1107번]]></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=5678</guid>

					<description><![CDATA[<p>백준(BAEKJOON) 1107번 '리모컨' 문제에 대한 글입니다. 'Brute Force' 알고리즘을 이용하여 해결하였습니다.<br />
(This is an article about the 'remote control' problem in BAEKJOON 1107. Solved using the 'Brute Force' algorithm.)</p>
<p>The post <a href="https://lycos7560.com/cpp/baekjoon_online_judge/%eb%b0%b1%ec%a4%80-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/">백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [BAEKJOON]</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671" crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-5698326622209671" data-ad-slot="6908948342" data-ad-format="auto" data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



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



<h1 class="wp-block-heading">리모컨</h1>



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



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



<figure id="problem-info" class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th class="has-text-align-left" data-align="left">시간 제한</th><th class="has-text-align-left" data-align="left">메모리 제한</th><th class="has-text-align-left" data-align="left">제출</th><th class="has-text-align-left" data-align="left">정답</th><th class="has-text-align-left" data-align="left">맞힌 사람</th><th class="has-text-align-left" data-align="left">정답 비율</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left">2 초</td><td class="has-text-align-left" data-align="left">256 MB</td><td class="has-text-align-left" data-align="left">82926</td><td class="has-text-align-left" data-align="left">20011</td><td class="has-text-align-left" data-align="left">13910</td><td class="has-text-align-left" data-align="left">22.624%</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">수빈이는 TV를 보고 있다. 수빈이는 채널을 돌리려고 했지만, 버튼을 너무 세게 누르는&nbsp;바람에, 일부 숫자 버튼이 고장났다.</p>



<p class="has-medium-font-size">리모컨에는 버튼이 0부터 9까지 숫자, +와 -가 있다. +를 누르면 현재 보고있는 채널에서 +1된 채널로 이동하고, </p>



<p class="has-medium-font-size">-를 누르면 -1된 채널로 이동한다. 채널 0에서 -를 누른 경우에는 채널이 변하지 않고, 채널은 무한대 만큼 있다.</p>



<p class="has-medium-font-size">수빈이가 지금 이동하려고 하는 채널은 N이다. 어떤 버튼이 고장났는지 주어졌을 때, </p>



<p class="has-medium-font-size">채널 N으로 이동하기 위해서 버튼을 최소 몇 번 눌러야하는지 구하는 프로그램을 작성하시오. </p>



<p class="has-medium-font-size">수빈이가 지금 보고 있는 채널은 100번이다.</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 (0 ≤ N ≤ 500,000)이 주어진다.  </p>



<p class="has-medium-font-size">둘째 줄에는 고장난 버튼의 개수 M (0 ≤ M ≤ 10)이 주어진다. </p>



<p class="has-medium-font-size">고장난 버튼이 있는 경우에는 셋째 줄에는 고장난 버튼이 주어지며, 같은 버튼이 여러 번 주어지는 경우는 없다.</p>



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



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



<p class="has-medium-font-size">첫째 줄에 채널 N으로 이동하기 위해 버튼을 최소 몇 번 눌러야 하는지를 출력한다.</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="">5457
3
6 7 8</pre>



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



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



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



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



<div style="height:40px" 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="">1
9
1 2 3 4 5 6 7 8 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="">2</pre>



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



<h2 class="wp-block-heading">예제 입력 7</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="">80000
2
8 9</pre>



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



<h2 class="wp-block-heading">예제 출력 7</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="">2228</pre>



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



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



<h2 class="wp-block-heading">예제 입력 F</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="">139133
7
9 6 8 2 1 5 7</pre>



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



<h2 class="wp-block-heading">예제 출력 F</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="">94694</pre>



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



<h2 class="wp-block-heading">예제 입력 G</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
0</pre>



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



<h2 class="wp-block-heading">예제 출력 G</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">힌트</h2>



<p class="has-medium-font-size">예제 1의 경우 5455++ 또는 5459&#8211;</p>



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



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



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



<li>문제를 번역한 사람: <a href="https://www.acmicpc.net/user/baekjoon" target="_blank" rel="noreferrer noopener">baekjoon</a></li>



<li>잘못된 조건을 찾은 사람: <a href="https://www.acmicpc.net/user/jh05013" target="_blank" rel="noreferrer noopener">jh05013</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/125" target="_blank" rel="noreferrer noopener">브루트포스 알고리즘</a></li>
</ul>



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



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



<p class="has-medium-font-size">아래에서 위로 올라가는 방법도 있지만 위에서 아래로 내려가는 방법도 같이 생각해야한다.</p>



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



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



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



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

using namespace std;

bool arr[10];

string str, strTemp;

int N, M, temp, cnt, target, result = INT32_MAX;

void dfs(string st, char ch)
{
	if (st.length() == str.length() + 1) return;
	st.push_back(ch);
	cnt = abs(target - atoi(st.c_str())) + st.length();
	result = min(cnt, result);

	for (int i = 0; i &lt; 10; i++) {
		if (arr[i] == true) continue;
		dfs(st, i + '0');
	}
}

int main()
{
	cin >> str >> M;

	target = atoi(str.c_str());

	for (int i = 0; i &lt; M; i++) {
		cin >> temp;
		arr[temp] = true;
	}
	
	for (int i = 0; i &lt; 10; i++) {
		if (arr[i] == true) continue;
		dfs(strTemp, i + '0');
	}

	result = min(abs(target - 100), result);

	cout &lt;&lt; result;

	return 0;
}</pre>



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



<p class="has-medium-font-size">문자열로 접근하니까 속도가 너무 느리다&#8230;.</p>



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



<figure class="wp-block-image size-full"><img decoding="async" width="1245" height="160" src="https://lycos7560.com/wp-content/uploads/2023/01/image-30.png" alt="" class="wp-image-5679" srcset="https://lycos7560.com/wp-content/uploads/2023/01/image-30.png 1245w, https://lycos7560.com/wp-content/uploads/2023/01/image-30-300x39.png 300w, https://lycos7560.com/wp-content/uploads/2023/01/image-30-768x99.png 768w" sizes="(max-width: 1245px) 100vw, 1245px" /></figure>



<div style="height:38px" 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-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/">백준 1107번 (리모컨, C++, Brute Force) / 추가 반례 [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-1107%eb%b2%88-%eb%a6%ac%eb%aa%a8%ec%bb%a8-c-brute-force-%ec%b6%94%ea%b0%80-%eb%b0%98%eb%a1%80-baekjoon/5678/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
