question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p01044
<h1>Problem H: Puzzle and Hexagons</h1> <h2>Backgorund</h2> <p> 超大人気ゲーム「パズル&amp;ヘキサゴンズ」がついにリリースされた。このゲームは超面白すぎてドハマりする人が続出。あまりの熱中度に医師から中毒認定を受ける者も続出した。世界各国の有志達はこのゲームの中毒者達を助けるために「パズル&amp;ヘキサゴンズ」のシミュレータを作り、危険な実機でのプレイを避けるよう促そうとした。あなたにはシミュレータ作りに協力して欲しい。 </p> <h2>Problem</h2> <p> 正六角形のマスを縦に<var>H</var>個、横に<var>W</var>個敷き詰め...
p03079
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>You are given three integers <var>A, B</var> and <var>C</var>.</p> <p>Determine if there exists an equilateral triangle whose sides have lengths <var>A, B</var> and <var>C</var>.</p> </section> </div> ...
p01414
<H1>H: Rectangular Stamps</H1> <p> ICPC で良い成績を収めるには修行が欠かせない.うさぎは ICPC で勝ちたいので,今日も修行をすることにした. </p> <p> 今日の修行は,絵を描くことによって,創造力を高めようというものである.四角いスタンプを用いて,上手く模様を描こう. </p> <p> 大小さまざまなスタンプを使い,4 &times; 4 のマス目の紙に指定された赤・緑・青の通りの絵を完成させたい.スタンプは長方形であり,マス目にぴったり合わせて使う.スタンプの縦と横を入れ替えることはできない. </p> <p> 紙は最初色が塗られていない状態にある.紙にスタンプを押すと,押さ...
p03429
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has an <var>N \times M</var> grid, with <var>N</var> horizontal rows and <var>M</var> vertical columns. Determine if we can place <var>A</var> <var>1 \times 2</var> tiles (<var>1</var> vertica...
p02392
<H1>Range</H1> <p> Write a program which reads three integers <var>a</var>, <var>b</var> and <var>c</var>, and prints "Yes" if <var>a &lt; b &lt; c</var>, otherwise "No". </p> <H2>Input</H2> <p> Three integers <var>a</var>, <var>b</var> and <var>c</var> separated by a single space are given in a line. </p> <H...
p01947
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config...
p02668
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi and Snuke came up with a game that uses a number sequence, as follows:</p> <ul> <li> <p>Prepare a sequence of length <var>M</var> consisting of integers between <var>0</var> and <var>2^N-1</v...
p00655
<H1>Problem I: FIMO sequence</H1> <p> Your task is to simulate the sequence defined in the remaining part of the problem description. </p> <p> This sequence is empty at first. <i> i </i>-th element of this sequence is expressed as <i> a<sub>i</sub> </i>. The first element of this sequence is <i> a<sub>1</sub> </i> i...
p02238
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <H1>Depth First Search</H1> <p...
p00205
<H1>じゃんけん</H1> <p> 仲良し 5 人組でじゃんけんをすることになりました。じゃんけんとは、グー、チョキ、パーという 3つの手があり、グーとチョキの勝負ならグーが「勝ち」・チョキが「負け」、チョキとパーなら、チョキが「勝ち」・パーが「負け」、パーとグーならパーが「勝ち」・グーが「負け」というルールです。全員が同じ手、またはグー、チョキ、パー全てが出た場合は「あいこ」となります。 </p> <p> 5 人のじゃんけんの手を入力とし、それぞれの人の勝敗を出力するプログラムを作成してください。じゃんけんの手は、グーは 1、チョキは 2、パーは 3 の数字で表します。勝敗は「勝ち」を 1、「負け」を 2、「あいこ...
p03700
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are going out for a walk, when you suddenly encounter <var>N</var> monsters. Each monster has a parameter called <em>health</em>, and the health of the <var>i</var>-th monster is <var>h_i</var> at t...
p02812
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a string <var>S</var> of length <var>N</var> consisting of uppercase English letters.</p> <p>How many times does <code>ABC</code> occur in <var>S</var> as contiguous subsequences (see Sample Inp...
p01697
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <!-- begin en only --> <!--<h...
p00985
<h2>Ambiguous Encoding</h2> <p> A friend of yours is designing an encoding scheme of a set of characters into a set of variable length bit sequences. You are asked to check whether the encoding is ambiguous or not. In an encoding scheme, characters are given distinct bit sequences of possibly different lengths as th...
p03350
<span class="lang-en"> <p>Score : <var>2300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a set <var>S</var> of strings consisting of <code>0</code> and <code>1</code>, and an integer <var>K</var>.</p> <p>Find the longest string that is a subsequence of <var>K</var> or more di...
p02111
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Problem A: Clock</h1> <h2>Problem</h2> <p> がっちょ君はお気に入りの時計を持っている。ある日時計の長針が取れてしまい、どこかへなくしてしまった。しかし、がっちょ君はその時計を使い続けたいため短針だけで時刻を読み取りたいと考えている。 </p> <p> 短針の情報<var>&theta;</var>に...
p00086
<H1>パトロール</H1> <p> 文久2(1862)年、会津の殿様が京都守護職を命ぜられました。京都守護職とは治安の悪化した幕末の京都を守る大切な役目です。幕府や他の藩と分担して市中をパトロールしなければなりません。ところがいざ分担ルートを決める段になって、家臣の中でも有名な頑固者の古老から以下のような注文がつきました。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_14_1"> </center> <br/> <p> 大変なことになりました。殿様といえどもこの家臣の言い分を無視するわけにはいきません。分担ルー...
p02541
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is an integer <var>N</var>. Find the minimum possible positive integer <var>k</var> such that <var>(1+2+\cdots+k)</var> is a multiple of <var>N</var>. It can be proved that such a positive integer...
p00069
<H1>あみだくじ II</H1> <p> 縦線が <var>n</var> 本のあみだくじがあります。このあみだくじは以下の条件を満たしています。 </p> <ul> <li>横線は真横に引きます。斜めに引くことはありません。</li> <li>横線は必ず隣り合った縦線同士をつなぎます。つまり、横線が縦線をまたぐことはありません。</li> <li>どの縦線についても同じ点から左右同時に横線が出ることはありません。つまり、横線が縦線を横切ることはありません。</li> <li>当りはひとつだけです。</li> </ul> <p> 下図 に <var>n</var> = 5 のときの、あみだくじの例を示します。上側の数字...
p02054
<h2>C: 串刺し (Skewering)</h2> <h3>問題</h3> <p> ある日、ほむらちゃんが積み木で遊んでいるとてんぷら君がやってきました。 ほむらちゃんは、てんぷら君と一緒に積み木で遊ぶことにしました。 </p> <p>一辺の長さが <var>1</var> の立方体の積み木のブロックを <var>A \times B \times C</var> 個隙間なく積み重ねてできた、<var>A \times B \times C</var> の直方体があります。全ての立方体と直方体の各辺は <var>x</var> 軸、<var>y</var> 軸、<var>z</var> 軸のいずれかと平行です。</p> <...
p00593
<H1>JPEG Compression</H1> <p> The fundamental idea in the JPEG compression algorithm is to sort coeffi- cient of given image by zigzag path and encode it. In this problem, we don’t discuss about details of the algorithm, but you are asked to make simple pro- gram. You are given single integer N , and you must o...
p00439
<H1>最大の和 </H1> <h2>問題</h2> <p> <i>n</i> 個の整数からなる数列 <i>a</i><sub>1</sub>, <i>a</i><sub>2</sub>, ..., <i>a<sub>n</sub></i> と正整数 <i>k</i> (1 &le; <i>k</i> &le; <i>n</i>) が与えられる.このとき, 連続して並ぶ <i>k</i> 個の整数の和 <i>S<sub>i</sub></i> = <i>a<sub>i</sub></i> + <i>a</i><sub>i+1</sub> + ... + <i>a</i><sub><i>i</i>+<i>k</i>-1</...
p02404
<H1>Print a Frame</H1> <p> Draw a frame which has a height of <var>H</var> cm and a width of <var>W</var> cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. </p> <pre> ########## #........# #........# #........# #........# ########## </pre> <H2>Input</H2> <p> The ...
p03645
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In Takahashi Kingdom, there is an archipelago of <var>N</var> islands, called Takahashi Islands. For convenience, we will call them Island <var>1</var>, Island <var>2</var>, ..., Island <var>N</var>.</p...
p01678
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h3>Problem Statement</h3> <p>T...
p02957
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have two distinct integers <var>A</var> and <var>B</var>.</p> <p>Print the integer <var>K</var> such that <var>|A - K| = |B - K|</var>.</p> <p>If such an integer does not exist, print <code>IMPOSSIBLE...
p01382
<div> <h1 class="title">問題 G : プログラミングコンテストチャレンジブック</h1> <p>今,G○○gle Code Jam の地区大会が始まろうとしている. 前の席に座っている男の ID は omeometo と言うらしい. 後ろの席に座っている男の ID は jellies と言うらしい. 東京大学時代の記憶に,似たような ID の仲間が居た覚えがあるが,僕の仲間は一人残さず美少女だったはずだ.</p> <p>彼らは,机の上に蟻のイラストが掛かれた本を持っている. あれはもしや…プログラミングコンテストのアルゴリズムを最初に網羅し,今では発売禁止となった伝説の本, 「プログラミングコンテス...
p03215
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence <var>(a_1, ..., a_N)</var> of length <var>N</var>. He is interested in properties of the sequence <var>a</var>.</p> <p>F...
p01228
<h1><font color="#000">Problem F:</font> Problem F: リズムマシーン</h1> <p> Advanced Computer Music社(ACM社)は, あらかじめプログラムされたリズム通りに音楽を演奏する リズムマシーンを販売していた. ある時,ACM社は新しいリズムマシーンを開発して売り出そうとしていた. ACM社の旧製品は同時に1つの音しか鳴らすことができなかったのに対し, 新製品では最大で8つの音を同時に鳴らせるようになるというのが 一番の目玉機能であった. 今まで複数の旧製品を利用して演奏する必要...
p03080
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>There are <var>N</var> people numbered <var>1</var> to <var>N</var>. Each person wears a red hat or a blue hat.</p> <p>You are given a string <var>s</var> representing the colors of the people. Person ...
p01547
<h1>最終防衛線</h1> <p> たびたび未確認生物に侵略されるようになった某国では重要施設を新型防衛兵器で保護することにした。<br> この兵器は多角形の領域に特殊なガスを充満させることで未確認生物にダメージを与えることができる。未確認生物が侵攻する途中でガスの濃度が変わると、濃度の差の絶対値のダメージを与える。ガスの濃度が同じ領域を動いているときはダメージは一切発生しない。<br> 現在の技術ではガスの濃度は一定にしかできないので、某国は新型防衛兵器を複数投入することにした。全ての兵器でガスの濃度は同じであり、複数の兵器の領域に含まれる部分は濃度が足し合わされる。 未確認生物の出現地点と重要施設の位置を元に、未確認生物...
p01117
<!-- begin en only --> <h3>Scores of Final Examination</h3> <!-- end en only --> <!-- begin en only --> <p> I am a junior high school teacher. The final examination has just finished, and I have all the students' scores of all the subjects. I want to know the highest total score among the students, but it is not an ea...
p02691
<span class="lang-en"> <p>Score: <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens.</p> <p>There are <var>N</var> ...
p03983
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p> Eli- <var>1</var> started a part-time job handing out leaflets for <var>N</var> seconds. Eli- <var>1</var> wants to hand out as many leaflets as possible with her special ability,...
p00356
<H1>Wire</H1> <p> I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an <var>x</var> (horizontal) b...
p00706
<H1> Get Many Persimmon Trees </H1> <P> Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a recta...
p03829
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> towns on a line running east-west. The towns are numbered <var>1</var> through <var>N</var>, in order from west to east. Each point on the line has a one-dimensional coordinate, a...
p01814
<h2>ほぼ周期文字列</h2> <p> 文字列 <var>S</var> が与えられる。この文字列 <var>S</var> に対し、<var>Q</var> 個のクエリに答えよ。 <var>i</var> 番目のクエリでは、<var>S[l_i,\ r_i]</var> から1文字まで変えてよいとき、<var>S[l_i,\ r_i]</var> を周期 <var>t_i</var> の文字列にできるかどうかを判定せよ。<var>S[l,\ r]</var> は文字列 <var>S</var> の <var>l</var> 文字目から <var>r</var> 文字目までの部分文字列を表す。 </p> <p> 文字列 ...
p00213
<H1>>土地分割</H1> <p> ハウジングメーカーの山田ハウスは、新たな目玉商品として、学校や病院など環境が充実している緑ホームタウンの分譲地を売り出しました。この分譲地は複数の区画に分割されており、好きなだけ購入できますが、購入する区画を合わせた土地の形状は長方形(正方形を含む)でなければなりません。 </p> <p> 山田ハウスは、全区画が完売した分譲地を管理するため購入者ごとに境界線を引き、その区画の 1つに購入者番号を書いた看板を設置しておきました。境界線は地面に木の枝で線を引いただけのものであったため、数日後の豪雨により消えてしまい看板だけが残りました。図 1 は看板のあった区画に、その区画を買った購入者...
p00643
<H1><font color="#000000">Problem G:</font> Rolling Dice</H1> <p> The north country is conquered by the great shogun-sama (which means king). Recently many beautiful dice which were made by order of the great shogun-sama were given to all citizens of the country. All citizens received the beautiful dice with a tear o...
p01951
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], skipTags: ["script","noscript","style","textarea","code"], processEscapes: true }}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config...
p02384
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Dice II</h1><br> <p> Cons...
p01402
<h2> Problem E: アニペロ </h2> <p> 猛暑が続いた、長かったようで短かったような夏がもうすぐ終わろうとしていた。 そんな8月下旬のある日、とある2D好きな人物とその先輩のslipは、アニペロサマーライブ、通称アニペロと呼ばれるイベントに参加していた。 アニペロとは、さまざまなアニメソングアーティストたちが集結する、日本国内最大のアニメソングライブイベントである。 今年のアニペロは、公式で公表されていたアーティストの他に、シークレットで超豪華歌手も出演し、大盛況の内に幕を閉じた。 アニペロには初参戦だった2D好きな彼は、ライブ後の余韻にひたりつつも、ひとつの疑問を抱えていた。 「アニペロに出演するア...
p01052
<h1>Movie</h1> <h2>Problem</h2> <p> 太郎君は夏休みの間、毎日1つの映画を近所の映画館で見ることにしました。 (太郎君の夏休みは8月1日から8月31日までの31日間あります。) </p> <p> その映画館では、夏休みの間に<var>n</var> つの映画が上映されることになっています。 それぞれの映画には 1 から <var>n</var> までの番号が割り当てられており、<var>i</var> 番目の映画は8月 <var>a<sub>i</sub></var> 日から8月 <var>b<sub>i</sub></var> 日の間だけ上映されます。 </p> <p> 太郎君は...
p03595
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Ringo got interested in modern art. He decided to draw a big picture on the board with <var>N+2</var> rows and <var>M+2</var> columns of squares constructed in the venue of CODE FESTIVAL 2017, using so...
p02557
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are two sequences <var>A</var> and <var>B</var>, both of length <var>N</var>. <var>A</var> and <var>B</var> are each sorted in the ascending order. Check if it is possible to reorder the terms of ...
p00090
<H1>シールの重なり</H1> <p> 1 辺の長さが 10 の正方形の折り紙に半径 1 の円形のシールを <var>n</var> 枚貼ります。シールは重ねて貼ることができます。シールを貼る位置の座標を読み込んで、折り紙上でもっとも多くシールが重なっている場所(シールが1枚だけでも"重なっている"とする)でのシールの枚数を出力するプログラムを作成してください。 </p> <p>折り紙の左下を原点とした <var>x, y</var> 座標を与えます。この <var>x, y</var> を円の中心としてシールを貼ることとします。円の中心が折り紙の外に出ることはありません。また、同一座標に複数のシールが貼られることはありま...
p02107
<script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h1>Problem J: Demon's Plan</h1> <h2>BackGround</h2> <p> デーモンズプランでは慾を司る108体の悪魔が日夜プログラミングコンテストでしのぎを削っている。主催であるパトローンは、全ての慾が集う場所”リクス=マグナ”に悪魔たちを招待しようとしている。 パトローンはまだ招待を送っていな...
p03346
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a sequence <var>(P_1,P_2,...,P_N)</var> which is a permutation of the integers from <var>1</var> through <var>N</var>. You would like to sort this sequence in ascending order by repeating ...
p00993
<H1>Problem D : Numbers </H1> <p> <i>n</i> が与えられるので、<i>n</i> 個の連続した正の整数を求めよ。 ただしすべての数が、1とその数自身以外の約数をもたなくてはならない。 </p> <H2>Input</H2> <p> 入力は以下のフォーマットで与えられる。 </p> <pre> <i>n</i> </pre> <p> 入力は以下の制約を満たす。<br> 1 &le; <i>n</i> &le; 1,500 </p> <h2>Output</h2> <p> 最初の行に、あなたが選んだ連続した<i>n</i> 個の正の整数の中で一番小さいものを出力せよ。<br> 2行目...
p01681
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h3>Problem Statement</h3> <p>...
p02804
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For a finite set of integers <var>X</var>, let <var>f(X)=\max X - \min X</var>.</p> <p>Given are <var>N</var> integers <var>A_1,...,A_N</var>.</p> <p>We will choose <var>K</var> of them and let <var>S</...
p00839
<H1><font color="#000">Problem D:</font> Organize Your Train</H1> <p> In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day. </p> <p> All freight trains travel at night, so these trains containing various types of cars...
p03716
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>N</var> be a positive integer.</p> <p>There is a numerical sequence of length <var>3N</var>, <var>a = (a_1, a_2, ..., a_{3N})</var>. Snuke is constructing a new sequence of length <var>2N</var>...
p03203
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi and Aoki will play a game using a grid with <var>H</var> rows and <var>W</var> columns of square cells. There are <var>N</var> obstacles on this grid; the <var>i</var>-th obstacle is at <var>(...
p01394
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1><font color="#000">問題 G </font> XOR 回路</h1> <h2>問題文</h2> <p> <a href="http://www.t.kyoto-u.ac.jp/syllabus-s/?mode=subject&lang=ja&year=2011&b=5&c=90840">計算機科学実験及演習 3</a> は CAD を用いて CPU を設計する授業である.CPU は多くの回路を組み合わせなければ動かず,その中の 1 つに <var>n</var> ビット入力の X...
p02941
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> positive integers arranged in a circle.</p> <p>Now, the <var>i</var>-th number is <var>A_i</var>. Takahashi wants the <var>i</var>-th number to be <var>B_i</var>. For this objecti...
p03653
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>X+Y+Z</var> people, conveniently numbered <var>1</var> through <var>X+Y+Z</var>. Person <var>i</var> has <var>A_i</var> gold coins, <var>B_i</var> silver coins and <var>C_i</var> bronze c...
p02412
<H1>How many ways?</H1><br> <p> Write a program which identifies the number of combinations of three integers which satisfy the following conditions: </p> <ul> <li>You should select three distinct integers from 1 to <var>n</var>.</li> <li>A total sum of the three integers is <var>x</var>.</li> </ul> <p> For ...
p00585
<h1>珍しい都市(Unique Cities)</h1> <p> JOI 国には$N$ 個の都市があり,1 から$N$ までの番号がついている.これらの都市は$N - 1$ 本の道路で結ばれている.$i$ 番目($1 \leq i \leq N - 1$) の道路は都市$A_i$ と都市$B_i$ を結んでおり,双方向に通行可能である.どの都市からどの都市へも何本かの道路を通行することで移動できる. </p> <p> JOI 国にはいくつかの特産品が存在する.特産品には,種類を表す1 以上$M$ 以下の番号が付けられている(JOI 国で生産されている特産品に対応していない番号があるかもしれない).各都市は1 つの特産品...
p02042
<h1>F: Absum</h1> <h2>問題</h2> <p>長さ $N$ の数列 $A$ が与えられる.あなたは高々 $M$ 回まで,数列の $i$ 番目と $j$ 番目($0 \leq i, j \leq N-1$)の要素を入れ替える操作を行うことができる.</p> <p>操作を行なってできる数列の $\sum_{i = 0}^{N - 1} abs(A_i - i)$ の最大値を求めよ.</p> <h2>制約</h2> <ul> <li>$2 \leq N \leq 10^5$</li> <li>$0 \leq M \leq N$</li> <li>$0 \leq A_i \...
p00751
<h1><font color="#000000">Problem F:</font> Old Memories</h1> <!-- end en only --> <!-- begin en only --> <p> In 4272 A.D., Master of Programming Literature, Dr. Isaac Cornell Panther-Carol, who has miraculously survived through the three World Computer Virus Wars and reached 90 years old this year, won a Nobel Pr...
p01843
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h2>E - 選挙活動</h2> <h3>Problem Statement</h3> <p>...
p02296
<H1>Distance</H1> <br/> <p> For given two segments <var>s1</var> and <var>s2</var>, print the distance between them. </p> <p> <var>s1</var> is formed by end points <var>p0</var> and <var>p1</var>, and <var>s2</var> is formed by end points <var>p2</var> and <var>p3</var>. </p> <H2>Input</H2> <p> The entire input lo...
p00301
<h1>対称3進数</h1> <p> 1 グラム、3 グラム、9 グラム、27 グラムのおもりが1つずつあれば、天びんを使って 1 グラムから 40グラムまで 1 グラム刻みで量れることが知られています。たとえば、天びんの一方の皿に重さを量りたいものと 3 グラムのおもりを載せ、もう一方の皿に 27 グラムと 1 グラムのおもりを載せて釣り合えば、量りたいものの重さは 27-3+1=25 グラムだとわかります。 さらに、1(=3<sup>0</sup>)グラム、3<sup>1</sup> グラム、... 、3<sup>n-1</sup> グラム、3<sup>n</sup> グラムまでのおもりが1つずつあれば、天びんを使って(...
p01140
<!-- begin en only --> <h3><U>Square Route</U></h3> <!-- end en only --> <!-- begin ja only --> <h3><U>スクウェア・ルート</U></h3> <!-- end ja only --> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> このたび新しい豪邸を建てることを決めた大富豪の品田氏は,どの街に新邸を...
p03487
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a sequence of positive integers of length <var>N</var>, <var>a = (a_1, a_2, ..., a_N)</var>. Your objective is to remove some of the elements in <var>a</var> so that <var>a</var> will be a...
p01510
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>Skyland</H1> <p> Somewhere in the sky, KM kingdom built <var>n</var> floating islands by their highly developed technology. The islands are numbered from 1 to <var>n</var>. </p> <p> The king of the country, Kita_masa, can choose any non-negative real n...
p03038
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have <var>N</var> cards. On the <var>i</var>-th card, an integer <var>A_i</var> is written.</p> <p>For each <var>j = 1, 2, ..., M</var> in this order, you will perform the following operation once:<...
p01005
<h1>Problem G: The Humans Braving the Invaders</h1> <h2>Problem</h2> <p> 現在、地球は宇宙からの侵略者であるインベーダーの攻撃を受け、人類で生き残った者は基地にいる我々だけとなった。 奴らに対抗できる戦力もほとんど残されていない。<!--人類に勝ち目はほぼ無いと言っていいだろう。--> だが、ここで我々は諦めるということはしない。 インベーダを全滅させることが、我々人類が生き残る最後の手段である。 <!--そして、残された人類の代表として、我々は最後まで戦わなければならない。--> 今から最後になるであろう作戦の内容を説明する。 </p> <p> まず、イ...
p03192
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer <var>N</var> that has exactly four digits in base ten. How many times does <code>2</code> occur in the base-ten representation of <var>N</var>?</p> </section> </div> <div class=...
p03468
<span class="lang-en"> <p>Score : <var>2100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have a circle of length <var>C</var>, and you are placing <var>N</var> arcs on it. Arc <var>i</var> has length <var>L_i</var>.</p> <p>Every arc <var>i</var> is placed on the circle uniformly at ran...
p01455
<H1>Problem I: よくわかる二重魔法</H1> <p> 紀慧暦2119 年15 の月。宮廷魔術士Sengemon Lugene の手によって、一冊の魔術書が書き記された。この魔術書「In Magiray」は、この世界の魔術法則の根幹に深く関わる「二重魔法」を、誰にでも習得可能な技術として体系化した、という点で革新的な書物であった。まずは、この書物の内容を要約したものを見ていこう。 </p> <p> 【エレメント】<br> 世界中のあらゆる物体は、「泉」「風」「羽」「花」「砂」「灯」……といった、極小要素「エレメント」から構成されている。エレメントには多くの種類があり、人間はエレメントと契約を交わすことで、契約を...
p00614
<H1><font color="#000000">Problem J:</font> ICPC: Ideal Coin Payment and Change</H1> <p> Taro, a boy who hates any inefficiencies, pays coins so that the number of coins to be returned as change is minimized in order to do smoothly when he buys something. </p> <p> One day, however, he doubt if this way is really eff...
p02629
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><var>1000000000000001</var> dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered <var>1</var> through <var>1000000000000001</var>, but he g...
p01906
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <h1>B: 重さの範囲</h1> <h2>問題</h2> <p> 重さの異なる $N$ 色のボールがキューにたくさん入っていま...
p02783
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Serval is fighting with a monster.</p> <p>The <em>health</em> of the monster is <var>H</var>.</p> <p>In one attack, Serval can decrease the monster's health by <var>A</var>. There is no other way to dec...
p03891
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A <var>3×3</var> grid with a integer written in each square, is called a magic square if and only if the integers in each row, the integers in each column, and the integers in each diagonal (from the to...
p00244
<H1>温泉旅行</H1> <p> 温泉好きのたけしさんは、次の長期休暇を利用してとある温泉地への旅行を計画しています。移動は長距離バスを乗り継ぎ、なるべくお金をかけずに目的地へたどり着きたいと思っています。貯金があるとはいえ、資金に心許ないたけしさんは、おじいさんに相談することにしました。計画を聞いて感心したおじいさんは、たけしさんに特別な切符を渡しました。 </p> <p> その切符は、長距離バスの連続した2区間を1回だけ無料で乗れるというものでした。使いようによってはかなりの移動費削減が見込めますが、より大きな効果を発揮させるためにはしっかりした計画を練る必要があります。 </p> <p> 出発地と目的地、及び中継...
p02279
<H1>Rooted Trees</H1> <p> A graph <i>G</i> = (<i>V</i>, <i>E</i>) is a data structure where <i>V</i> is a finite set of vertices and <i>E</i> is a binary relation on <i>V</i> represented by a set of edges. Fig. 1 illustrates an example of a graph (or graphs). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/re...
p01286
<H1><font color="#000">Problem D:</font> Luigi's Tavern</H1> <p> Luigi's Tavern is a thriving tavern in the Kingdom of Nahaila. The owner of the tavern Luigi supports to organize a party, because the main customers of the tavern are adventurers. Each adventurer has a job: hero, warrior, cleric or mage. </p> <p> Any p...
p02853
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We held two competitions: Coding Contest and Robot Maneuver.</p> <p>In each competition, the contestants taking the <var>3</var>-rd, <var>2</var>-nd, and <var>1</var>-st places receive <var>100000</var>...
p03741
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer sequence of length <var>N</var>. The <var>i</var>-th term in the sequence is <var>a_i</var>. In one operation, you can select a term and either increment or decrement it by one....
p03311
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has an integer sequence <var>A</var> of length <var>N</var>.</p> <p>He will freely choose an integer <var>b</var>. Here, he will get sad if <var>A_i</var> and <var>b+i</var> are far from each othe...
p00497
<H1>釘(Nails)</H1> <p> JOI くんは板に釘を刺して遊んでいる.下図のように,JOI くんは一辺<i>N</i> 本の正三角形の形に釘を並べて刺した.上から<i>a</i> 行目(1 &le; <i>a</i> &le; <i>N</i>) には<i>a</i> 本の釘が並んでいる.そのうち左から<i>b</i> 本目(1 &le; <i>b</i> &le; <i>a</i>) の釘を(<i>a</i>, <i>b</i>) で表す. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_nails...
p02150
<h1>Problem B: Milk</h1> <h2>Problem</h2> <p> ちょうど$a$本の牛乳の空き瓶を持っていくと新たに$b$本の牛乳の入った瓶と交換できる。<br> 最初に$x$本の牛乳の入った瓶を持っている川林さんは、最大何本分の牛乳を飲めるだろうか。$1000000007$で割った余りを出力せよ。<br> </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $a$ $b$ $x$ </pre> <p> 3つの整数$a$, $b$, $x$が空白区切りで与えられる。 </p> <h2>Constraints</h2> <p>入力は以下の条件を満...
p02015
<h2>A: パ研 (Paken)</h2> <p>あなたはパ研部員であるから、"Paken" と出力しなさい。</p> <h3>入力</h3> <p>この問題には入力は与えられない。</p> <h3>出力</h3> <p>"Paken" と 1 行に出力してください。</p> <p><span style="color:red">最後の改行を忘れないようにしましょう。</span> 必要な空白や改行がなかったり、余計な空白や改行を出力すると'Presentation Error'となり不正解になってしまいますので、注意してください。</p> <h3>入力例</h3> <pre> (No input) </pre> <h3...
p00028
<h1>Mode Value</h1> <p> Your task is to write a program which reads a sequence of integers and prints mode values of the sequence. The mode value is the element which occurs most frequently. </p> <H2>Input</H2> <p> A sequence of integers <var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; 100). The numb...
p02445
<h1>Swap</h1> <p> Write a program which reads a sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$ and swap specified elements by a list of the following operation: </p> <ul> <li>swapRange($b, e, t$): For each integer $k$ ($0 \leq k < (e - b)$, swap element $(b + k)$ and element $(t + k)$.</li> </ul> <h2>Inpu...
p00478
<H1>指輪 (Ring)</H1> <h2>問題</h2> <p> あなたは N 個の指輪を持っている.どの指輪にも,アルファベットの大文字 10 文字からなる文字列が刻印されている.指輪には文字列の最初と最後がつながった形で文字が刻印されている.指輪に刻印された文字列を逆順に読む心配はない. </p> <p> 探したい文字列が与えられたとき,その文字列を含む指輪が何個あるかを求めるプログラムを作成せよ. </p> <h2>入力</h2> <p> 入力は 2+N 行からなる.<br> 1 行目には,1 文字以上 10 文字以下のアルファベットの大文字からなる探したい文字列が書かれている.<br> 2 行目には,...
p00182
<H1>ビーカー</H1> <p> いろいろな容量のビーカーが与えられています。はじめに、その中の一番容量の大きなビーカーを一個選び、蛇口から水をいっぱいになるまで注ぎます。つぎに、次のルールにしたがいながら、ビーカーの水を他のビーカーに移し替えていきます。 </p> <ul> <li>ビーカーに入っている水は,残さずにすべて他のビーカーに移さなければならない。ただし、一個のビーカーに水を全部移せないときは、複数のビーカーに分けて移してもよい。</li> <li>ビーカーに水を入れるとき、いっぱいになるまで水を注がなければならない。また、水をこぼしてはならない。</li> <li>複数のビーカーから同じビーカーに一度に水...
p02916
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi went to an all-you-can-eat buffet with <var>N</var> kinds of dishes and ate all of them (Dish <var>1</var>, Dish <var>2</var>, <var>\ldots</var>, Dish <var>N</var>) once.</p> <p>The <var>i</va...
p01639
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [['\\(','\\)']] } }); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> <h1 class="ndoc-heading1">Problem F: MLE</h1> <p class="ndoc-top">IC...
p03604
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>2N</var> balls in the <var>xy</var>-plane. The coordinates of the <var>i</var>-th of them is <var>(x_i, y_i)</var>. Here, <var>x_i</var> and <var>y_i</var> are integers between <var>1</v...
p01269
<h1><font color="#000">Problem C:</font> Brave Princess Revisited</h1> <p> ある貧乏な国のおてんばで勇敢なお姫様が,政略結婚のため別の国に嫁ぐことになった.ところがお姫様を亡き者としようとしている悪漢が嫁ぎ先への道の途中で刺客を放っている. </p> <p> お姫様を無事に相手国に送り届けるため,あなたは安全な経路を既に決定していたのだが,お姫様の今までに通ったことのない道を通ってみたいという<s>わがままな</s>たっての願いで別の道を通ることとなった.そこであなたは地図を見ながらお姫様が通る道を決めなおすことにした. </p> <p> 全ての道...
p03254
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> children, numbered <var>1, 2, ..., N</var>.</p> <p>Snuke has decided to distribute <var>x</var> sweets among them. He needs to give out all the <var>x</var> sweets, but some of th...
p00881
<H1><font color="#000">Problem H:</font> Twenty Questions</H1> <p> Consider a closed world and a set of features that are defined for all the objects in the world. Each feature can be answered with "yes" or "no". Using those features, we can identify any object from the rest of the objects in the world. In other word...
p01793
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem D Content Delivery</h2...
p01287
<H1><font color="#000">Problem E:</font> Colored Octahedra</H1> <p> A young boy John is playing with eight triangular panels. These panels are all regular triangles of the same size, each painted in a single color; John is forming various octahedra with them. </p> <p> While he enjoys his playing, his father is wonder...
p02852
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi is playing a board game called Sugoroku.</p> <p>On the board, there are <var>N + 1</var> squares numbered <var>0</var> to <var>N</var>. Takahashi starts at Square <var>0</var>, and he has to s...