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

191 lines
8.2 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 30924 - 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>A+B - 10 (제2편)</h1>
</header>
<article class="section">
<h2>문제</h2>
<p>1 이상 10,000 이하의 정수 A, B에 대해 A+B의 값을 출력해야 한다. 단, 이 문제는 <strong>인터랙티브 (상호작용)</strong> 문제이다. 이 문제에서는 A와 B의 값이 바로 주어지지 않고, 채점기와의 상호작용을 통해 그 값을 알아내야 한다.</p>
<p>상호작용 문제에 대해 잘 모른다면, <a href="/problem/30917">제1편</a>을 먼저 풀어보자.</p>
</article>
<article class="section">
<h2>출력</h2>
<p><a href="/problem/30917">제1편</a>과 같은 방식으로 상호작용하면 된다. 단, 이 문제에서는 <strong>최대 19,997번</strong> 질문할 수 있다.</p>
<p>이 문제의 채점기는 <strong>적응하지 않는다</strong>. 자세한 설명은 아래 <strong>노트</strong> 란을 참조하자.</p>
</article>
<article class="section">
<h2>힌트</h2>
<p>이 문제는 예제를 포함하여 10개의 테스트케이스를 사용한다.</p>
<p>상호작용 문제의 채점기는 <strong>적응하는 (adaptive)</strong> 채점기와 <strong>적응하지 않는 (non-adaptive)</strong> 채점기로 나뉜다. 둘의 구분은 다음과 같다.</p>
<ul>
<li><strong>적응하는</strong> 채점기는 사용자의 질문에 맞춰서 문제의 값을 (모순이 일어나지 않는 선에서) 조정한다. 예를 들어, 만약 이 문제가 적응하는 채점기를 쓴다면, 채점기는 사용자가 질문하거나 A+B를 출력할 때 그에 맞춰서 A와 B의 값을 결정할 것이다. 그렇다고 해서 <code>? A 1</code><code>? A 2</code>에 모두 &quot;&quot;라고 답하는 등의 모순적인 답변은 하지 않는다.</li>
<li><strong>적응하지 않는</strong> 채점기는 채점을 시작할 때 문제의 값을 미리 정해 놓는다. 예를 들어, 이 문제의 채점기는 A와 B의 값을 바로 정해 놓고, 사용자가 질문할 때도 맨 처음에 정해 놓은 값에 따라 답변한다.</li>
</ul>
<p>A와 B의 값을 정하는 시점이 사용자에게 보이지 않는데, 채점기가 적응하든 아니든 무슨 차이가 있을까? 그 차이는 다음과 같다. 만약 이 문제의 채점기가 적응한다면 이 문제는 풀 수 없는 문제였을 것이다. 다음과 같은 채점기를 사용하면 A와 B를 알아내는 데 항상 19,998번의 질문이 필요한데, 실제로는 19,997번까지만 질문할 수 있기 때문이다.</p>
<ol>
<li>채점기가 A의 후보 집합과 B의 후보 집합을 관리한다. 처음에는 두 집합 모두 <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">&#x0007B;</mo><mn>1</mn><mo>&#x0002C;</mo><mn>2</mn><mo>&#x0002C;</mo><mo>&#x022EF;</mo><mo>&#x0002C;</mo><mn>10000</mn><mo stretchy="false">&#x0007D;</mo></mrow></math></span>이다.</li>
<li>프로그램이 질문할 때, 후보 집합에 원소가 두 개 이상 있다면 &quot;아니요&quot;라고 답한 뒤, 질문한 값이 집합에 있을 경우 이를 제거한다. 후보 집합에 원소가 하나만 있다면 질문에 따라 &quot;&quot; 또는 &quot;아니요&quot;라고 답한다.</li>
<li>프로그램이 A+B의 값을 출력할 때, 두 후보 집합 중 하나라도 원소가 두 개 이상 있다면 오답으로 판정하고, 아니라면 정답으로 판정한다.</li>
</ol>
<p>두 후보 집합에서 총 19,998개의 원소를 제거해야 정답을 받는데, 질문 하나당 한 원소만 지울 수 있으므로 최소 19,998번의 질문이 필요한 것이다.</p>
<p>하지만 이 문제의 채점기는 적응하지 않기 때문에, 위와 같은 방식을 사용하지 않고 A와 B의 값을 처음부터 정해 놓는다. 이 경우에는 랜덤을 잘 활용하면 각 테스트케이스에 대해 99.999999%의 확률로 정답을 낼 수 있다. 정답 확률이 정확히 100%가 아니니까 틀린 풀이가 아닌지 의문이 들 수 있다. 하지만 실제로 제출했을 때 틀렸습니다를 받을 일은 사실상 없다고 보아도 무방하고, 이렇게 랜덤을 사용하여 푸는 문제가 온라인 저지는 물론 대회에도 가끔 등장한다는 점을 고려하면 충분히 인정되는 풀이라고 할 수 있다.</p>
</article>
<article class="section">
<h2>예제 입력 1 복사</h2>
<pre class="sampledata" id="sample-input-1">
0
0
1
0
1
</pre>
</article>
<article class="section">
<h2>예제 출력 1 복사</h2>
<pre class="sampledata" id="sample-output-1">? A 123
? A 2517
? A 3150
? B 1342
? B 205
! 3355
</pre>
</article>
</main>
</body>
</html>