Files
CodeObject/storage/zeta/_static/24435.html
2026-04-27 09:44:16 +09:00

207 lines
11 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BOJ 24435 - Offline</title>
<style>
:root {
--bg: #fafaf8;
--paper: #ffffff;
--ink: #1e1f24;
--muted: #6a6d75;
--line: #d8dce3;
--accent: #0d6e6e;
--code-bg: #f4f6fb;
}
* { box-sizing: border-box; }
body {
margin: 0;
background:
radial-gradient(circle at 15% 0%, #f0efe9 0%, transparent 42%),
radial-gradient(circle at 85% 20%, #e7f1f2 0%, transparent 38%),
var(--bg);
color: var(--ink);
font-family: "Noto Sans KR", "Pretendard", "Apple SD Gothic Neo", sans-serif;
line-height: 1.65;
}
main {
max-width: 980px;
margin: 0 auto;
padding: 24px 16px 56px;
}
.header {
background: var(--paper);
border: 1px solid var(--line);
border-radius: 14px;
padding: 18px 20px;
margin-bottom: 18px;
}
.header h1 { margin: 0 0 6px; font-size: 1.5rem; }
.header p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.header a { color: var(--accent); text-decoration: none; }
.section {
background: var(--paper);
border: 1px solid var(--line);
border-radius: 14px;
padding: 16px 18px;
margin-bottom: 14px;
overflow-x: auto;
}
h2 {
margin: 0 0 10px;
font-size: 1.05rem;
color: var(--accent);
border-bottom: 1px solid var(--line);
padding-bottom: 8px;
}
pre, code {
font-family: "JetBrains Mono", "Fira Code", monospace;
background: var(--code-bg);
}
pre {
padding: 12px;
border-radius: 10px;
border: 1px solid #e7ebf2;
overflow: auto;
}
blockquote {
margin: 14px 0;
padding: 16px 16px 14px 22px;
border-left: 4px solid var(--accent);
border-radius: 10px;
background: linear-gradient(90deg, #eef8f8 0%, #f9fdfd 100%);
color: #24313a;
font-weight: 600;
position: relative;
}
blockquote::before {
content: "“";
position: absolute;
left: 8px;
top: 2px;
font-size: 1.35rem;
line-height: 1;
color: #0b5f5f;
opacity: 0.7;
}
blockquote > :first-child { margin-top: 0; }
blockquote > :last-child { margin-bottom: 0; }
q {
color: #114f50;
font-weight: 700;
background: #edf8f8;
border-radius: 6px;
padding: 0 4px;
}
.math-inline math {
font-size: 1em;
vertical-align: middle;
}
.math-block {
margin: 10px 0;
padding: 8px 10px;
overflow-x: auto;
background: #f8fbff;
border: 1px solid #e2ecf8;
border-radius: 8px;
}
.math-block math {
font-size: 1.04em;
display: block;
}
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--line); padding: 6px 8px; }
img { max-width: 100%; height: auto; }
</style>
</head>
<body>
<main>
<header class="header">
<h1>카드 게임</h1>
</header>
<article class="section">
<h2>문제</h2>
<p>Alice와 Bob은 각자 n장의 카드를 갖고 있는데 각 카드에는 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>1</mn></mrow></math></span>보다 크거나 같고, <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>9</mn></mrow></math></span>보다 작거나 같은 숫자가 하나씩 적혀 있다. 두 사람은 각자 자신이 가진 카드를 이용해서 최대 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>n</mi></mrow></math></span>자리의 수를 만들 수 있고, 더 큰 수를 만든 사람이 이긴다.</p>
<p>Bob은 아직 어려서 어떻게 큰 수를 만드는지 잘 모른다. 대신, 자신이 가진 카드를 바닥에 좌우로 순서대로 나열한 뒤, 좌에서 우로 읽었을 때 만들어지는 수와 우에서 좌로 읽었을 때 만들어지는 수 중 아무 수나 고르는 전략을 택한다. 예를 들어, Bob이 바닥에 나열한 카드의 순서가 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">[</mo><mn>2</mn><mo>&#x0002C;</mo><mn>3</mn><mo>&#x0002C;</mo><mn>4</mn><mo stretchy="false">]</mo></mrow></math></span> 라면 Bob은 좌-우 순서대로 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>234</mn></mrow></math></span>를 만들 수도 있고 혹은 우-좌 순서대로 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>432</mn></mrow></math></span>를 만들 수도 있다.</p>
<p>Alice는 동생인 Bob이 이기도록 해주고 싶어서 아래 규칙에 따라 플레이 하기로 했다:</p>
<ul>
<li>먼저, Bob이 바닥에 카드를 내려 놓도록 기다린다.</li>
<li>Bob이 좌-우 혹은 우-좌 둘 중 어떤 방법으로 수를 만들더라도 Bob이 만든 수가 Alice의 수 보다 크게 해서 동생이 이기게 해주고 싶다. 단, 카드를 최소 한 장은 사용해야 한다.</li>
<li>Bob이 이길 수 있도록 하는 방법 중 자신이 만들 수 있는 가장 큰 수를 만들고 싶다.</li>
</ul>
<p>예를 들어 위의 예제의 경우 Bob은 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">[</mo><mn>2</mn><mo>&#x0002C;</mo><mn>3</mn><mo>&#x0002C;</mo><mn>4</mn><mo stretchy="false">]</mo></mrow></math></span> 순서로 카드를 바닥에 나열했고, Alice가 가진 카드는 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">[</mo><mn>1</mn><mo>&#x0002C;</mo><mn>2</mn><mo>&#x0002C;</mo><mn>3</mn><mo stretchy="false">]</mo></mrow></math></span>이라 하자.</p>
<ul>
<li>Alice가 만들 수 있는 세 자리 수는 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>123</mn></mrow></math></span>, <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>132</mn></mrow></math></span>, <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>213</mn></mrow></math></span>, <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>231</mn></mrow></math></span>, <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>312</mn></mrow></math></span>, <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>321</mn></mrow></math></span>로 총 여섯 가지가 있다.</li>
<li>Bob<span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>234</mn></mrow></math></span><span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>432</mn></mrow></math></span>중 어떤 수를 만들지 모르므로, Alice가 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>231</mn></mrow></math></span>을 만들면 Bob이 어떤 수를 만들더라도 이기게 해줄 수 있고, 그 중 Alice가 만들 수 있는 가장 큰 수가 된다.</li>
</ul>
<p>다른 예로, Bob이 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">[</mo><mn>2</mn><mo>&#x0002C;</mo><mn>1</mn><mo>&#x0002C;</mo><mn>2</mn><mo stretchy="false">]</mo></mrow></math></span>를 가지고 있고 Alice가 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">[</mo><mn>2</mn><mo>&#x0002C;</mo><mn>2</mn><mo>&#x0002C;</mo><mn>2</mn><mo stretchy="false">]</mo></mrow></math></span>를 가지고 있다하자.</p>
<ul>
<li>Bob이 만들 수 있는 수는 좌-우와 우-좌의 경우 모두 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>212</mn></mrow></math></span>로 같다.</li>
<li>Alice가 만들 수 있는 세자리 수는 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>222</mn></mrow></math></span><span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>212</mn></mrow></math></span>보다 크므로, Alice는 카드를 세 장 모두 사용해서는 Bob이 이기게 해줄 수 없다.</li>
<li>Alice가 만들 수 있는 두자리 수는 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>22</mn></mrow></math></span>가 있고, 이 예제의 답이 된다.</li>
</ul>
<p>입력으로 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>n</mi></mrow></math></span>과 두 사람이 가진 카드에 적힌 값이 주어졌을 때, Alice가 만들 수 있는 가장 큰 수를 구해보자.</p>
</article>
<article class="section">
<h2>입력</h2>
<p>첫 줄에 테스트 케이스의 수 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>T</mi></mrow></math></span>가 주어진다. 각 테스트 케이스는 세 줄에 걸쳐 주어진다.</p>
<p>첫째 줄에 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>n</mi></mrow></math></span>이 주어진다.</p>
<p>둘째 줄에 Bob이 가진 카드에 적힌 숫자가 공백없이 주어진다. Bob이 이 순서대로 바닥에 카드를 내려놓는다.</p>
<p>셋째 줄에 Alice가 가진 카드에 적힌 숫자가 공백없이 주어진다.</p>
</article>
<article class="section">
<h2>출력</h2>
<p>각 테스트 케이스의 정답을 각 줄에 출력한다.</p>
</article>
<article class="section">
<h2>제한</h2>
<ul>
<li><span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>1</mn><mi></mi><mi>T</mi><mi></mi><mn>10</mn></mrow></math></span></li>
<li><span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>2</mn><mi></mi><mi>n</mi><mi></mi><mn>8</mn></mrow></math></span></li>
</ul>
</article>
<article class="section">
<h2>예제 입력 1 복사</h2>
<pre class="sampledata" id="sample-input-1">5
2
99
99
3
212
222
3
234
123
4
4123
2345
8
12345678
99999999
</pre>
</article>
<article class="section">
<h2>예제 출력 1 복사</h2>
<pre class="sampledata" id="sample-output-1">9
22
231
2543
9999999
</pre>
</article>
</main>
</body>
</html>