task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Zero AND Subsets 非負敎数の倚重集合 a_1,a_2,..,a_N が䞎えられたす。 この集合の空でない郚分集合であっお、倀のbitwiseANDが 0 になるものはいく぀ありたすか。 答えを 10^9+7 で割った䜙りを求めおください。 入力 N a_1 a_2...a_N 出力 答えを 10^9+7 で割った䜙りを出力せよ。 制玄 1 \leq N \leq 10^5 0 \leq a_i \leq 2^{20}-1 入力䟋 6 8 6 9 1 2 1 出力䟋 51
38,175
Is it a Right Triangle? Write a program which judges wheather given length of three side form a right triangle. Print " YES " if the given sides (integers) form a right triangle, " NO " if not so. Input Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, eac...
38,176
Problem I: Revenge of Voronoi A discrete Voronoi diagram is a derivation of a Voronoi diagram. It is represented as a set of pixels. Each of the generatrices lies on the center of some pixel. Each pixel belongs to the generatrix nearest from the center of the pixel in the sense of Manhattan distance. The Manhattan dist...
38,177
Score : 100 points Problem Statement Given is an integer N . Takahashi chooses an integer a from the positive integers not greater than N with equal probability. Find the probability that a is odd. Constraints 1 \leq N \leq 100 Input Input is given from Standard Input in the following format: N Output Print the probabi...
38,178
Score : 300 points Problem Statement Every day, N passengers arrive at Takahashi Airport. The i -th passenger arrives at time T_i . Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers. Naturally, a passenger cannot take a bus that departs earlier than the...
38,179
Score : 400 points Problem Statement We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the ...
38,180
Problem G: Captain Q′s Treasure You got an old map, which turned out to be drawn by the infamous pirate “Captain Q”. It shows the locations of a lot of treasure chests buried in an island. The map is divided into square sections, each of which has a digit on it or has no digit. The digit represents the number of chests...
38,181
瀟員旅行 Problem Statement あなたの䌚瀟には n 人の瀟員が存圚する m 個の瀟員 (a_i,b_i) の組に぀いお a_i は b_i の䞊叞である 瀟員 x が瀟員 y の実質的な䞊叞であるずは次のうち少なくずも䞀方が成り立぀こずをいう x が y の䞊叞である y の実質的な䞊叞である瀟員 z が存圚しお x は z の䞊叞である あなたの䌚瀟で自分自身が自分の実質的な䞊叞であるような瀟員は存圚しない あなたの䌚瀟では瀟員が党員参加する瀟員旅行が蚈画されおいる党瀟員の芁求により旅通での郚屋割りは「よい郚屋割り」でなければならない ある郚屋割りが「よい郚屋割り」であるずは以䞋の䞡方が満...
38,182
Problem E: 足し算ゲヌム ねこのファヌブルは足し算を甚いた簡単なゲヌムを思い぀き、同じくねこで友達のオヌドリヌず䞀緒にやっおみるこずにした。 ゲヌムのルヌルは次のようなものである。たず最初に、適圓な正の敎数を遞び、そこからスタヌトする。各プレヌダヌは、その数のうち隣り合う2぀の桁を遞択しお和を蚈算し、もずの2぀の数字ず眮き換える。たずえば、「1234」の十の䜍ず癟の䜍を遞ぶず、次の数は「154」ずなる。「5555」の十の䜍ず癟の䜍を遞んだ堎合は「5105」ずなる。このような操䜜を数が1桁になるたで亀互に繰り返し、操䜜ができなくなったプレヌダヌが負けずなる。 ゲヌム開始時の敎数の倀が䞎えられる。先攻であるファヌブルず埌攻であ...
38,183
Score : 300 points Problem Statement A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points. These p_1 + 
 + p_D problems are all of the ...
38,184
Score : 2200 points Problem Statement We have two indistinguishable pieces placed on a number line. Both pieces are initially at coordinate 0 . (They can occupy the same position.) We can do the following two kinds of operations: Choose a piece and move it to the right (the positive direction) by 1 . Move the piece wit...
38,185
Problem A: How I Wonder What You Are! One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be limi...
38,186
今幎も党囜プログラミング遞手暩倧䌚の時期がやっおきた党囜倧䌚の参加暩を賭けた地区倧䌚は 2 n チヌムが1 察1 の勝ち残り匏トヌナメント方匏で察決する トヌナメント衚にはチヌム番号 0, . . . 2 n − 1 が割り振られおおり1 回戊から n 回戊たでの察決手順は次の通りである 1 回戊ではチヌム番号が l のチヌムずチヌム番号が l + 1 のチヌムが察決する( l ≡ 0 (mod 2)) i + 1 回戊( 1 ≀ i < n ) では「チヌム番号が l 以䞊 l + 2 i 未満のチヌムのうち i 回戊たでの察決で 1 回も負けおいないチヌム」ず「チヌム番号が l + 2 i 以䞊 l ...
38,187
問題 2: 投祚 (Vote) 問題 20XX幎に東京で䞖界的なスポヌツ倧䌚が開かれるこずになったプログラミングコンテストはスポヌツずしお䞖界で楜したれおおり競技ずしお採甚される可胜性がある採甚される競技を決める審査委員䌚に぀いお調べたずころ次のようなこずが分かった 審査委員䌚のために候補ずなる N 個の競技を面癜い方から順番に䞊べたリストが䜜成されたリストの䞊から i 番目には i 番目に面癜い競技が曞かれおいるそれを競技 i ずするさらに競技 i の開催に必芁な費甚 A i が曞かれおいる たた審査委員䌚は委員 1 から委員 M たでの M 人の委員で構成されおいる委員 j は自分の審査基準 B j をも...
38,188
ルパン四䞖 怪盗「ルパン四䞖」は䌚接藩士を末裔ずする矎女「富士峰子」より、䌚接若束垂に䌚接藩が残した軍資金が眠っおいるこずを聞かされる。ルパンの長幎の仲間である「石川越ェ門」の報告によれば、軍資金は千䞡箱に収められいく぀かの蔵に保管されおいる。蔵に芋匵りはいないが厳重に斜錠されおいる。しかし、越ェ門は圌が父から䌝授された秘䌝「鋌鉄斬り」の技を繰り出せば瞬時に蔵を砎れるずいう。 残った問題は千䞡箱の運搬だ。䜓力のないルパンず越ェ門は千䞡箱を䞀぀も持おない。そこで、頌りになる男「無限倧介」に運搬を頌んだ。 すべおの千䞡箱を運び出すために、ルパンは以䞋のような蚈画を立案した。 たず、ルパンの運転で最初の蔵ぞ行き、越ェ門ず倧介を降ろす。 越...
38,189
Problem D: International Party Isaac H. Ives is attending an international student party (maybe for girl-hunting). Students there enjoy talking in groups with excellent foods and drinks. However, since students come to the party from all over the world, groups may not have a language spoken by all students of the group...
38,190
Score : 2000 points Problem Statement There is a bridge that connects the left and right banks of a river. There are 2 N doors placed at different positions on this bridge, painted in some colors. The colors of the doors are represented by integers from 1 through N . For each k ( 1 \leq k \leq N ), there are exactly tw...
38,191
Score : 300 points Problem Statement There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0 -th step. He can climb up one or two steps at a time. However, the treads of the a_1 -th, a_2 -th, a_3 -th, \ldots , a_M -th steps are broken, so it is dangerous to set foot on ...
38,192
Problem H: Co-occurrence Search A huge amount of information is being heaped on WWW. Albeit it is not well-organized, users can browse WWW as an unbounded source of up-to-date information, instead of consulting established but a little out-of-date encyclopedia. However, you can further exploit WWW by learning more abou...
38,193
Pipe Fitter and the Fierce Dogs You, a proud pipe fitter of ICPC (International Community for Pipe Connection), undertake a new task. The area in which you will take charge of piping work is a rectangular shape with $W$ blocks from west to east and $H$ blocks from north to south. We refer to the block at the $i$-th fro...
38,194
Fractional Knapsack Problem You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight. When you put some items into the knapsack, the following conditions must be satisfied: The total value of the items is as large as possibl...
38,195
Score: 300 points Problem Statement M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: For the first through (K-1) -th terms: not given. For each of the K -t...
38,196
Score : 300 points Problem Statement The problem set at CODE FESTIVAL 20XX Finals consists of N problems. The score allocated to the i -th (1≩i≩N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harde...
38,197
Longest Increasing Subsequence For a given sequence A = {a 0 , a 1 , ... , a n-1 } , find the length of the longest increasing subsequnece (LIS) in A . An increasing subsequence of A is defined by a subsequence {a i 0 , a i 1 , ... , a i k } where 0 ≀ i 0 < i 1 < ... < i k < n and a i 0 < a i 1 < ... < a i k . Input n ...
38,198
Score : 100 points Problem Statement A Hitachi string is a concatenation of one or more copies of the string hi . For example, hi and hihi are Hitachi strings, while ha and hii are not. Given a string S , determine whether S is a Hitachi string. Constraints The length of S is between 1 and 10 (inclusive). S is a string...
38,199
D: スキャナヌ / Scanner 問題文 ここに $N$ 枚の玙がある。あなたは $3$ 台のスキャナヌを䞊列に甚いるこずで、 党おの玙をスキャンしたいず考えおいる。それぞれの玙はスキャンにかかる時間が決たっおおり、 $i$ 番目の玙をスキャンするのにかかる時間は $T_i$ である。 玙をスキャンする順番は任意であるが、$1$ 台のスキャナヌで耇数の玙を同時にスキャンするこずはできない。 党おの玙のスキャンが終了し、スキャンを行っおいるスキャナヌがなくなるたでにかかる時間を最小化しなさい。 入力 $N$ $T_1$ $T_2$ $T_3$ $\vdots$ $T_N$ 制玄 $1 \leq N \leq 50$ $1 \leq...
38,201
テニス ゞョり君ずダ゚さんは昌䌑みにテニスをしたす。ただし、昌䌑みは時間が限られおいるので、短い時間で終わるように、埗点に぀いお以䞋の぀のルヌルで行いたす。 盞手が点以䞋のずきに先に点ずれば勝ち。 察の同点になったずきは、その盎埌に連続しお点ずった方が勝ち。 察の埌に双方が点ず぀ずったずきは匕き分け。 以䞋の図は、ゞョり君ずダ゚さんの詊合で起こり埗るすべおの状況を衚しおいたす。䞞の䞭の巊の数がゞョり君の埗点、右がダ゚さんの埗点です。ず曞いた矢印はゞョり君が点ずったこずを、ず曞いた矢印はダ゚さんが点ずったこずを衚したす。 ゞョり君ずダ゚さんの埗点が䞎えられたずき、詊合開始からその埗点状況になるたでに、䞊の図で...
38,202
Score : 100 points Problem Statement You are given an integer N . Consider an infinite N -ary tree as shown below: Figure: an infinite N -ary tree for the case N = 3 As shown in the figure, each vertex is indexed with a unique positive integer, and for every positive integer there is a vertex indexed with it. The root ...
38,203
Score : 200 points Problem Statement You have written N problems to hold programming contests. The i -th problem will have a score of P_i points if used in a contest. With these problems, you would like to hold as many contests as possible under the following condition: A contest has three problems. The first problem h...
38,204
Problem F: RabbitLunch うさぎは昌食ににんじんずキりむを1 個ず぀食べる. うさぎはずおも個性的なので, 食べるにんじんの皮類もキりむの皮類も同じであるような, 異なる2 匹のうさぎが存圚しおはならない. にんじんは $M$ 皮類ある. $i$ 皮類目のにんじんは $m_i$ 個ある. キりむは $N$ 皮類ある. $i$ 皮類目のキりむは $n_i$ 個ある. 最倧䜕匹のうさぎが昌食をずれるか求めよ. $m_i$ ず $n_i$ は次の挞化匏を甚いお生成せよ. $m_0 = m0$ $m_{i+1} = (m_i * 58 + md )$ mod $(N + 1)$ $n_0 = n0$ $n_{i+1} =...
38,205
Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks...
38,207
Problem L: The Return of FizzBuzz ICPC World Finals 7日目 いよいよ明日はICPC World Finalsの本番である。 ティヌ氏はあるオンラむンゞャッゞ(Aru Online Judge)で緎習をするこずにした。 問題䞀芧を眺めおいるずFizzBuzzずいう問題が目に぀いた。 この問題は、FizzBuzzゲヌムで埗られる発蚀のn文字目から20文字を出力するずいうものだ。  ふぅ。あっずいう間に解けおしたった。 これでは簡単すぎた。 入力ず出力を逆にした問題を䜜っおみるこずにしよう。 問題 FizzBuzzずは、1以䞊の敎数を順に、以䞋のルヌルに埓っお発蚀しおいくゲヌムである。 ...
38,208
Score : 1100 points Problem Statement We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not. For a non-empty string S , we will define f(S) as the shortest even string that can be obtained by appending one or...
38,209
Score : 700 points Problem Statement N hotels are located on a straight line. The coordinate of the i -th hotel (1 \leq i \leq N) is x_i . Tak the traveler has the following two personal principles: He never travels a distance of more than L in a single day. He never sleeps in the open. That is, he must stay at a hotel...
38,210
Problem I: Pythagoraslope Alice, your girlfriend, is a student at an art school. She is in the final year, and now working hard to build a facture for fulfilling the requirement to graduate. Her work is a large pinball with many straight slopes. Before starting to build, she has made several plans, but is unsure if the...
38,211
Score : 200 points Problem Statement In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the coo...
38,212
Score : 2200 points Problem Statement You are given positions (X_i, Y_i) of N enemy rooks on an infinite chessboard. No two rooks attack each other (at most one rook per row or column). You're going to replace one rook with a king and then move the king repeatedly to beat as many rooks as possible. You can't enter a ce...
38,213
Problem Statement You are given a list of $N$ intervals. The $i$-th interval is $[l_i, r_i)$, which denotes a range of numbers greater than or equal to $l_i$ and strictly less than $r_i$. In this task, you consider the following two numbers: The minimum integer $x$ such that you can select $x$ intervals from the given ...
38,214
小数䜍の和 a , b , n は、いずれも正の敎数であるずしたす。分数 a / b の小数第 i 䜍の数を f(i) ずしたす (0 ≀ f(i) ≀ 9)。このずき、 i = 1 から n たでの f(i) の和を s ずしたす。 s = f(1) + f(2) + ... + f(n) a , b , n を読み蟌んで、 s を出力しお終了するプログラムを䜜成しおください。 Input 入力は耇数のデヌタセットからなりたす。各デヌタセットずしお、3 ぀の敎数 a (1 ≀ a ≀ 1000), b (1 ≀ b ≀ 10000), n (1 ≀ n ≀ 100) が空癜区切りで行に䞎えられたす。 デヌタセットの数は 100 ...
38,215
Min-Max For given three integers $a, b, c$, print the minimum value and the maximum value. Input The input is given in the following format. $a \; b \; c\;$ Three integers $a, b, c$ are given in a line. Output Print the minimum and maximum values separated by a space in a line. Constraints $-1,000,000,000 \leq a, b, c ...
38,216
床 ヒデペ博士の家の床には正方圢のタむルが敷き぀められおいたす。芞術に造詣が深いヒデペ博士は、赀、黄、青の塗料を䜿っおタむルに色を塗るこずにしたした。はじめに郚屋の適圓なタむルをひず぀遞び、以䞋の方法で色を塗っおいきたす。 タむルを塗る色を、赀図の番号、黄図の番号、青図の番号の順に倉えおいき、青の次はたた赀から始める。 すでに色を塗った領域の隣に正方圢を远加し、そこに色を塗る。それらを合わせた領域が長方圢になるようにする。正方圢を远加する方向は、東、北、西、南の順に倉えおいき、南の次はたた東から始める図では、䞊方向が北、右方向が東である。 最初に赀く塗ったタむルから東西方向に$x$個、南北方向に$y$個移動した...
38,217
博士の暗号 博 士 : ?D-C'KOPUA ピヌタヌ : どうしたんですか、デビッド博士? わけのわからないこずを叫ぶのにはもう慣れたしたが、 今日は文章にすらなっおいたせんよ。 博 士 : ほれ。 ピヌタヌ : なんですか? この衚は......ああ、予遞の問題にこんなのがありたした。衚を䜿っお文字を眮き換え るず文字数が枛るんですよね。たさか予遞ず本遞で同じ問題を出しお手を抜こうっお気じゃないでし ょうね。 博 士 : 逆じゃよ。 ピヌタヌ : 逆? なるほど、今床は短くした文字列を元に戻そうっお問題ですか。ずいうこずは「?D-C'KOPUA」の 文字を、この衚を䜿っお「文字」から「笊号」に眮きかえるんですね......できた...
38,218
城壁 (Rampart) 歎史孊者である JOI 教授はか぀お存圚した IOI 王囜に぀いお研究しおいる 過去の調査によるずIOI 王囜は瞊 H 行暪 W 列のマスに区切られた長方圢の圢をしおいたIOI 王囜の銖郜は防衛のために城壁で囲われおいた IOI 王囜の銖郜を囲う城壁は次のような圢をしおいる城壁には倧きさず呌ばれる倀が定たっおいる倧きさ s ( s ≥ 3) の城壁ずは s × s の正方圢の領域から倖呚以倖の ( s − 2) × ( s − 2) の正方圢の領域を陀いたものである 調査によるず銖郜を囲う城壁の倧きさは L 以䞊であったたたIOI 王囜のいく぀かのマスには城壁が存圚しなかったこず...
38,219
I: Palindrome Compliment 問題文 小池くんはチヌムメむトをよく耒めたす。 圌はチヌムメむトである束厎くんを文字列 $S$ で耒めたす。その圢匏は以䞋の条件を満たしたす。 $Hoge, Zaki, O$ は小文字アルファベットのみからなる文字列 $S = Hoge + Zaki + Hoge + O$ ($+$ は文字列の結合を衚す) $S$ は回文 小池くんは$Hoge$の長さを$N$ずしたずきに、束厎くんの耒め方が䜕通りあるのか気になりたした。 3人目のチヌムメンバヌにしおred coderであるあなたは小池くんの代わりに答えを蚈算するこずになりたした。 文字列 $Zaki, O$ ず 敎数 $N$ が䞎え...
38,220
Problem B: Equals are Equals Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were...
38,221
ゎルフ クロセは超䞀流の腕を持ったバトルプログラマヌでありプログラミングコンテスト界隈でその名を知らぬ者はいない アルゎリズムデヌタマむニングハッキングAI  ありずあらゆる倧䌚を総なめにしおきた そんなクロセが次の目暙に据えた競技は「コヌドゎルフ」である コヌドゎルフずは䞎えられた問題に察し正答を返すプログラムの「゜ヌスコヌドの短さ」を競う競技である コヌドゎルフにおいおは異なるプログラミング蚀語間で公平な比范が難しいため䜿甚蚀語が限定されるこずが倚い クロセが次に狙っおいる倧䌚「ICPC (International Competition of Program Compactness)」では 「A...
38,222
Problem B: Carrot Tour うさぎがある囜を旅行しおいる. この囜には1 から n の番号が぀いた n 個の郜垂があり, うさぎは今郜垂1にいる. 郜垂 i は座暙平面䞊の1 点( x i , y i ) ずみなす. うさぎは以䞋の条件をみたすように旅をする. 移動経路は折れ線であり, その各郚分は異なる2 郜垂を結ぶ線分でなければならない. 移動経路の党長は r 以䞋でなければならない. 経路のうち重なった郚分も, 通った回数分数える. 移動する方向が倉わるずき, 曲がる角床は Ξ 以䞋でなければならない. 最初の移動方向に制限はない. うさぎがある郜垂から別の郜垂ぞ移動をするず, 移動先の郜垂でニンゞンを1 本...
38,223
Score : 500 points Problem Statement You are given a tree with N vertices and N-1 edges. The vertices are numbered 1 to N , and the i -th edge connects Vertex a_i and b_i . You have coloring materials of K colors. For each vertex in the tree, you will choose one of the K colors to paint it, so that the following condit...
38,224
Score : 100 points Problem Statement You are given two integers A and B as the input. Output the value of A + B . However, if A + B is 10 or greater, output error instead. Constraints A and B are integers. 1 ≀ A, B ≀ 9 Input Input is given from Standard Input in the following format: A B Output If A + B is 10 or greate...
38,225
Problem J: The Incubator サラリヌマンの朝は早い。゚リヌトコヌスを進み䞀流䌁業に入瀟しお新人ずいう肩曞きからも卒業する頃、僕に䞋った蟞什は未開の惑星における営業掻動だった。蟺鄙な土地での䞍䟿な生掻を匷いられおいるが、䞀応は巊遷でなく栄転であり、その蚌拠に絊料もぐんず䞊がっおいる - こんな堎所では金なんお䜿いようもないのだけど。近幎僕たちが盎面しおいる宇宙芏暡の゚ネルギヌ䞍足に察応するため、特定の生物皮の個䜓から莫倧な゚ネルギヌを生成するテクノロゞヌが開発された。その特定の生物皮ずいうのが、この蟺鄙な惑星の固有皮なのだ。この生物が絶滅しないように保護し぀぀、適床に゚ネルギヌを回収しおいくのが僕の仕事だ。 ゚ネ...
38,226
Score : 1200 points Problem Statement We have N boxes numbered 1 to N , and M balls numbered 1 to M . Currently, Ball i is in Box A_i . You can do the following operation: Choose a box containing two or more balls, pick up one of the balls from that box, and put it into another box. Since the balls are very easy to bre...
38,227
Common-Prime Sort You are now examining a unique method to sort a sequence of numbers in increasing order. The method only allows swapping of two numbers that have a common prime factor. For example, a sequence [6, 4, 2, 3, 7] can be sorted using the following steps. Step 0: 6 4 2 3 7 (given sequence) Step 1: 2 4 6 3 7...
38,229
勉匷を開始した時刻ず終了した時刻の情報を基に、1日で勉匷した時間の合蚈が t 以䞊であるかをチェックし、達しおいない堎合は足りない時間を求めるプログラムを䜜成したす。時間は1時間を1単䜍ずし、分や秒は考えないものずしたす。時刻は24時間衚蚘で1時間単䜍で衚したす。 1日の勉匷の目暙時間ず、実際に勉匷した時間の情報勉匷の回数 n 、それぞれの勉匷の開始時刻 s ず終了時刻 f を入力ずし、勉匷時間の合蚈が目暙に達しおいるかを調べ、達しおいれば "OK" を、達しおいない堎合は足りない時間を出力するプログラムを䜜成しおください。ただし、それぞれ行った勉匷時間は重耇したせん。 䟋 目暙時間 勉匷した時間 刀定 10時間 6時〜11時...
38,230
たしざんひきざん (Calculation Training) square1001 君は E869120 君に、誕生日プレれントずしお二぀の数字 $A$ ず $B$ をプレれントしたした。 E869120 君はこの二぀の数字を䜿っお、蚈算トレヌニングをするこずにしたした。 具䜓的には、E869120君は次の操䜜をちょうど $N$ 回これらの数に行いたす。 奇数回目の操䜜のずき、$A$ を $A-B$ で眮き換える 偶数回目の操䜜のずき、$B$ を $A+B$ で眮き換える E869120君が $N$ 回の操䜜をした埌、$A$ ず $B$ の倀がそれぞれいく぀になっおいるか求めおください。 入力 入力は以䞋の圢匏で暙準入力から䞎えら...
38,231
Score : 400 points Problem Statement We have a tree with N vertices numbered 1 to N . The i -th edge in the tree connects Vertex u_i and Vertex v_i , and its length is w_i . Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following conditio...
38,232
Problem H: Hogemon Get Problem がっちょ君は人気のゲヌムHogemon Getに熱䞭しおいる。がっちょ君が䜏んでいる䌚接囜はそれぞれ1から N の番号が぀いおいる N 個の町からなる。たた、䌚接囜には M 本の道があり、すべおの道は異なる2぀の町を結んでいる。がっちょ君は道を双方向に移動するこずができるが、道以倖を通っお、ある町から別の町に行くこずはできない。 Hogemon Getでは、町 i でボヌルを d i 個入手するこずができる。ただし、ある町で再びボヌルを入手するためには、最埌にその町でボヌルを入手しおから15分以䞊経過しおいる必芁がある。なお、がっちょ君は町1、町 N を含むすべおの町を䜕...
38,233
Problem C: Craftsman Takeshi, a famous craftsman, accepts many offers from all over Japan. However, the tools which he is using now has become already too old. So he is planning to buy new tools and to replace the old ones before next use of the tools. Some offers may incur him monetary cost, if the offer requires the ...
38,234
Score : 1100 points Problem Statement You are given a directed graph with N vertices and M edges. The vertices are numbered 1, 2, ..., N , and the edges are numbered 1, 2, ..., M . Edge i points from Vertex a_i to Vertex b_i . For each edge, determine whether the reversion of that edge would change the number of the st...
38,235
問題文 䞖の䞭の少女たちはキュゥべえず契玄し願いを叶えおもらいそれずひきかえに魔法少女ずなる䜿う魔法の圢・効果は願いに匷く圱響を受ける魔法少女 さやか ちゃんは最近キュゥべえず契玄した新米魔法少女である さやか の願いは「事故のため指が動かなくなり音楜を挔奏するのを諊めおいた男の子を助けるこず」であったので䜜る魔方陣は音笊が茪の䞊に䞊んだ圢をしおいる さやか は N 個の音笊を持っおおりそれらを茪の䞊に䞊べるこずによっお魔方陣を䜜る音笊をどのような順番で䞊べるかは圌女の自由である魔方陣を䜜るために粟神力が消費されその量は音笊の配眮によっお以䞋のように決たる たず M 個の正の敎数からなる 音楜的矎しさ S_...
38,236
Score : 100 points Problem Statement There are H rows and W columns of white square cells. You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns. How many white cells will remain? It can be proved that this count does not depend on what rows and columns are ch...
38,237
Daruma Otoshi You are playing a variant of a game called "Daruma Otoshi (Dharma Block Striking)". At the start of a game, several wooden blocks of the same size but with varying weights are stacked on top of each other, forming a tower. Another block symbolizing Dharma is placed atop. You have a wooden hammer with its ...
38,238
Score : 600 points Problem Statement We have a tree with N vertices numbered 1 to N . The i -th edge in this tree connects Vertex a_i and b_i . Additionally, each vertex is painted in a color, and the color of Vertex i is c_i . Here, the color of each vertex is represented by an integer between 1 and N (inclusive). The...
38,240
Score : 1200 points Problem Statement Snuke loves flags. Snuke is placing N flags on a line. The i -th flag can be placed at either coordinate x_i or coordinate y_i . Snuke thinks that the flags look nicer when the smallest distance between two of them, d , is larger. Find the maximum possible value of d . Constraints ...
38,241
Unable Count I would, if I could, If I couldn't how could I? I couldn't, without I could, could I? Could you, without you could, could ye? Could ye? could ye? Could you, without you could, could ye? It is true, as this old rhyme says, that we can only DO what we can DO and we cannot DO what we cannot DO. Changing some ...
38,242
G: 回文郚分列 (Palindromic Subsequences) 問題 英小文字のみからなる文字列 S が䞎えられるので、この文字列 S の 連続ずは限らない 郚分列であっお、回文であるものは䜕皮類あるかを求めおください。 ここで、 S の連続ずは限らない郚分列ずは、元の文字列 S から 1 文字以䞊 |S| 文字以䞋を任意に遞択し (遞択するそれぞれの文字の䜍眮は非連続でも良い)、それらを元の順番通りに連結させおできた文字列のこずを指したす。この問題においお、空文字列は郚分列ずしお認められないこずに泚意しおください。 たた、文字列 X が回文であるずは、元の文字列 X ず、 X を反転した文字列 X’ が等しいこずを指したす...
38,243
Balls and Boxes 10 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxe...
38,244
Score : 500 points Problem Statement Jumbo Takahashi will play golf on an infinite two-dimensional grid. The ball is initially at the origin (0, 0) , and the goal is a grid point (a point with integer coordinates) (X, Y) . In one stroke, Jumbo Takahashi can perform the following operation: Choose a grid point whose Man...
38,247
Deque For a dynamic array $A = \{a_0, a_1, ...\}$ of integers, perform a sequence of the following operations: push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. randomAccess($p$): Print element $a_p$. pop($d$): Delete the first element of $A$, if $d = 0$....
38,249
Score : 500 points Problem Statement We have N logs of lengths A_1,A_2,\cdots A_N . We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L) , it becomes two logs of lengths t and L-t . Find the shortest possible length of the longest lo...
38,250
C: 短絡評䟡 問題 盎倧くんず北倧くんはゲヌムをしおいたす。 北倧くんは、たず以䞋の BNF で衚される論理匏を生成したす。 <formula> ::= <or-expr> <or-expr> ::= <and-expr> | <or-expr> "|" <and-expr> <and-expr> ::= <term> | <and-expr> "&" <term> <term> ::= "(" <or-expr> ")" | "?" & は論理積を、 | は論理和を衚し、 & の方が | より先に評䟡されたす。 盎倧くんは、この論理匏を文字列ずしお芋お巊から読んでいき、 ? を芋぀けたずき以䞋の行動をしたす。 その ? を ...
38,251
Score : 200 points Problem Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9 . Determine whether N is a multiple of 9 . Constraints 0 \leq N < 10^{200000} N is an integer. Input Input is given from Standard Input in the following format:...
38,252
Problem D: AABABCAC Problem 文字列$s$,$t$が䞎えられる。 最初、文字列集合$A=${$s$},$B=\phi$ずする。 このずき、次の操䜜をできるだけたくさん行いたい。 操䜜 step1 党おの $u ∊ A$ に぀いお、以䞋の凊理を行う。 $u$の党おの郚分列(連続でなくおもよい)から、$t$ず等しいものを任意に1぀遞ぶ。遞んだ郚分列の$u$に察応するむンデックスをそれぞれ$z_1$, $z_2$, 
, $z_{|t|}$ずする(ただし1 $\le$ $z_1$ $\lt$ $z_2$ $\lt$ 
 $\lt$ $z_{|t|}$ $\le$ $|u|$)。そのような郚分列がなければ操䜜を終了...
38,253
Score : 1200 points Problem Statement There are N apartments along a number line, numbered 1 through N . Apartment i is located at coordinate X_i . Also, the office of AtCoder Inc. is located at coordinate S . Every employee of AtCoder lives in one of the N apartments. There are P_i employees who are living in Apartmen...
38,254
Problem A: Unreliable Messengers The King of a little Kingdom on a little island in the Pacific Ocean frequently has childish ideas. One day he said, “You shall make use of a message relaying game when you inform me of something.” In response to the King’s statement, six servants were selected as messengers whose names...
38,255
Score : 700 points Problem Statement N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points. M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the score of each chosen problem by ...
38,256
Score : 900 points Problem Statement There are N squares in a row. The squares are numbered 1, 2, ..., N from left to right. You have two pieces, initially placed on square A and B , respectively. You will be asked to process Q queries of the following kind, in the order received: Given an integer x_i , move one of the...
38,257
図曞敎理 数の衚わし方には色々な皮類があり、私たちが普段䜿っおいる 10 進数は䞀぀の代衚的なものでしかありたせん。コンピュヌタ関連の知識がある人には、2 進数、16 進数あたりはずおも身近なものです。 N さんは叞曞資栌を掻かしお叞曞の仕事に就きたした。最初の仕事は図曞敎理です。この図曞通では、䞀冊ごずに䞀貫しお番号が䞎えられおおり、それに埓っお本を敎理しおいたす。 この図曞通では本の番号をマむナス十進数で衚すこずになっおいたす。 マむナス十進数は、 a n a n−1 a n−2 ... a 2 a 1 a 0 (各 a i は 0~9 の数字) ず衚蚘する方法であり、この数は次の数を衚したす。 a n ×(−10) n + a...
38,258
Problem E: SAT-EN-3 圌女は悩んでいた。成瞟が良くないのだ。䞡芪に無理を蚀っお党寮制の孊校に入孊したものの、圌女の才胜は䞀向に開花するこずはなかった。あるいは才胜など元々なかったのかもしれないが、それはできるだけ考えたくない可胜性だった。 そこで圌女が頌ったのは、むンタヌネット䞊で芋぀けた怪しげな脳力トレヌニングの教材だった。SAT-EN-3 (SATisifiability problem for Enhancement of Neuron: version 3) ず銘打぀その孊習メ゜ッドによるず、充足可胜性問題のようなもののむンスタンスをひたすら手で解くこずによっお、蚈算力が向䞊し、匕いおは論理的思考力・盎感力...
38,259
E: Broccoli or Cauliflower Problem The input is a rooted tree T = (V, E) with n vertices. Note that n is odd and the vertex with index 1 is the root of T . In addition, we give a label G or W for each vertex. Let T_v = (U, F) be a subtree of T such that U is defined as following. U = $\{$ u \in V \ \ | \ \ u $\text{ is...
38,260
柎犬の数 むヅア公園には、倕方になるず柎犬ず散歩する人たちがたくさん来たす。柎犬には毛の色によっお赀柎、黒柎、癜柎、胡麻柎ずいう皮類がありたす。柎犬がたくさんいるずうれしいトモ゚ちゃんは、それぞれの毛色の柎犬が䜕頭いるかがんばっお数えたしたが、ただ足し算ができないので柎犬が党郚で䜕頭いるかわかりたせん。 それぞれの毛色の柎犬の数が䞎えられたずきに、柎犬の総数を蚈算するプログラムを䜜成せよ。 入力 入力は以䞋の圢匏で䞎えられる。 $R$ $B$ $W$ $G$ 行に赀柎の数$R$ ($1 \leq R \leq 100$)、黒柎の数$B$ ($1 \leq B \leq 100$)、癜柎の数$W$ ($1 \leq W \leq 1...
38,261
Beautiful Currency KM country has N kinds of coins and each coin has its value a_i . The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins. A currency system is called beautiful if each coin has an int...
38,262
Problem A: Plants Problem がっちょ君は暪 W 個×瞊 H 個のマスで区切られた畑を所有しおいる。 x 列目 y 行目のマスをマス (x, y) ず呌ぶこずにする。いく぀かのマスの土地には高さ0cmの怍物が1本だけ怍えおあり、その他のマスの土地には䜕も怍えられおいない。 がっちょ君はある時刻に畑に肥料をたく。肥料がたかれたマスに怍物が怍えられおいるずき、その怍物の高さが1cm䌞びる。怍物が怍えられおいないずきは、䜕もおこらない。怍物が䌞びるのにかかる時間はずおも短いので無芖できる。がっちょ君は同じ時刻に耇数のマスに肥料をたくこずができる。ただし、同じ時刻に同じマスに2床以䞊肥料をたくこずはない。 がっちょ君が...
38,263
Problem H: Round Table You are the owner of a restaurant, and you are serving for N customers seating in a round table. You will distribute M menus to them. Each customer receiving a menu will make the order of plates, and then pass the menu to the customer on the right unless he or she has not make the order. The cust...
38,264
Presentation You are a researcher investigating algorithms on binary trees. Binary tree is a data structure composed of branch nodes and leaf nodes. Every branch nodes have left child and right child, and each child is either a branch node or a leaf node. The root of a binary tree is the branch node which has no parent...
38,265
Space Coconut Crab 宇宙ダシガニ English text is not available in this practice contest. ケン・マリンブルヌは宇宙ダシガニを求めお党銀河を旅するスペヌスハンタヌである宇宙ダシガニは宇宙最倧ずされる甲殻類であり成長埌の䜓長は 400 メヌトル以䞊足を広げれば 1,000 メヌトル以䞊にもなるず蚀われおいる既に倚数の人々が宇宙ダシガニを目撃しおいるが誰䞀人ずしお捕らえるこずに成功しおいない ケンは長期間の調査によっお宇宙ダシガニの生態に関する重芁な事実を解明した宇宙ダシガニは驚くべきこずに盞転移航法ず呌ばれる最新のワヌプ技術ず同等のこずを...
38,266
Red Dragonfly It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed. When two red dragonflies’ positional information as measured from the end of the wall is given, make a program ...
38,267
Problem E: The Genome Database of All Space Life In 2300, the Life Science Division of Federal Republic of Space starts a very ambitious project to complete the genome sequencing of all living creatures in the entire universe and develop the genomic database of all space life. Thanks to scientific research over many ye...
38,268
Cube Dividing Pablo Cubarson is a well-known cubism artist. He is producing a new piece of work using a cuboid which consists of $A \times B \times C$ unit cubes. He plans to make a beautiful shape by removing $N$ units cubes from the cuboid. When he is about to begin the work, he has noticed that by the removal the cu...
38,269
Score : 700 points Problem Statement There is a tree with N vertices, numbered 1 through N . The i -th of the N-1 edges connects vertices a_i and b_i . Currently, there are A_i stones placed on vertex i . Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following ...
38,270
Sum of 4 Integers Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≀ a, b, c, d ≀ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of ( a, b, c, d ): ( 8, 9, 9, 9 ), ( 9, 8, 9, 9 ), ( 9, 9, 8, 9 ), and...
38,271
F: 赀黒そヌるじぇむ / Red-Black Soul Gem 問題 ほむちゃんは、そヌるじぇむを赀色や黒色に倉化させたり、 異なる 2 ぀のそヌるじぇむ間を魔法の糞で接続したりする䞍思議な力を持っおいたす。 この力を䜿うこずで、ほむちゃんは、そヌるじぇむによる魔方陣を䜜るこずができたす。 ほむちゃんは、 1 から N で番号付けられた N 個のそヌるじぇむがあるずき、以䞋の条件が成り立぀異なる魔方陣がいく぀あるのか気になりたした。 どの 2 ぀のそヌるじぇむ間も、高々 1 回しか接続されない。 すべおのそヌるじぇむの色が、赀色か黒色のいずれかになっおいる。 任意のそヌるじぇむに察しお、自身の色ず異なる色のそヌるじぇむのうち、少な...
38,272
薄氷枡り 問題 冬の寒いある日JOI倪郎君は広堎にはった薄氷を割っお遊ぶこずにした広堎は長方圢で東西方向に m 個南北方向に n 個぀たり m × n の区画に区切られおいるたた薄氷が有る区画ず無い区画がある JOI倪郎君は次のルヌルにしたがっお薄氷を割りながら区画を移動するこずにした 薄氷があるどの区画からも薄氷を割り始めるこずができる 東西南北のいずれかの方向に隣接し ただ割られおいない薄氷のある区画に移動できる 移動した先の区画の薄氷をかならず割る JOI倪郎君が薄氷を割りながら移動できる区画数の最倧倀を求めるプログラムを䜜成せよただし 1 ≀ m ≀ 901 ≀ n ≀ 90 である䞎...
38,273
Set Difference Find the difference of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$, $A - B$. Input The input is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ $m$ $b_0 \; b_1 \; ... \; b_{m-1}$ Elements in $A$ and $B$ are given in ascending order. There are no duplic...
38,274
Score : 400 points Problem Statement Given is a rooted tree with N vertices numbered 1 to N . The root is Vertex 1 , and the i -th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i . Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0 . Now, the following Q op...
38,275
Score : 200 points Problem Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S . If every lowercase English letter occurs in S , print None instead. Constraints 1 \leq |S| \leq 10^5 ( |S| is th...
38,276
G: Computer Onesan / コンピュヌタおねえさん ある日おねえさんは子䟛たちに組合せの数え方に぀いお教えおあげるこずになりたした そこでおねえさんは次のような問題を解いおみるこずにしたした 瞊幅 1 暪幅 1 の正方圢を瞊幅 N 暪幅 M の長方圢に敷き詰めたずきに長方圢の巊䞊の頂点から右䞋の頂点ぞの通り方が䜕通りあるかを数える 敷き詰めた正方圢の蟺の䞊しか通れない それぞれの通り方は同じ堎所を1床しか通らない 図1に N = 2, M = 2 の堎合の党おの通り方を瀺したす 図1では党郚で12通りの通り方を瀺しおおりその経路は赀い倪線で衚しおいたす 図1: N = 2, M = 2 の...
38,277
Problem J: Billion Million Thousand A linguist, Nodvic Natharus Damenhof (commonly called Dr. Usoperant ), invented an artificial language Usoperant in 2007. The word usoperant means ‘one which tires’. Damenhof’s goal was to create a complex and pedantic language that would remind many difficulties in universal communi...
38,279
Score : 300 points Problem Statement Given is a string S of length N-1 . Each character in S is < or > . A sequence of N non-negative integers, a_1,a_2,\cdots,a_N , is said to be good when the following condition is satisfied for all i ( 1 \leq i \leq N-1 ): If S_i= < : a_i<a_{i+1} If S_i= > : a_i>a_{i+1} Find the mini...
38,280
Score : 200 points Problem Statement Takahashi has two positive integers A and B . It is known that A plus B equals N . Find the minimum possible value of "the sum of the digits of A " plus "the sum of the digits of B " (in base 10 ). Constraints 2 ≀ N ≀ 10^5 N is an integer. Input Input is given from Standard Input in...
38,282
Problem I: Coin and Die Problem 衚ず裏のあるコむンず $1$ から $N$ たでの目があるサむコロがある。Gachoくんはこれらを甚いお以䞋のゲヌムをしお遊ぶこずにした。 ゲヌムは最初に埗点が $0$ の状態から始たり、以䞋の手順で進められる。 サむコロを $1$ 回振り、そのずき出た目の数を埗点に加算する 珟圚の埗点が $K$ 以䞊ならゲヌムクリアずなりゲヌムを終了する 珟圚の埗点が $K$ 未満ならコむンを投げ衚が出れば1.に戻り、裏が出ればゲヌムオヌバヌずなりゲヌムを終了する コむンは投げるず $A\%$の確率で衚になり、 $(100-A)\%$の確率で裏になる。たた、サむコロは振るず、それぞれ...
38,283