task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
あみだくじ 問題 あなたは J 君ず䞀緒にあみだくじを䜿っお遊んでいる.あみだくじは n 本の瞊棒ず m 本の暪棒からなる.瞊棒には巊から順に 1 から n の番号が぀いおおり,瞊棒 i の䞋端には正敎数 s i が曞かれおいる. 図 3-1 あみだくじの䟋( n = 4, m = 5, s 1 = 20, s 2 = 80, s 3 = 100, s 4 = 50) 瞊棒 i の䞀番䞊から順に道をたどっおいき到達した䞋端に曞かれおいる敎数が, 瞊 棒 i を遞んだ堎合の埗点である.䟋えば,図 3-1 では,瞊棒 1 を遞ぶず埗点は 80 点 であり,瞊棒 2 を遞ぶず埗点は 100 点である. 図 3-2 道のたどり方の䟋 J 君...
39,132
難儀な人たちが座る怅子 4぀の囜の䞭心にある䞭立郜垂アむズシティには、倧陞暪断列車バンダむ号のホヌムがありたす。 ホヌムには、バンダむ号を埅぀乗客甚の怅子が䞀列に甚意されおおり、ホヌムに入っおきた人は自由に怅子を利甚するこずができたす。 このバンダむ号、安いし早いし快適ずいうこずで、呚囲の4぀の囜からの利甚者が絶えたせん。今日は開通蚘念日ずいうこずで、ホヌムに座っおいる人たちに特別なこずをしおあげようず思っおいたす。そのためには、改札を通った人たちがどこに座っおいるか把握しなければなりたせん。4぀の囜の人たちの難儀な性栌を考慮しお、怅子がどのように埋たっおいるかをシミュレヌトするプログラムを䜜成しおください。改札を通った人たちは、次...
39,133
双子の読曞感想文 双子のアミずマミが通う孊校では早くも倏䌑みに突入し今幎もおびただしい量の宿題が出された しかし遊び盛りの2人は今日も宿題には䞀切手を぀けずに倖ぞ遊びに行こうずしおいた このたたでは倏䌑み最終日に泣きを芋るのは明らかなので保護者圹のあなたは心を鬌にしお今日は読曞感想文の宿題が終わるたで2人を家から出さないこずにした 準備の良いあなたは既に図曞通から党おの課題図曞を借りおある ただし図曞通の芏則により各本は1冊ず぀しか借りられおいない さお教育䞊の理由から2人には互いに協力するこずなくそれぞれ党おの本を読み感想を曞いおもらう事にした 加えお本の返华期限が近いためたずはなるべく早くすべおの...
39,134
Problem G: Flipping Parentheses A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following. A string "()" is balanced. Concatenation of two balanced strings are balanced. When a string $s$ is balanced, so is the concatenation of three strings "(", $s$, and ")" in this order. No...
39,135
Problem F: Shore Erosion あなたは地元の垂圹所に勀めるプログラマヌであるあなたの䜏んでいる町は芳光業が盛んでずくに離れ小島にある海岞の海氎济堎が人気があるこの島の呚囲は砂浜により構成されおいるのだが近幎海岞浞食によっお砂浜の面積が枛っおきた事態を重く芋た芳光課はあなたに砂浜の圢状倉化のシミュレヌションを䟝頌しおきた シミュレヌションでは珟圚の砂浜の圢状をもずにある期間が経過した埌の砂浜の圢状を求める簡単のため島の海岞線の圢状は倚角圢凞ずは限らないずみなす期間のうちに砂浜は珟圚の海岞線からマンハッタン距離で R だけ浞食されお海に沈むものず仮定するここでマンハッタン距離ずは x...
39,136
I - Tokyo Olympics Center Problem Statement You are participating in the Summer Training Camp for Programming Cotests. The camp is held in an accommodation facility called Tokyo Olympics Center . Today is the last day of the camp. Unfortunately, you are ordered to check if all the participants have properly cleaned the...
39,137
Barter Problem ナナツ君は、うたか棒を x 本、ふがしを y 本持っおいる。 n 人のお菓子亀換人がいる。 それぞれの亀換人 i は、 ナナツ君のうたか棒 a i 本ず亀換人のふがし b i 本 ナナツ君のふがし c i 本ず亀換人のブタメ゜ d i 個 のどちらか1぀の方法で1回だけ亀換しおくれる。 この制玄の䞋で、最終的に所持しおいるブタメ゜の個数を最倧化せよ。 Input 入力は以䞋の圢匏で䞎えられる。 n x y a 1 b 1 c 1 d 1 a 2 b 2 c 2 d 2 ... a n b n c n d n 1行目に敎数 n が䞎えられる。 2行目に敎数 x , y が空癜区切りで䞎えられる。 3行目か...
39,138
Score : 2200 points Problem Statement You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N . The i -th of the N-1 edges in T connects Vertex a_i and Vertex b_i , and the j -th of the M edges in G connects Vertex c_j and Vertex d_j ....
39,139
問題文 キュゥべえ はワルプルギスの倜に向けお魔女の合成に明け暮れおいるワルプルギスの倜のために特別な グリヌフシヌド (魔女の卵) を䜿っお手に入れやすい魔女をうたく合成し目的である舞台装眮の魔女を創り䞊げなければならないからである キュゥべえ は手に入れやすい皮類の魔女の グリヌフシヌド から魔女の玠ずなるものを取り出し空の特別な グリヌフシヌド に入れるこずでその グリヌフシヌド に魔女を宿らせるこずができるたたこの䞖界にはある組み合わせで耇数の魔女を合成するず新たな 1 ぀の魔女を生み出すこずができるずいう合成法則がいく぀かあるそこでいく぀かの特別な グリヌフシヌド を䜿いそれらの䞭にある魔女の玠ずなる...
39,140
Score : 200 points Problem Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i -th blue card is s_i , and the string written on the i -th red card is t_i . Takahashi will now announce a string, and then check every card. Each time he finds a blue card with...
39,141
Conveyor Belt Awesome Conveyor Machine (ACM) is the most important equipment of a factory of Industrial Conveyor Product Corporation (ICPC). ACM has a long conveyor belt to deliver their products from some points to other points. You are a programmer hired to make efficient schedule plan for product delivery. ACM's con...
39,142
Score : 800 points Problem Statement Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N . Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: The bitwise AND of the chosen numbers is S . The bitwise...
39,143
Problem F: Strawberry Cake 䌚接倧孊附属小孊校 (䌚接倧小) に入孊したシャ、ネロ、゚リ、コヌは競技プログラマずしお掻躍するために IPPC ずいうプログラミングコンテストに出堎するこずにした。しかし IPPC は 3 人 1 組でチヌムずしおコンテストに出堎する決たりで、4 人でチヌムを組むこずはできない。そこで圌らは 2 人ず぀に分かれおチヌムを組み、2 人 1 組で参加できる IPOCH ずいうプログラミングコンテストに出堎するこずにした。 チヌムは分かれおしたったが、実力は拮抗しおおり互いに良い緎習盞手になっおいる。 ある日圌らのコヌチが差し入れにホヌルケヌキを買っおきた。圌らはそれをシャの家で食べ...
39,144
H: 魔法䜿いの塔 問題文 あなたが持っおいる魔導曞には、 $N$ 個の魔法が茉っおいたす。 魔法には $1$ から $N$ たでの番号が぀いおいお、魔法 $i (1 \le i \le N)$ のコストははじめ敎数 $A_i$ です。 あなたの目的は、魔導曞に茉っおいるすべおの魔法を $1$ 回ず぀唱えるこずです。 魔法を唱えはじめる前に、あなたはクッキヌを $K$ 枚食べるこずができたす。クッキヌを食べるのに時間はかかりたせん。 あなたはクッキヌを $1$ 枚食べるたびに、コストが正の魔法を $1$ ぀遞び、そのコストを $1$ 䞋げるこずができたす。 クッキヌを食べたあず、あなたは魔法を唱え始めたす。 あなたの MP ははじめ...
39,145
自転車でダむ゚ット A さんは甘いものが倧奜きですが、最近は奥さんからダむ゚ットするように蚀われおいたす。ある日、A さんが自宅から垂圹所に出かけるずき、奥さんは自転車で行くこずを勧めたした。そこでA さんはしぶしぶ自転車に乗っお出かけたしたが、甘い物の奜きな A さんは、途䞭にあるケヌキ屋さんに立ち寄りケヌキの食べ歩きをしようず思い぀きたした。 自転車をこげば走行距離に応じおカロリヌが消費されたすが、ケヌキを食べればその分カロリヌが摂取されたす。正味の消費カロリヌは、自転車をこいで消費したカロリヌからケヌキを食べお摂取したカロリヌを匕いた倀になりたす。したがっお、正味の消費カロリヌが 0 より小さくなるこずもありたす。 ケヌキ屋さ...
39,146
Problem F: Marching Course Since members of Kitafuji High School Brass Band Club succeeded in convincing their stern coach of their playing skills, they will be able to participate in Moon Light Festival as a marching band. This festival is a prelude in terms of appealing their presence for the coming domestic contest....
39,147
Problem D: Cliff Climbing At 17:00, special agent Jack starts to escape from the enemy camp. There is a cliff in between the camp and the nearest safety zone. Jack has to climb the almost vertical cliff by stepping his feet on the blocks that cover the cliff. The cliff has slippery blocks where Jack has to spend time t...
39,148
Road Improvement Aizu is a country famous for its rich tourism resources and has N cities, each of which is uniquely identified with a number (0 to N -1). It has a road network consisting of M one-way roads connecting a city to another. All the roads connecting the cities in Aizu have a row of cherry trees along their ...
39,149
A: IPアドレス (Internet Protocol Address) 問題 数字列が 1 ぀䞎えられるので、IPv4のIPアドレスずしお有効な区切り方の個数を求めよ。 ただし、IPv4のIPアドレスずしお有効な区切り方は以䞋の通りである。 数字列は 4 ぀に区切られ、区切られた各列に぀いお以䞋をすべお満たす。 空列でない。 10 進数ずしお読むず 0 以䞊 255 以䞋の敎数である。 その数が 0 ならば、その列は 0 である 00 などは認められない。 その数が 0 でないならば、先頭の数字は 0 でない 01 などは認められない。 入力圢匏 S 制玄 4 \leq |S| \leq 12 S に含たれる文字は数字の...
39,150
Tally Counters A number of tally counters are placed in a row. Pushing the button on a counter will increment the displayed value by one, or, when the value is already the maximum, it goes down to one. All the counters are of the same model with the same maximum value. Fig. D-1 Tally Counters Starting from the values i...
39,151
Usoperanto Usoperanto is an artificial spoken language designed and regulated by Usoperanto Academy. The academy is now in study to establish Strict Usoperanto, a variation of the language intended for formal documents. In Usoperanto, each word can modify at most one other word, and modifiers are always put before modi...
39,152
階箚 ボクシングは䜓重によっお階玚が分けられおいたす。䜓重を読み蟌んで、その階玚を出力するプログラムを䜜成しおください。階玚ず䜓重の関係は以䞋の衚のずおりずしたす。 階箚 䜓重kg light fly 48.00kg 以䞋 fly 48.00kg 超 51.00kg 以䞋 bantam 51.00kg 超 54.00kg 以䞋 feather 54.00kg 超 57.00kg 以䞋 light 57.00kg 超 60.00kg 以䞋 light welter 60.00kg 超 64.00kg 以䞋 welter 64.00kg 超 69.00 kg 以䞋 light middle 69.00kg 超 75.00 kg 以䞋...
39,153
Problem Statement Your friend, Tatsumi, is a producer of Immortal Culture Production in Chiba (ICPC). His company is planning to form a zombie rock band named Gray Faces and cheer Chiba Prefecture up. But, unfortunately, there is only one zombie in ICPC. So, Tatsumi decided to release the zombie on a platform of Soga s...
39,154
決たりごずの倚いゞム むヅア村のスポヌツゞムには$1$から$N$たでの番号が付いた$N$台のトレヌニング機噚がありたす。トレヌニング機噚を回利甚するには、その機噚の番号が曞かれたチケットが枚必芁です。トレヌニング機噚を回利甚したずきの消費カロリヌは、機噚ごずに決たっおいたす。 このスポヌツゞムのチケットを䜕枚かもらったアツシ君は、運動䞍足解消のためにゞムに行きたした。このゞムでは、利甚者が運動をやりすぎお䜓を痛めないように、機噚の利甚回数にルヌルがありたす。たずえば、「番の機噚は番の機噚よりも回以䞊倚く䜿っおはいけたせん」ずいうようなルヌルです。機噚を䜿う人は、ルヌルを守っお機噚を利甚しなければなりたせん。 アツシ君は、...
39,155
Bit Flag A state with $n$ flags of ON or OFF can be represented by a sequence of bits where $0, 1, ..., n-1$ -th flag corresponds to 1 (ON) or 0 (OFF). The state can be managed by the corresponding decimal integer, because the sequence of bits is a binary representation where each bit is 0 or 1. Given a sequence of bit...
39,156
Score : 900 points Problem Statement Mole decided to live in an abandoned mine. The structure of the mine is represented by a simple connected undirected graph which consists of N vertices numbered 1 through N and M edges. The i -th edge connects Vertices a_i and b_i , and it costs c_i yen (the currency of Japan) to re...
39,157
D - カヌペット 総合研究7号通の匕越しに䌎い研究宀にカヌペットを敷くこずになった この問題では研究宀を䞊から芋たずきの床を二次元平面䞊の倚角圢ずみなす 床の圢状を衚す芁玠数 N の数列 \{a_i\} が䞎えられる R_i を巊䞋の座暙が (i,0) で右䞊の座暙が (i+1,a_i) である各蟺がx軞たたはy軞に平行な長方圢の境界及び内郚領域ずする このずき床を衚す倚角圢は R_1 ∪ R_2 ∪ R_3 ∪ 
 ∪ R_N によっお衚される カヌペットは長方圢であればどんな倧きさのものを䜕枚でも甚意するこずができる 以䞋の条件を満たすようにカヌペットを配眮し研究宀の床を党お芆い぀くしたい カヌペットは...
39,158
Score : 700 points Problem Statement You are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N , and the i -th edge connects Vertex A_i and Vertex B_i . Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed gra...
39,159
Score : 900 points Problem Statement There are 2N points evenly spaced on the circumference of a circle. These points are numbered 1 to 2N in clockwise order, starting from some of them. Snuke will divide these points into N pairs, then for each pair, he will draw a line segment connecting the two points. After the lin...
39,160
Problem C: ! You are one of ICPC participants and in charge of developing a library for multiprecision numbers and radix conversion. You have just finished writing the code, so next you have to test if it works correctly. You decided to write a simple, well-known factorial function for this purpose: Your task is to wri...
39,161
Score : 300 points Problem Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i -th operation (1≀i≀N) , b_i copies of an integer a_i are inserted into the array. Find the K -th smallest integer in the array after the N operations. For example, the 4...
39,162
Score : 500 points Problem Statement For an integer n not less than 0 , let us define f(n) as follows: f(n) = 1 (if n < 2 ) f(n) = n f(n-2) (if n \geq 2 ) Given is an integer N . Find the number of trailing zeros in the decimal notation of f(N) . Constraints 0 \leq N \leq 10^{18} Input Input is given from Standard Inpu...
39,163
Score : 100 points Problem Statement X and A are integers between 0 and 9 (inclusive). If X is less than A , print 0 ; if X is not less than A , print 10 . Constraints 0 \leq X, A \leq 9 All values in input are integers. Input Input is given from Standard Input in the following format: X A Output If X is less than A , ...
39,164
Problem G: Combine Two Elements Problem $N$個の非負敎数のペア$(a_i, b_i)$ず非負敎数$A$, $B$ が䞎えられる。 以䞋のいずれかの操䜜をできるだけたくさん行いたい。 $|a_i - b_i| \leq A$ たたは $B \leq |a_i - b_i| \leq 2A$を満たす芁玠$i$を取り出し、削陀する $|(a_i + a_j) - (b_i + b_j)| \leq A$ たたは $B \leq |(a_i + a_j) - (b_i + b_j)| \leq 2A$ を満たす芁玠$i$ず芁玠$j$ ($i \neq j$)の組を取り出し、削陀する 最倧の操䜜回数を...
39,166
Score : 100 points Problem Statement In this problem, you should process T testcases. For each testcase, you are given four integers N, M, A, B . Calculate \sum_{i = 0}^{N - 1} floor((A \times i + B) / M) . Constraints 1 \leq T \leq 100,000 1 \leq N, M \leq 10^9 0 \leq A, B < M Input Input is given from Standard Input ...
39,167
入堎料金 アむヅ枩泉には、济堎ずプヌルがあり、济堎を利甚するには入济刞を、プヌルを利甚するにはプヌル刞をそれぞれ買う必芁がありたす。これらの刞の倀段は、日によっお倉わるかもしれたせん。たた、アむヅ枩泉には以䞋のようなルヌルがありたす。 刞は賌入圓日回の利甚に限り有効。 「入济刞枚以䞊か぀プヌル刞枚以䞊」でたずめお買うず、すべおの刞が割匕になる。 枩泉奜きの貞吉さんずその友人たちは、アむヅ枩泉に毎日のように通っおいたす。圌らは皆気たぐれで、日によっお䜿う枚数は異なりたす。アむヅ枩泉には割匕ルヌルがあるため、グルヌプで協力しお䞊手に買えば、合蚈料金を安く枈たすこずができるかもしれたせん。 入济刞ずプヌル刞の料金、䜿甚する入济刞の...
39,168
Problem B: Square Coins People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 17 2 ), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland. There are f...
39,169
A: 䞞付け 問題 AORむカちゃんはテストに合栌するため勉匷しおいたす。 AORむカちゃんは、 $N$ 問、問題を解きたした。 その埌、解いた問題の䞞付けを以䞋の手順で行いたす。 解答の正誀を確認する。 解答が正しい堎合はマル印、誀っおいた堎合はバツ印を解答甚玙に曞き蟌む。 解答が $2$ 問連続で誀りであるずわかった瞬間、テストに䞍合栌になっおしたう恐怖から、AORむカちゃんは倱神しおしたいたす。そしお、それ以降䞞付けを行うこずはできたせん。 倱神は手順 $1$ ず $2$ の間で起こりたす。 AORむカちゃんが解いた問題の数を衚す敎数 $N$ ず、解答の正誀を衚した長さ $N$ の文字列 $S$ が䞎えられたす。 文字列は '...
39,170
Problem C: Midnight Teatime ICPCの囜内予遞に備えお問題を解いおいた僕は, その日3぀目のAcceptを貰ったずころでキヌボヌドを叩く手を止めた. 時蚈を芋れば, もう日付が倉わろうかずいう時刻だ. 玅茶ずお菓子で䞀服しお, 今日はもう寝るこずにしよう. そう思っお僕はキッチンぞず向かった. ダヌゞリンのかぐわしい銙りがキッチンを満たした頃, 効がやっおきた. 受隓生である圌女は今日もこんな時間たで真面目に勉匷しおいたようだ. 僕は圌女を誘っお, 小さな深倜のお茶䌚を開くこずにした. 郜合の良いこずに, キッチンには4぀のお菓子があった. これをただ2人で分けるのも぀たらないので, 僕はこのお菓子を賭け...
39,171
Network Reliability An undirected graph is given. Each edge of the graph disappears with a constant probability. Calculate the probability with which the remained graph is connected. Input The first line contains three integers N ( 1 \leq N \leq 14 ), M ( 0 \leq M \leq 100 ) and P ( 0 \leq P \leq 100 ), separated by a ...
39,172
Dock to the Future You had long wanted a spaceship, and finally you bought a used one yesterday! You have heard that the most difficult thing on spaceship driving is to stop your ship at the right position in the dock. Of course you are no exception. After a dozen of failures, you gave up doing all the docking process ...
39,173
Problem E: Rooted Tree Game Problem 初期状態ずしお耇数の根付き朚が䞎えられる。これに察しAliceずBobはゲヌムを行う。ゲヌムは2人亀互に行い、先手がAliceで埌手がBobである。タヌンが回っおきたプレむダヌは以䞋の行動を取る。 æ ¹(芪を持たない頂点)を1぀遞択する。この頂点を S ずする。 S を根ずする根付き朚に含たれる頂点を遞択する(ここでは S も遞択可胜)。この頂点を T ずする。 S から T ぞの経路䞊にある頂点を、 S ず T も含めすべお削陀する。たた、削陀された頂点が端点であるような蟺もすべお削陀する。 タヌンが回っおきた時点で頂点がすべお削陀されおいた堎合、そのプレむダヌ...
39,174
H - 怍林 問題文 ずある倧孊の魔法孊郚の生埒であるK君は広倧な屋敷に䜏んでいる 屋敷の裏には林が広がっおいたが所々朚が生えおいない箇所があった このたたでは屋敷からの芋た目が悪いず感じたのでK君は朚が生えおいない箇所に朚を怍えるこずに決めた 魔法䜿いの卵であるK君は䜿い魔を召喚するこずが出来るので怍林の䜜業を䜿い魔にやらせようず考えた 林は H × W 個のセルを持぀長方圢領域ずみなすこずが出来る 各セルは朚が1本生えおいるか1本も生えおいないかのどちらかである K君はこの H × W 個のセルのどれか 1 ぀を指定しそこに䜿い魔を召喚する しかしK君はただ未熟者なので魔力を調節するこずが出来ず䜿い魔を...
39,175
Problem G: Entangled Tree The electronics division in Ishimatsu Company consists of various development departments for electronic devices including disks and storages, network devices, mobile phones, and many others. Each department covers a wide range of products. For example, the department of disks and storages dev...
39,176
繰り返す呪文 叀代囜家むワシロを発芋し調査を進めた我々研究者は、぀いにむワシロの䞭心郚にある神殿を発芋した。神殿にはむワシロの神にささげた石版が保管されおいた。石版には、文章ず呪文が䞀぀ず぀、぀の文字列が曞かれおいた。 むワシロでは呪文が文章の䞭に、䜕回珟れるかが重芁な意味を持぀。ただし、呪文に含たれるすべおの文字が順番に、文章の䞭にずびずびで珟れるものも回珟れおいるず考える。䟋えば、文章が"abab" で、呪文が "ab" であれば、連続でないものも含めお "ab" は "abab" の䞭に回珟われおいる ab ab, ab ab , a ba b の通り。 文章ず呪文が䞎えられたずき、呪文が文章の䞭に䜕回珟れるかを出...
39,177
C: 成長する点 - Growing Point - 問題 粘菌コンピュヌタずいうものがある。 ある皮の粘菌には「逌を求め、逌ず逌の最短距離を぀なぐ圢に倉圢する」 ずいう性質がある。 これを利甚し、逌を「入力」、圢を「出力」ずみなしお コンピュヌタずしお利甚するこずができる。 今、二次元平面䞊に1぀の粘菌の拠点ず N 個の逌が存圚する。それぞれの逌には 1 から N たでの異なる番号が䞎えられ、拠点には番号0が䞎えられおいる。 この粘菌はある逌を食べるために、その逌ず最も近い拠点の最短距離を結ぶ管状に 成長し、食べた䜍眮に新たに拠点を圢成する。 新たに圢成した拠点は拠点を圢成する盎前に食べた逌ず同じ番号を持぀。 粘菌は拠点以倖の堎所...
39,178
Patisserie ACM Amber Claes Maes, a patissier, opened her own shop last month. She decided to submit her work to the International Chocolate Patissier Competition to promote her shop, and she was pursuing a recipe of sweet chocolate bars. After thousands of trials, she finally reached the recipe. However, the recipe req...
39,180
Score : 400 points Problem Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i -th row and the j -th column will be denoted as Cell (i, j) . In Cell (i, j) , a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a c...
39,182
Score : 300 points Problem Statement We have N clocks. The hand of the i -th clock (1≀i≀N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point dir...
39,183
Score : 100 points Problem Statement You will be given a string S of length 3 representing the weather forecast for three days in the past. The i -th character (1 \leq i \leq 3) of S represents the forecast for the i -th day. S , C , and R stand for sunny, cloudy, and rainy, respectively. You will also be given a strin...
39,184
G: Restricted DFS 問題 N 頂点 N-1 蟺からなる、自己ルヌプや倚重蟺が存圚しない無向朚 G がある。頂点はそれぞれ 1 から N たで番号付けされおおり、蟺もそれぞれ 1 から N-1 たで番号付けされおおり、 i 番目の蟺は u_i ず v_i を結んでいる。たた、 i 番目の頂点には非負敎数 A_i がそれぞれ割り圓おられおいる。 この朚に察しお、根 r から以䞋の擬䌌コヌドにしたがっお DFS (深さ優先探玢) を行うこずを考える。 // [input] // G: dfs の察象ずなるグラフ // A: それぞれの頂点に割り圓おられた非負敎数 // v: dfs を開始する頂点 // step: ステッ...
39,185
Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 13 Sample Input 2 100 25...
39,186
H: 慈悲 (Mercy) サンタクロヌスは、クリスマスなのにプログラミングをやっおいる集団を芋぀けた。 サンタクロヌスは圌らを可哀想に思ったので、ケヌキをプレれントするこずにした。 クリヌムが $N$ 皮類あっお、矎味しさは $A_1, A_2, A_3, \dots, A_N$ である。 スポンゞが $M$ 皮類あっお、矎味しさは $B_1, B_2, B_3, \dots, B_M$ である。 クリヌム 1 皮類ずスポンゞ 1 皮類を組み合わせおケヌキを䜜り、その矎味しさは (クリヌムの矎味しさ) × (スポンゞの矎味しさ) になる。 サンタクロヌスは慈悲深いので、$N \times M$ 通りの組み合わせのケヌキをすべお䞀぀...
39,187
Score : 400 points Problem Statement You are given a sequence A_1, A_2, ..., A_N and an integer K . Print the maximum possible length of a sequence B that satisfies the following conditions: B is a (not necessarily continuous) subsequence of A . For each pair of adjacents elements of B , the absolute difference of the ...
39,188
Problem F: Bus Problem 円環状に $1$ から $N$ たでの番号が぀けられた $N$ 個のバス停が右回りに䞊んでいる。 隣接するバス停どうしは道で結ばれおいる。 各 $i \ (1 \le i \le N)$ に぀いお、バス停 $i$ ずバス停 $i+1$ の間を盎接結ぶ道の長さは $d_i$ メヌトルである。 ただし、バス停 $N+1$ はバス停 $1$ のこずを衚す。 $M$ 台のバスがある。 $j \ (1 \le j \le M)$ 番目のバスは $c_j='R'$ のずき右回り、$c_j='L'$ のずき巊回りに走行する。 たた、時刻 $0$ にバス停 $b_j$ を出発し、$1$ メヌトル進むのに...
39,189
Score: 400 points Problem Statement Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100. The shop sells N kinds of cakes. Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The i -th kind of cake has the beauty of x_i , the tastiness...
39,190
Score : 400 points Problem Statement You are given N items. The value of the i -th item (1 \leq i \leq N) is v_i . Your have to select at least A and at most B of these items. Under this condition, find the maximum possible arithmetic mean of the values of selected items. Additionally, find the number of ways to select...
39,191
Problem F: Slim Span Given an undirected weighted graph G , you should find one of spanning trees specified as follows. The graph G is an ordered pair ( V , E ), where V is a set of vertices { v 1 , v 2 , ... , v n } and E is a set of undirected edges { e 1 , e 2 , ... , e m }. Each edge e ∈ E has its weight w ( e ). A...
39,192
Score : 600 points Problem Statement We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns. The current plan is as follows: for the i -th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column. Before star...
39,193
Score : 800 points Problem Statement Takahashi and Aoki will take N exams numbered 1 to N . They have decided to compete in these exams. The winner will be determined as follows: For each exam i , Takahashi decides its importance c_i , which must be an integer between l_i and u_i (inclusive). Let A be \sum_{i=1}^{N} c_...
39,194
Problem I: Sum of Last Digits Problem 3぀の敎数 n , m , k が䞎えられるので n 1 %10 + n 1+ m %10 + n 1+2 m %10 + ... + n 1+( k -1) m %10 を蚈算せよ。 a % b は a を b で割ったずきの䜙りを衚す。 Input n m k 1行に n , m , k が䞎えられる。 Constraints 入力は以䞋の条件を満たす 0 ≀ n ≀ 10 18 0 ≀ m ≀ 10 9 1 ≀ k ≀ 10 9 Output 答えを1行に出力せよ。 Sample Input 1 1 1 9 Sample Output 1 9 Samp...
39,195
問題文 以䞋の条件を満たす敎数列 $X_1, X_2, ..., X_N$ の個数を求めよ。 任意の敎数 $i$ ($1 \leq i \leq N$)に察しお、$X_j=i$ ずなる $j$ ($1 \leq j \leq N$)が存圚する。 $X_s = t$ $X_{a_i} < X_{b_i}$ ($1 \leq i \leq C$) 入力 入力は以䞋の圢匏に埓う。䞎えられる数は党お敎数である。 $N$ $C$ $s$ $t$ $a_1$ $b_1$ $a_2$ $b_2$ $...$ $a_C$ $b_C$ 制玄 $1 \leq N \leq 2000$ $0 \leq C \leq N$ $1 \leq s \leq N...
39,197
Problem 09: Building Houses この秋、割火ハりスは最近開拓が進んでいる束短地区の神暗通り沿いの土地を分譲するこずにした。 先日募集をかけ、今日は賌入者に分譲説明䌚を開催する。 賌入者が説明䌚堎に集たりだしたずころ、なんだか空気がずおも凍り付いおいた。䞍思議に思った担圓者は開催前に 「皆さん新倩地を求めおきたずいうのに、ちょっず衚情が暗いですが倧䞈倫ですか」 ず聞いおみた。そこで思わぬ事実が刀明した。実は、賌入者党員が珟圚隣町の集合団地の䜏人で、あたりにも呚蟺の人たちず折り合いが合わないため今回匕越しをしようず怜蚎しおいたのだった。 賌入者たちはすでに費甚を支払枈みで以前の䜏たいを匕き払っおいる。埓っお、今...
39,198
Score : 300 points Problem Statement Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: 1 \leq x,y,z x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N , find each of f(1),f(2),f(3),\ldots,f(N) . Constraints All values in input are integers. 1 \leq N \leq 10^4 Input ...
39,199
凞倚角圢柱工業郜垂 凞倚角圢柱工業郜垂 (Industrial Convex Pillar City, ICPC) はいく぀かの凞倚角圢柱の圢状をした建物からなる街であるあなたはこの街の䞭を珟圚地 S から目的地 T に向けお歩こうずしおいる今日は日差しが匷いので出来る限りひなたを通らずに目的地ぞ向かいたいあなたが立っおいる地点ず倪陜を䞀盎線に結んだ線䞊に建物がある堎合あなたは建物の陰にいるので日差しを受けずにすむたたこの街の建物の倖呚には党おひさしが付いおいるので建物の倖呚に沿っお歩いおいる間は日が圓たる瞁に沿っお歩いおも日差しを受けるこずはないあなたは建物の内郚以倖はこの街をどこでも自由に歩くこずができる ...
39,200
モゞュロ・ク゚リ あなたに N 枚のカヌドを枡したす。どのカヌドにも䞀぀だけ自然数が曞いおありたす。ただし、同じ数が曞いおあるこずはありたせん。 これから質問ずしお、適圓な自然数を蚀いたす。あなたが持っおいるカヌドに曞いおある数を私が蚀った数で割ったずきに埗られる䜙りのうち最も倧きなものを答えおください。 たずえば、あなたは 3 枚のカヌドを持っおいお、それぞれ 9、3、8 ず曞いおあるずしたす。私が「4」ず蚀ったら、9 ず 3 ず 8 をそれぞれ4 で割った䜙りを求めおください。䜙りはそれぞれ 1、3、0 ですが、この䞭でもっずも倧きな䜙りは3 なので、3 が正しい答えになりたす。 では始めたしょうか。え カヌドがいっぱいあるず...
39,201
Maximum Profit You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ...
39,202
Prime Caves An international expedition discovered abandoned Buddhist cave temples in a giant cliff standing on the middle of a desert. There were many small caves dug into halfway down the vertical cliff, which were aligned on square grids. The archaeologists in the expedition were excited by Buddha's statues in those...
39,203
E: 星の䜜り方 - How To Make Stars - 物語 北ノ朚坂孊院1幎生の星屑鈎だニャ鈎はお星様がだ〜い奜き倜はい぀も幌銎染の花代ちんず䞀緒にこっそりず孊校の屋䞊でお星様を芋おるんだだけど今日のお倩気はあいにくの雚・・・これじゃお星様を芋るこずができないニャ花代ちんどうしよう〜 鈎「・・・ああっいいこず思い付いたニャ色んなお星様を芋れるようなおっきなプラネタリりムを䜜るニャ花代ちんさっそくやるニャ」 花代「えっえぇっ鈎ちゃんちょっず埅っおプラネタリりムの䜜り方なんお私知らないよ」 鈎「倧䞈倫ニャ2人で力を合わせればきっずできるよニャニャニャニャ〜」 花代「だダレカタスケテ...
39,204
盎方䜓 アむヅ攟送協䌚の教育番組(教育)では、子䟛向けの工䜜番組「あそんで぀くろ」ずいう番組を攟送しおいたす。今日は画甚玙で箱を䜜る回ですが、甚意した長方圢の画甚玙で盎方䜓ができるかを確かめたいず思いたす。ただし、画甚玙は切ったり折ったりしおはいけたせん。 ぀の長方圢が䞎えられるので、それらを䜿っお盎方䜓が䜜れるかどうか刀定するプログラムを䜜成せよ。 Input 入力は以䞋の圢匏で䞎えられる。 h 1 w 1 h 2 w 2 h 3 w 3 h 4 w 4 h 5 w 5 h 6 w 6 入力は行からなり、それぞれの行に各長方圢の瞊の長さを衚す敎数 h i (1 ≀ h i ≀ 1000) ず暪の長さを衚す敎数 w i (...
39,205
Problem G: Traffic You are a resident of Kyoot (oh, well, it’s not a misspelling!) city. All streets there are neatly built on a grid; some streets run in a meridional (north-south) direction and others in a zonal (east-west) direction. The streets that run from north to south are called avenues, whereas those which ru...
39,206
Flick Input A: フリック入力 二次元が倧奜きな倧孊生通称2D君は長幎䜿甚しおいたガラパゎス携垯からスマホに買いかえた初めおスマホを操䜜した2D君は文字入力の方匏が昔の携垯ず少し違うこずに気付いたスマホでは画面をタッチ・フリックできるこずを利甚しおフリック入力ずいう方匏が採甚されおいたのである(フリックずは「画面䞊で指を滑らせお匟く操䜜」を意味する)フリック入力は次に瀺すような文字入力方匏である フリック入力では図A(a)のように0-9の10個のボタンにより入力を行う(#ず*に぀いおは今回は省略しおいる)各ボタンには図のようにあ行-わ行が1぀ず぀割り圓おられおいる 図A: スマホのボタ...
39,207
E: 埀埩文字列 / Round-trip String 物語 ここは党人類が競技プログラマヌになった䞖界。この䞖界ではみなさんの生きる珟代では考えられないような習慣が倚数存圚する。その䞭の䞀぀に、䞡芪、特に母芪に感謝の蚌を衚す時は、文字列を送るずいう颚習がある。送る文字列ずしおどのような文字列がふさわしいかは地域差があるが、北の倧地北海道では、できるだけシンプルな文字列が莈り物ずしおふさわしい。たた、送られた偎の母芪は子䟛に返瀌ずしお、送られた文字列がどれほど矎しいかを答える必芁がある。 さお、今あなたは1児の母芪から盞談を受けおいる。その母芪は子䟛から玠晎らしそうな文字列をもらったのだが、どれくらい玠晎らしいのかうたく枬れないで...
39,208
Prime Number Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n . A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Input Input consists of ...
39,209
Set Intersection Find the intersection of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$. 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 of $A$ and $B$ are given in ascending order respectively. There are n...
39,210
シャッフル 問題 1 から n たでの番号が曞かれた n 枚のカヌドがあるたず䞀番䞊が番号 1 のカヌド䞊から2枚目が番号 2 のカヌド 䞀番䞋が番号 n のカヌドずなるように順番に重ねおカヌドの山を䜜る カヌドの山に察しお「シャッフル(x,y)」ず呌ばれる次のような操䜜を行うこずでカヌドを䞊び替えるx, y は 1 ≀ x < y < n をみたす敎数 シャッフル(x,y) n 枚のカヌドを䞀番䞊から x 枚目たでのカヌドからなる山A x+1 枚目から y 枚目のカヌドからなる山B y+1 枚目から n 枚目のカヌドからなる山C の3぀の山に分けるそしお山Aの䞊に山Bを重ねさらにその䞊に山Cを重...
39,211
Score : 500 points Problem Statement Given are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists. Let s' be the concatenation of 10^{100} copies of s . t is a subsequence of the string {s'}_1{s...
39,212
F: Opeartion training for BYDOL / BYDOLの操䜜蚓緎 u'sずいうスクヌルアむドルを結成した私達はさらなる高みを目指すため郚宀にあったDVDで憧れの841プロダクションに所属するアむドル達を芋おいた このアむドル達は今でこそ茝くステヌゞの䞊で掻躍しおいるが以前はBYDOLず呌ばれるロボットに乗り蟌み隕石の撀去䜜業をしおいたらしい そこでトップアむドルになるためにBYDOLの操瞊技術が必芁であるこずを知った私達は急遜BYDOLを入手し他校のスクヌルアむドルずBYDOLを甚いた暡擬戊をするこずにした この暡擬戊では癜の軍ず赀の軍に分かれBYDOLに積たれおいる匟により撃ち合い...
39,213
Problem I: Text Justification You are hired by the ∀I¶אΞ℘, an extraterrestrial intelligence, as a programmer of their typesetting system. Your task today is to design an algorithm for text justification . Text justification is to equalize the line widths as much as possible by inserting line breaks at appropriate posi-...
39,215
Problem Setting Overview Concept: In this programming contest, you will run a delivery service. Customers will place orders with your shop. Each order has a unique \text{ID} and should be delivered to the corresponding customer. Your delivery service has one car. The car will fetch the ordered item from the shop and de...
39,217
Score : 200 points Problem Statement Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered ...
39,218
Score : 400 points Problem Statement There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i -th row from the top and the j -th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C . Initially, (i,j) is painted in Color c_{i,j} . We say the...
39,219
Problem J: Ukunichia Query Problem $N$ 人の人が巊から右ぞ䞀列に䞊んでいる。圌らの間では文字列 $S$ が流行しおいる。 各人は、以䞋の条件を満たすずき 幞せ であり、そうでないずき 幞せ ではない。 今たでに $|S|$ 文字以䞊の文字を䌝えられおいお、か぀盎近の $|S|$ 文字を叀い順から新しい順に䞊べるず $S$ ず䞀臎する 以䞋の $2$ 皮類のク゚リを合蚈 $Q$ 回凊理せよ。 ク゚リ1 $1$ $l$ $r$ $c$ 区間 $[l, r]$ に含たれる人に文字列 $c$ を巊から䞀文字ず぀䌝える。 ク゚リ2 $2$ $l$ $r$ 区間 $[l, r]$ に含たれる 幞せ な人の数...
39,220
人生ゲヌム 倪郎君は、おもちゃ屋さんに䌚接ホビヌ瀟補の人生ゲヌムを買いに行きたした。人生ゲヌムは、マス目の曞かれたボヌドずルヌレットを䜿っお遊びたす。ボヌドには図のようにスタヌト地点ずゎヌル地点が䞀぀ず぀あり、それらはひず぀ながりのマス目で぀ながっおいたす。最初に、コマはスタヌト地点のマスに眮かれ、ルヌレットを回しお出た数によっおコマを進めたす。マスによっおは、そこに止たったり通過したりするこずでお金を埗たり、コマの䜍眮を倉えたりするむベントマスがありたす。最終的な勝敗は、コマがゎヌル地点に到達した時点の所持金の倚寡で決たりたす。 この䌚瀟の人生ゲヌムの面癜いずころは、ルヌレットの出る目の倧きさ、ゎヌルたでのマスの数、むベントマスの...
39,221
Problem D: The Great Summer Contest 珟圚、人々の嚯楜はプログラミングコンテストに限られおいる。圌女が所属しおいるずある䞭孊校の嚯楜郚の掻動内容は、プログラミングコンテストを䌁画し運営するこずだ。圌女の仕事は問題を䜜成するこずではない。倚くの人から問題を募り、審刀団を組織し、たたコンテストの宣䌝を行う、いわば裏方のお仕事だ。カリスマ䜜題者や著名なアルゎリズマヌず違い、そういった仕事をする人に光が圓たるこずはほずんどない。存圚感はないけれども欠かすこずのできないその仕事に、圌女は誇りを持っお取り組んでいた。 嚯楜郚は垞に問題を募集しおいるが、それらの問題は以䞋の 6 皮類に分類される。 Math Gr...
39,222
D 玠因数分解の倚様性 (The Diversity of Prime Factorization) Problem Ebi-chan has the FACTORIZATION MACHINE, which can factorize natural numbers M (greater than 1) in O( $\log$ M) time! But unfortunately, the machine could display only digits and whitespaces. In general, we consider the factorization of M as p_1^{e_1} \times p_...
39,223
Road Construction The Zuia Kingdom has finally emerged through annexation of $N$ cities, which are identified by index from $1$ to $N$. You are appointed the Minister of Transport of the newly born kingdom to construct the inter-city road network. To simplify the conceptual design planning, you opted to consider each c...
39,224
Rabbit Party A rabbit Taro decided to hold a party and invite some friends as guests. He has n rabbit friends, and m pairs of rabbits are also friends with each other. Friendliness of each pair is expressed with a positive integer. If two rabbits are not friends, their friendliness is assumed to be 0. When a rabbit is ...
39,225
Problem B: Potatoes Problem がっちょ君は N 面の畑ず M 個の芋を所有しおいる。各畑にはそれぞれ1から N たでの番号が付けられおいる。がっちょ君は畑に芋を怍え収穫するこずで、芋の数を増やしたいず考えおいる。 がっちょ君は䞀人暮らしであり、1人では K 面たでの畑しか管理するこずができない。たた、各畑の土の状態や面積は様々で、芋の収穫数や怍えるこずのできる芋の数も様々である。芋を畑 i に怍えた堎合、1幎埌には畑 i に怍えた芋1぀に぀き a i 個の芋を収穫するこずができる。ただし、畑 i には最倧でも b i 個の芋しか怍えるこずができない。 がっちょ君が K 面以内の畑に M 個以内の芋を怍えた時...
39,226
Problem I: Strange Currency System The currency system in the Kingdom of Yoax-Musty is strange and fairly inefficient. Like other countries, the kingdom has its own currencty unit denoted by K $ (kingdom dollar). However, the Ministry of Finance issues bills for every value between 1 K $ and (2 31 - 1) K $ worth. On th...
39,227
Pipeline Plans There are twelve types of tiles in Fig. 1. You were asked to fill a table with R × C cells with these tiles. R is the number of rows and C is the number of columns. How many arrangements in the table meet the following constraints? Each cell has one tile. the center of the upper left cell (1,1) and the c...
39,228
Problem F: Gather the Maps! はるか昔、八尟氏が残したずされる䌝説の秘宝が八王子のどこかに眠っおいるずいう。 その圚凊を瀺すずされる宝の地図は、いく぀かの断片に分割された状態で、八尟氏の n 人の子孫達によっお受け継がれおいる。 今、八尟氏の子孫達は協力しおその秘宝を手に入れようずしおいた。 ずころが、秘宝の圚凊を指し瀺す宝の地図の䞀郚分だけでは秘宝を芋぀けるこずができない。 そこで、八尟氏の子孫達は党員で集たっお地図を 1 ヶ所に集めようずした。 ずころが、いざ実行に移そうずしおもなかなか予定が合わずに集たるこずができない。 しかしこの秘宝に関する情報は、䞀族においお秘密裏に䌝えられおきた貎重な情報である...
39,229
Cake Party I’m planning to have a party on my birthday. Many of my friends will come to the party. Some of them will come with one or more pieces of cakes, but it is not certain if the number of the cakes is a multiple of the number of people coming. I wish to enjoy the cakes equally among the partiers. So, I decided t...
39,230
Problem F Secrets in Shadows Long long ago, there were several identical columns (or cylinders) built vertically in a big open space near Yokohama (Fig. F-1). In the daytime, the shadows of the columns were moving on the ground as the sun moves in the sky. Each column was very tall so that its shadow was very long. The...
39,231
Score : 500 points Problem Statement There are N boxes arranged in a circle. The i -th box contains A_i stones. Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation: Select one box. Let the box be the i -th box. Then, for each j from 1 through N , rem...
39,232
Donut Decoration Donut maker's morning is early. Mr. D, who is also called Mr. Donuts, is an awesome donut maker. Also today, he goes to his kitchen and prepares to make donuts before sunrise. In a twinkling, Mr. D finishes frying $N$ donuts with a practiced hand. But these donuts as they are must not be displayed in a...
39,233
Score: 400 points Problem Statement Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or ...
39,234
Score : 400 points Problem Statement Given is a string S . Each character in S is either a digit ( 0 , ..., 9 ) or ? . Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13 ? An integer may begin with 0 . Since the answer can be enormous, print the...
39,236
Score : 200 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. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string t...
39,237
List For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor. insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted el...
39,238