195 lines
11 KiB
HTML
195 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ko">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>BOJ 33027 - 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>Adrenaline Rush</h1>
|
|
</header>
|
|
<article class="section">
|
|
<h2>문제</h2>
|
|
<p>Alice's friend is a big fan of the Adrenaline Rush racing competition and always strives to attend every race. However, this time, Alice is the one watching the race. To ensure her friend does not miss any important details, Alice decides to take notes on everything that happens on the track.</p>
|
|
|
|
<p>The first thing Alice notices before the race begins is the numbering of the cars. All the cars line up in front of the starting line in a specific order. The car closest to the line is numbered <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>1</mn></mrow></math></span>, the second car is numbered <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>2</mn></mrow></math></span>, and so on, up to the last car, which is numbered <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>n</mi></mrow></math></span>. How convenient! --- Alice thought.</p>
|
|
|
|
<p>The race begins with the countdown: "Three! Two! One! Go!". Alice observes that the cars start in their original order. However, as the race progresses, their order changes. She records whenever one car overtakes another, essentially swapping places with it on the track.</p>
|
|
|
|
<p>During the race, Alice notices something curious: no car overtakes another more than once. In other words, for any two cars <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>x</mi></mrow></math></span> and <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>y</mi></mrow></math></span>, there are at most two overtakes between them during the race: "<span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>x</mi></mrow></math></span> overtakes <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>y</mi></mrow></math></span>" and/or "<span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>y</mi></mrow></math></span> overtakes <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>x</mi></mrow></math></span>".</p>
|
|
|
|
<p>At the end of the race, Alice carefully writes down the final order of the cars <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><msub><mi>c</mi><mn>1</mn></msub><mo>,</mo><msub><mi>c</mi><mn>2</mn></msub><mo>,</mo><mi>…</mi><mo>,</mo><msub><mi>c</mi><mi>n</mi></msub></mrow></math></span>, where <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><msub><mi>c</mi><mn>1</mn></msub></mrow></math></span> represents the winner of the race.</p>
|
|
|
|
<p>Alice's friend, however, is only interested in the final ranking and discards all of Alice's notes except for the final ordering. As Alice is quite curious, she wonders: <em>What is the longest possible sequence of overtakes she could have observed during the race?</em> Your task is to help Alice answer this question.</p>
|
|
</article>
|
|
<article class="section">
|
|
<h2>입력</h2>
|
|
<p>The first line of the input contains a single integer <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>n</mi><mo stretchy="false">(</mo><mn>1</mn><mo>≤</mo><mi>n</mi><mo>≤</mo><mn>1000</mn><mo stretchy="false">)</mo></mrow></math></span> --- the number of cars in the race.</p>
|
|
|
|
<p>The second line contains a permutation <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><msub><mi>c</mi><mn>1</mn></msub><mo>,</mo><msub><mi>c</mi><mn>2</mn></msub><mo>,</mo><mi>…</mi><mo>,</mo><msub><mi>c</mi><mi>n</mi></msub><mo stretchy="false">(</mo><mn>1</mn><mo>≤</mo><msub><mi>c</mi><mi>i</mi></msub><mo>≤</mo><mi>n</mi><mo>,</mo><msub><mi>c</mi><mi>i</mi></msub><mo>≠</mo><msub><mi>c</mi><mi>j</mi></msub><mo stretchy="false">)</mo></mrow></math></span> --- the final order of the cars.</p>
|
|
</article>
|
|
<article class="section">
|
|
<h2>출력</h2>
|
|
<p>The first line of the output should contain a single integer <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>m</mi></mrow></math></span> --- the maximum possible number of overtakes that can occur during the race.</p>
|
|
|
|
<p>Each of the next <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>m</mi></mrow></math></span> lines should contain two integers <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>x</mi></mrow></math></span> and <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>y</mi></mrow></math></span> (<span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mn>1</mn><mo>≤</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo>≤</mo><mi>n</mi></mrow></math></span>, <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>x</mi><mo>≠</mo><mi>y</mi></mrow></math></span>) representing an overtake event, where car <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>x</mi></mrow></math></span> overtakes car <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>y</mi></mrow></math></span>. This means that car <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>x</mi></mrow></math></span> was directly behind car <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>y</mi></mrow></math></span> and overtakes it. The overtakes must be listed in the order they occurred during the race.</p>
|
|
|
|
<p>After all <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>m</mi></mrow></math></span> overtakes have occurred, the cars must arrive at the finish line in the order <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><msub><mi>c</mi><mn>1</mn></msub><mo>,</mo><msub><mi>c</mi><mn>2</mn></msub><mo>,</mo><mi>…</mi><mo>,</mo><msub><mi>c</mi><mi>n</mi></msub></mrow></math></span>. Note that any car <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>x</mi></mrow></math></span> should not overtake another car <span class="math-inline"><math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>y</mi></mrow></math></span> more than once.</p>
|
|
|
|
<p>If there are multiple possible longest sequences of overtakes, output any of them.</p>
|
|
</article>
|
|
<article class="section">
|
|
<h2>예제 입력 1 복사</h2>
|
|
<pre class="sampledata" id="sample-input-1">3
|
|
2 3 1
|
|
</pre>
|
|
</article>
|
|
<article class="section">
|
|
<h2>예제 입력 2 복사</h2>
|
|
<pre class="sampledata" id="sample-input-2">1
|
|
1
|
|
</pre>
|
|
</article>
|
|
<article class="section">
|
|
<h2>예제 입력 3 복사</h2>
|
|
<pre class="sampledata" id="sample-input-3">2
|
|
1 2
|
|
</pre>
|
|
</article>
|
|
<article class="section">
|
|
<h2>예제 출력 1 복사</h2>
|
|
<pre class="sampledata" id="sample-output-1">4
|
|
2 1
|
|
3 1
|
|
3 2
|
|
2 3
|
|
</pre>
|
|
</article>
|
|
<article class="section">
|
|
<h2>예제 출력 2 복사</h2>
|
|
<pre class="sampledata" id="sample-output-2">0
|
|
</pre>
|
|
</article>
|
|
<article class="section">
|
|
<h2>예제 출력 3 복사</h2>
|
|
<pre class="sampledata" id="sample-output-3">2
|
|
2 1
|
|
1 2
|
|
</pre>
|
|
</article>
|
|
</main>
|
|
</body>
|
|
</html>
|