task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Problem G: Yu-kun Likes a Treasure Background 䌚接倧孊付属幌皚園はプログラミングが倧奜きな子䟛が集たる幌皚園である。園児の䞀人であるゆう君は、プログラミングず同じくらい財宝が倧奜きだ。ゆう君は今日も財宝を探すため掞窟を探玢する予定だ。そこでゆう君は掞窟の地図から、掞窟を党お芋お回る際に歩く距離を求めるプログラムを曞くこずにした。 Problem 掞窟の情報ずゆう君の初期䜍眮が䞎えられる。Fig.1のように、 掞窟は2次元平面䞊の倚角圢で衚される郚屋が、぀以䞊繋がった集合で構成される。郚屋が別の郚屋ず接する堎合は必ず点で接し、その接点が掞窟の道ずなり、接点に蚪れるずその道を通ったこずにな...
38,064
G: Quest of Merchant ICPC で良い成瞟を収めるには修行が欠かせないうさぎは ICPC で勝ちたいので今日も修行をするこずにした 今日の修行は街を駆け回り亀易を行うこずで商売の力を手にしようずいうものである 今埌の修行のためにもできるだけ倚くの資金を皌ぎたい この䞖界は東西南北方向の道路が等間隔に䞊んでいお碁盀状になっおいる唯䞀存圚する垂堎の䜍眮を (0, 0)街には x 座暙 y 座暙が定たっおいる (座暙が敎数倀の点が亀差点に察応する)うさぎは道路に沿っおのみ移動するこずができ隣接する亀差点間を移動するのに 1 分を芁するいく぀かの亀差点には街がある亀易では街で商品を買い...
38,066
Score : 1600 points Problem Statement You are given a string S of length 2N , containing N occurrences of a and N occurrences of b . You will choose some of the characters in S . Here, for each i = 1,2,...,N , it is not allowed to choose exactly one of the following two: the i -th occurrence of a and the i -th occurren...
38,067
Problem E: Safe Area Nathan O. Davis is challenging a kind of shooter game. In this game, enemies emit laser beams from outside of the screen. A laser beam is a straight line with a certain thickness. Nathan moves a circular-shaped machine within the screen, in such a way it does not overlap a laser beam. As in many sh...
38,068
Score : 2000 points Problem Statement There are N cards. The two sides of each of these cards are distinguishable. The i -th of these cards has an integer A_i printed on the front side, and another integer B_i printed on the back side. We will call the deck of these cards X . There are also N+1 cards of another kind. T...
38,069
Score: 200 points Problem Statement Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (ro...
38,070
歩くサンタクロヌス(Walking Santa) 昚幎末サンタクロヌスはJOI 村の子䟛たちにクリスマスプレれントを枡すのを忘れおしたったそこでお詫びの気持ちずしお子䟛たちにチョコレヌトケヌキを届けるこずにした届けるべき日は明日に迫っおいるのでそろそろ移動蚈画を考えなければならない JOI 村は南北方向にたっすぐに䌞びる W 本の道路ず東西方向にたっすぐに䌞びる H 本の道路により碁盀の目の圢に区分けされおいる. 南北方向の W 本の道路には西から順に1, 2, ... , W の番号が付けられおおり東西方向の H 本の道路には南から順に1, 2, ... , H の番号が付けられおいる. 西から x 番目の...
38,071
Problem E: Donut Hole Problem あなたはACPCのために暪$W$瞊$H$の長方圢で平べったく、穎のないドヌナツを持参したした。 このドヌナツを$2$次元平面䞊の座暙$(0,0)$にドヌナツの䞭心を重ね、長さがHの蟺ず$y$軞が平行になるように眮きたす。 ACPC$1$日目にあなたは座暙($x$,$y$)を䞭心に暪$w$瞊$h$の範囲に存圚するドヌナツを食べたした。 $2$日目ず$3$日目に食べる量を等しくしたいあなたは、座暙$(0,0)$を通る盎線でドヌナツを分割し、盎線の片偎の領域にあるドヌナツの面積の総和がもう片偎の領域にあるドヌナツの面積の総和ず等しくなっおいるようにしたいず考えおいたす。 そのよう...
38,072
カヌド䞊べ 問題 花子さんは n 枚4 ≀ n ≀ 10のカヌドを䞊べお遊んでいる それぞれのカヌドには 1 以䞊 99 以䞋の敎数が 1 ぀ず぀曞かれおいる 花子さんはこれらのカヌドの䞭から k 枚2 ≀ k ≀ 4を遞び 暪䞀列に䞊べお敎数を䜜るこずにした 花子さんは党郚で䜕皮類の敎数を䜜るこずができるだろうか 䟋えば1, 2, 3, 13, 21 の 5 枚のカヌドが䞎えられそこから 3 枚を遞び敎数を䜜るこずを考える 2, 1, 13 をこの順に䞊べるず敎数 2113 を䜜るこずができる たた21, 1, 3 をこの順に䞊べおも同じ敎数 2113 を䜜るこずができる このように異なるカヌ...
38,073
Equal Range For a given sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, print a pair of the lower bound and the upper bound for a specific value $k$ given as a query. lower bound: the place pointing to the first element greater than or equal to a specific value, or $n$ if there is no such ...
38,074
コンビニ コンビニ゚ンスストア・デブンむレブンは事業を広げるため若束垂に䞀店舗目をオヌプンしようず考えおいたす。若束垂には既に他のたくさんのコンビニ゚ンスストアがあるので、新店舗をオヌプンする堎所が成功の鍵を握るこずになりそうです。デブンむレブンは「お客さんは自分の䜏んでいる地域から最も近いコンビニを利甚する」ずいう前提の䞋、「倚くのお客さんが利甚するであろう地点」に出店するこずにしおいたす。 デブンむレブンは、既蚭の各コンビニがカバヌしおいる範囲を把握するため、若束垂の地図を合同な正六角圢(以埌「ブロック」)を甚いお区分したした。このずき、各ブロックには既蚭のコンビニが倚くずも䞀぀だけ入るように区分したした。この地図䞊で、各ブロッ...
38,075
ロヌマ数字 叀代ロヌマでは数を数えるこずは難しい仕事でした。アラビア数字の 0,1,2,3,
, 9 はただ流垃しおいたせんでした。その代わり次のような蚘号が䜿われおいたした。 アラビア数字 ロヌマ数字 アラビア数字 ロヌマ数字 アラビア数字 ロヌマ数字 1 I 11 XI 30 XXX 2 II 12 XII 40 XL 3 III 13 XIII 50 L 4 IV 14 XIV 60 LX 5 V 15 XV 70 LXX 6 VI 16 XVI 80 LXXX 7 VII 17 XVII 90 XC 8 VIII 18 XVIII 100 C 9 IX 19 XIX 500 D 10 X 20 XX 1000 M I は 1...
38,076
Problem A. GuruGuru You are playing a game called Guru Guru Gururin . In this game, you can move with the vehicle called Gururin. There are two commands you can give to Gururin: ' R ' and ' L '. When ' R ' is sent, Gururin rotates clockwise by 90 degrees. Otherwise, when ' L ' is sent, Gururin rotates counterclockwise ...
38,077
Problem F: Voronoi Island Some of you know an old story of Voronoi Island. There were N liege lords and they are always involved in territorial disputes. The residents of the island were despaired of the disputes. One day, a clever lord proposed to stop the disputes and divide the island fairly. His idea was to divide ...
38,079
C - Decoding Ancient Messages Problem Statement Professor Y's work is to dig up ancient artifacts. Recently, he found a lot of strange stone plates, each of which has $N^2$ characters arranged in an $N \times N$ matrix. Further research revealed that each plate represents a message of length $N$. Also, the procedure to...
38,080
Problem G: Test Case Tweaking You are a judge of a programming contest. You are preparing a dataset for a graph problem to seek for the cost of the minimum cost path. You've generated some random cases, but they are not interesting. You want to produce a dataset whose answer is a desired value such as the number repres...
38,081
Score : 700 points Problem Statement You are given N points (x_i,y_i) located on a two-dimensional plane. Consider a subset S of the N points that forms a convex polygon. Here, we say a set of points S forms a convex polygon when there exists a convex polygon with a positive area that has the same set of vertices as S ...
38,082
Problem B: あみだくじ Problem Statement 䌚接合宿に参加予定の高槻さんは、家が貧乏であり、い぀も玙をなるべく節玄しお䜿うようにしおいる。圌女は、䌚接合宿のチヌム決めのために、他の参加者の人達ずあみだくじをするこずになった。 この合宿のあみだくじの䜜り方は次のようなものである。たず、玙にN本の瞊棒を平行に曞く。そしお、M本の暪棒を䞊から順番に、瞊棒ず垂盎になるように、か぀暪棒の高さが党お異なるように曞いおいく。䟋えば、Sample Input 1のあみだは、図1のようになる。 ここで、高槻さん、ちょっず䞍満げな衚情。こんなに瞊長にあみだくじを曞いおいるず玙がもったいない。もっず、高さを圧瞮できるはず。ずいう...
38,083
Score : 1600 points Problem Statement Snuke found a random number generator. It generates an integer between 0 and N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{N-1} represents the probability that each of these integers is generated. The integer i ( 0 \leq i \leq N-1 ) is generated with probability A_i / S...
38,084
参加者数 遞手のみなさん、パ゜コン甲子園にようこそ。パ゜コン甲子園では、珟圚、プログラミング郚門、モバむル郚門、そしお、いちたいの絵郚門、蚈郚門の競技が開催されおいたす。 各郚門の参加者数が䞎えられたずき、参加者の総数を蚈算するプログラムを䜜成せよ。 Input 入力は以䞋の圢匏で䞎えられる。 p m c 入力は行であり、プログラミング郚門の参加者数 p (0 ≀ p ≀ 10000)、モバむル郚門の参加者数 m (0 ≀ m ≀ 10000)、いちたいの絵郚門の参加者数 c (0 ≀ c ≀ 10000) が䞎えられる。 Output 参加者の総数を行に出力する。 Sample Input 1 10 10 20 Sa...
38,085
A : 指折り数えお / Finger Counting 問題文 肉西くんは指の数を増やしたり枛らしたりできる 肉西くんの前には n 個のたんじゅうがある 肉西くんは指を折っおたんじゅうの個数を数えようずしおいる 肉西くんの指が取れる圢は折れおいるか折れおいないかの 2 ぀しか無い 肉西くんは 2 進数 を理解しおいる 肉西くんは各指に 2 進数の桁を察応させお数を数えるこずが出来る 肉西くんは察数を理解しおいない 肉西くんのかわりにたんじゅうを数え䞊げるのに必芁な指の本数の最小倀を求めよ 入力 n 制玄 敎数である 0 ≀ n ≀ 10 18 出力 答えを 1 行に出力し最埌に改行を出力せよ サンプル サンプル...
38,086
Problem A: Next Mayor One of the oddest traditions of the town of Gameston may be that even the town mayor of the next term is chosen according to the result of a game. When the expiration of the term of the mayor approaches, at least three candidates, including the mayor of the time, play a game of pebbles, and the wi...
38,087
Complete Binary Tree A complete binary tree is a binary tree in which every internal node has two children and all leaves have the same depth. A binary tree in which if last level is not completely filled but all nodes (leaves) are pushed across to the left, is also (nearly) a complete binary tree. A binary heap data s...
38,088
Problem G: Shelter Taro lives in a town with N shelters. The shape of the town is a convex polygon. He'll escape to the nearest shelter in case of emergency. Given the current location, the cost of escape is defined as the square of the distance to the nearest shelter. Because emergency occurs unpredictably, Taro can b...
38,089
Problem D: Divisor is the Conqueror Divisor is the Conquerer is a solitaire card game. Although this simple game itself is a great way to pass one’s time, you, a programmer, always kill your time by programming. Your task is to write a computer program that automatically solves Divisor is the Conquerer games. Here is t...
38,090
Score : 100 points Problem Statement There are N blocks, numbered 1, 2, \ldots, N . For each i ( 1 \leq i \leq N ), Block i has a weight of w_i , a solidness of s_i and a value of v_i . Taro has decided to build a tower by choosing some of the N blocks and stacking them vertically in some order. Here, the tower must sa...
38,092
Problem H: Sky Jump Dr. Kay Em, a genius scientist, developed a new missile named "Ikan-no-i." This missile has N jet engines. When the i -th engine is ignited, the missile's velocity changes to ( vx i , vy i ) immediately. Your task is to determine whether the missile can reach the given target point ( X , Y ). The mi...
38,093
Problem I: Rolling Block Problem Rolling Blockは盎方䜓の金属䜓を回転させ぀぀移動させ、ゎヌルの穎に萜ずすゲヌムである。 このゲヌムのクリア条件は金属䜓をゎヌルに萜ずすこずである。 ブロックに぀いお 䞋の図の(1)より、ブロックは1×1× L の盎方䜓である。 ブロックは東西南北のどれかの方向に回転しながら移動するこずができる。 しかし、ブロックはステヌゞからはみ出るような動きをずるこずは出来ない。 䞋の図の(2)より、ブロックが暪に倒れおいる堎合は移動方向に察しおこのような回転をし぀぀移動する。 䞋の図の(3)より、ブロックが盎立しおいる堎合は移動方向に察しおこのような回転をし぀぀移動す...
38,095
Score : 100 points Problem Statement We have A apples and P pieces of apple. We can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan. Find the maximum number of apple pies we can make with what we have now. Constraints All values in input are integers. 0 \leq A, ...
38,096
Score : 400 points Problem Statement Given is a positive integer N . Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition: When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B , and the first digit of A i...
38,098
Search II You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q i...
38,099
パむプ぀なぎ職人の絊料 がくはパむプ぀なぎ職人です。パむプを぀なぐゞョむントずパむプさえもらえれば、どんなパむプだっお぀ないでみせたす。がくは毎日、芪方からパむプずゞョむントを枡されお、それを぀ないで芪方に枡したす。でも、パむプの数が倚すぎるずきは、日でそれを党郚぀なげるこずはできたせん。そんなずきでも芪方はにっこり笑っお、がくに絊料を枡しおくれたす。 ずころで、あるずき倉なこずに気が぀きたした。党郚のパむプを぀なげられたずきより、぀なげられなかったずきの方が絊料が倚いこずがしょっちゅうあるんです。あんたり倉なので、ある日、芪方が来たずきに、絊料の蚈算方法が曞いおあるメモをこっそり芋ちゃいたした。そしたら、なんず "絊料は「パむプ...
38,100
B: だんすなうwww - Dance Now! - 物語 前回のラボラむフダむガクむン マスタヌアむドルたちが競う最倧の倧䌚「ラボラむフ」の前哚戊ずもいえるむベント「マスタヌアむドルワヌルド」で9䜍を取っおしたったドサンコスノヌ。 キレのあるダンスは「9䜍の舞」、枟身の決めポヌズも「9䜍の構え」などず冷やかされおしたい、心に深い傷を負っおしたう。 来たるラボラむフ予備予遞では絶察に9䜍をずるわけにはいかない   決意を新たにしたドサンコスノヌは、自分たちの特技「セルフコントロヌル」に磚きをかけ、決戊の地ぞず向かうのだった。 問題 N 組のナニットが競う倧䌚「ラボラむフ」が開かれる。 この倧䌚では、スマむル・ピュア・クヌルの3...
38,101
Score : 2000 points Problem Statement Given are integers N and K , and a prime number P . Find the number, modulo P , of directed graphs G with N vertices that satisfy below. Here, the vertices are distinguishable from each other. G is a tournament, that is, G contains no duplicated edges or self-loops, and exactly one...
38,102
Problem A: Vampirish Night There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each vampire has his/her favorite amount for e...
38,103
ガ゜リンスタンド 癜虎サヌビス゚リアのガ゜リンスタンドには、$1$から$N$の番号が割り圓おられた$N$個のレヌンがありたす。各レヌンの先頭の車が絊油を行うこずができたす。 ガ゜リンスタンドに入堎した車は、䞊んでいる車が最も少ないレヌンを遞び列の末尟に䞊びたす。そのようなレヌンが耇数ある堎合は、番号が最も小さいレヌンを遞びたす。絊油が終わるずその車はレヌンから出おいき、その埌ろの車が絊油を行いたす。䞀床レヌンを遞んだら、他のレヌンに移るこずはできたせん。たた、レヌンに䞊んでいる車の順番が倉わるこずはありたせん。 レヌンの数、入堎した車ず絊油が終了したレヌンの情報が䞎えられたずき、絊油が終了した車のナンバヌを順番に出力するプログラムを...
38,104
泥棒 宝物がたくさん収蔵されおいる博物通に、泥棒が倧きな颚呂敷を䞀぀だけ持っお忍び蟌みたした。盗み出したいものはたくさんありたすが、颚呂敷が耐えられる重さが限られおおり、これを超えるず颚呂敷が砎れおしたいたす。そこで泥棒は、甚意した颚呂敷を砎らず䞔぀最も䟡倀が高くなるようなお宝の組み合わせを考えなくおはなりたせん。 颚呂敷が耐えられる重さ W 、および博物通にある個々のお宝の䟡倀ず重さを読み蟌んで、重さの総和が W を超えない範囲で䟡倀の総和が最倧になるずきの、お宝の䟡倀総和ず重さの総和を出力するプログラムを䜜成しおください。ただし、䟡倀の総和が最倧になる組み合わせが耇数あるずきは、重さの総和が小さいものを出力するこずずしたす。 I...
38,105
Score : 400 points Problem Statement Takahashi will play a game using a piece on an array of squares numbered 1, 2, \cdots, N . Square i has an integer C_i written on it. Also, he is given a permutation of 1, 2, \cdots, N : P_1, P_2, \cdots, P_N . Now, he will choose one square and place the piece on that square. Then,...
38,106
Problem B: Compress Files Your computer is a little old-fashioned. Its CPU is slow, its memory is not enough, and its hard drive is near to running out of space. It is natural for you to hunger for a new computer, but sadly you are not so rich. You have to live with the aged computer for a while. At present, you have a...
38,107
Score : 300 points Problem Statement You are given a string S consisting of digits between 1 and 9 , inclusive. You can insert the letter + into some of the positions (possibly none) between two letters in this string. Here, + must not occur consecutively after insertion. All strings that can be obtained in this way ca...
38,108
Problem Statement A magician lives in a country which consists of N islands and M bridges. Some of the bridges are magical bridges, which are created by the magician. Her magic can change all the lengths of the magical bridges to the same non-negative integer simultaneously. This country has a famous 2-player race game...
38,109
Problem G Do Geese See God? A palindrome is a sequence of characters which reads the same backward or forward. Famous ones include "dogeeseseegod" ("Do geese see God?"), "amoreroma" ("Amore, Roma.") and "risetovotesir" ("Rise to vote, sir."). An ancient sutra has been handed down through generations at a temple on Tsuk...
38,110
Score : 600 points Problem Statement Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \{a_{1}, a_{2}, ..., a_{N}\} of distinct positive integers is called special if for all 1 \leq i \leq N , the gcd (greatest common divisor...
38,111
Score : 100 points Problem Statement The door of Snuke's laboratory is locked with a security code. The security code is a 4 -digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same. You are given the current security code S . If S is hard to enter, print Bad ; ...
38,113
Problem H: Ropeway On a small island, there are two towns Darkside and Sunnyside, with steep mountains between them. There’s a company Intertown Company of Package Conveyance; they own a ropeway car between Darkside and Sunnyside and are running a transportation business. They want maximize the revenue by loading as mu...
38,114
問題 E : Pattern Language 問題文 m 個の盞異なるアルファベット var_0, var_1, 
 , var_{m-1} がある 0, 1, 
 , 9, var_0, var_1, 
 , var_{m-1} の 10+m 皮類の文字からなる長さ N の文字列 s_0s_1s_2
s_{N-1} が䞎えられる この文字列における各アルファベットを数字で眮き換えお回文になるようにしたい(回文ずは前から読んでも埌ろから読んでも同じ文字列をあらわす) ここで同じアルファベットは同じ数字で眮き換えなければならないたた䞎えられたすべおのアルファベット var_i は少なくずも䞀床は文字列 s_0s_1...
38,115
Problem B: e-Market The city of Hakodate recently established a commodity exchange market. To participate in the market, each dealer transmits through the Internet an order consisting of his or her name, the type of the order (buy or sell), the name of the commodity, and the quoted price. In this market a deal can be m...
38,116
Score : 500 points Problem Statement We have a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i -th row from the top and the j -th column from the left. The square (i, j) has two numbers A_{ij} and B_{ij} written on it. First, for each square, Takahashi paints one of the written ...
38,117
C: Shuttle Run Story University H has a unique physical fitness test program, aiming to grow the mindset of students. Among the items in the program, shuttle run is well-known as especially eccentric one. Surprisingly, there are yokans (sweet beans jellies) on a route of the shuttle run. Greedy Homura-chan would like t...
38,118
å°Ÿæ ¹ (Ridge) 問題 JOI カルデラは景芳の良さが倚くの登山家に愛される矎しい地圢である 特に尟根ず呌ばれる堎所からの景芳は絶景である JOI カルデラの土地は南北 H キロメヌトル東西 W キロメヌトルの長方圢である 南北東西に 1 キロメヌトルごずに JOI カルデラの土地を分けこれら H×W 個の領域を区域ず呌ぶ すべおの区域においおその䞭では暙高は等しいたた異なる区域の暙高は異なる ある区域に雚が降るず雚氎はその区域に東西南北に隣り合う最倧で 4 ぀の区域のうち 暙高がその区域より䜎いような区域のすべおに流れるそのような区域がない堎合雚氎はその区域に溜たる 他の区域から流れおきた雚氎...
38,119
Carry a Cheese Jerry is a little mouse. He is trying to survive from the cat Tom. Jerry is carrying a parallelepiped-like piece of cheese of size A × B × C . It is necessary to trail this cheese to the Jerry's house. There are several entrances in the Jerry's house. Each entrance is a rounded hole having its own radius...
38,120
Score : 500 points Problem Statement You are given two integers A and B . Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section: Let the size of the grid be h \times w ( h vertical, w horizontal). Both h and w are at most 100 . The se...
38,121
Problem E: Laser Puzzle An explorer John is now at a crisis! He is entrapped in a W times H rectangular room with a embrasure of laser beam. The embrasure is shooting a deadly dangerous laser beam so that he cannot cross or touch the laser beam. On the wall of this room, there are statues and a locked door. The door lo...
38,122
Score : 1200 points Problem Statement You are given a simple connected undirected graph G consisting of N vertices and M edges. The vertices are numbered 1 to N , and the edges are numbered 1 to M . Edge i connects Vertex a_i and b_i bidirectionally. It is guaranteed that the subgraph consisting of Vertex 1,2,\ldots,N ...
38,123
B: サむコロを転がさないで 問題文 $H$ 行 $W$ 列からなるグリッドがありたす。以降、グリッド䞊の $i$ 行目 $j$ 列目のマスを $(i, j)$ のマスず曞きたす。 グリッドの各マスには、$1$ 以䞊 $6$ 以䞋の数字か、あるいは # の文字が $1$ ぀ず぀曞かれおいたす。 ただし、$i$ ず $j$ がずもに偶数であるような $(i, j)$ のマスには必ず # が曞かれおいたす。 あなたは以䞋の図で衚されるようなサむコロを $1$ ぀持っおいたす。 最初、あなたはこのサむコロを底面が $6$, 前面が $2$, 右面が $3$ ずなるように $(1, 1)$ のマスに眮きたす。 ここで、前面は $(i, j)...
38,124
Dungeon 2 Bob is playing a game called "Dungeon 2" which is the sequel to the popular "Dungeon" released last year. The game is played on a map consisting of $N$ rooms and $N-1$ roads connecting them. The roads allow bidirectional traffic and the player can start his tour from any room and reach any other room by way o...
38,125
Score : 200 points Problem Statement Snuke is interested in strings that satisfy the following conditions: The length of the string is at least N . The first N characters equal to the string s . The last N characters equal to the string t . Find the length of the shortest string that satisfies the conditions. Constrain...
38,126
Score : 500 points Problem Statement There are N infants registered in AtCoder, numbered 1 to N , and 2\times 10^5 kindergartens, numbered 1 to 2\times 10^5 . Infant i has a rating of A_i and initially belongs to Kindergarten B_i . From now on, Q transfers will happen. After the j -th transfer, Infant C_j will belong t...
38,127
The Number of Windows For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and $Q$ integers $x_i$ as queries, for each query, print the number of combinations of two integers $(l, r)$ which satisfies the condition: $1 \leq l \leq r \leq N$ and $a_l + a_{l+1} + ... + a_{r-1} + a_r \leq x_i$. Constraints $1 \leq ...
38,128
知識の蚌明 あなたが䜏んでいる集合䜏宅の入口のドアにはパスワヌド匏のロックがかけられおいるこのパスワヌドはちょうど 4 桁の 0 から 9 の範囲の数字で構成されおおりあなたはい぀も集合䜏宅の管理人から䌝えられたパスワヌド P を䜿っおこのドアのロックを解陀しおいる ある日あなたは集合䜏宅の䜏民党員が自分ず同じパスワヌド P を䜿っおいるのかどうか気になり同じ集合䜏宅に䜏む友人に尋ねるこずにしたあなたずあなたの友人は自分のパスワヌドを互いに䌝えあうこずで同じパスワヌドを䜿っおいるのかどうか確かめ合うこずができるしかしながらパスワヌドがそれぞれの䜏民に個別に割り圓おられおいる可胜性を考えるずこの方法は奜た...
38,129
Fermat's Last Theorem In the 17th century, Fermat wrote that he proved for any integer $n \geq 3$, there exist no positive integers $x$, $y$, $z$ such that $x^n + y^n = z^n$. However he never disclosed the proof. Later, this claim was named Fermat's Last Theorem or Fermat's Conjecture. If Fermat's Last Theorem holds in...
38,130
Change a Password Password authentication is used in a lot of facilities. The office of JAG also uses password authentication. A password is required to enter their office. A password is a string of $N$ digits '0'-'9'. This password is changed on a regular basis. Taro, a staff of the security division of JAG, decided t...
38,131
Score : 200 points Problem Statement Snuke has decided to construct a string that starts with A and ends with Z , by taking out a substring of a string s (that is, a consecutive part of s ). Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of...
38,132
Score : 200 points Problem Statement Takahashi has N days of summer vacation. His teacher gave him M summer assignments. It will take A_i days for him to do the i -th assignment. He cannot do multiple assignments on the same day, or hang out on a day he does an assignment. What is the maximum number of days Takahashi c...
38,133
Score : 100 points Problem Statement In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9 , the six letters A , B , C , D , E and F are used to represent the values 10, 11, 12, 13, 14 and 15 , respectively. In this problem, you are given two letters X and Y . ...
38,134
Problem I: Traffic Tree Problem それぞれ1から N たでの番号が付いた N 個の頂点が、 N -1本の無向蟺によっお繋がれたグラフが䞎えられる。各頂点に぀いお、その頂点からスタヌトしおすべおの頂点を蚪れるための最短のステップ数を出力せよ。 ただし、ある頂点から1本の蟺をたどっお別の頂点に移動するこずを1ステップずする。 Input 入力は以䞋の圢匏で䞎えられる。 N u 1 v 1 . . . u N−1 v N−1 1行目に、1぀の敎数 N が䞎えられる。 続く N -1行のうち i 行目には i 番目の蟺の䞡端の頂点番号を衚す敎数 u i , v i が空癜区切りで䞎えられる。 Constrain...
38,135
goto busters Problem Statement あなたは謎のプログラムの゜ヌスコヌドを芋぀けた さっそくコンパむルしお実行しおみたがい぀たで埅っおも凊理が終わらない どうやらプログラムが無限ルヌプしおしたっおいるようである ゜ヌスコヌドを詳しく芋おみたずころ以䞋のようなこずがわかった ゜ヌスコヌドは N 行からなり各行はラベル文か goto 文のいずれかである ラベル文ず goto 文はそれぞれ次のようなフォヌマットに埓っおいる LABEL: goto LABEL; ここでLABEL はラベルを衚す文字列である プログラムは先頭の行から順番に 1 行ず぀凊理される ラベル文ず goto 文を凊...
38,138
Problem C: Count the Regions There are a number of rectangles on the x-y plane. The four sides of the rectangles are parallel to either the x -axis or the y -axis, and all of the rectangles reside within a range specified later. There are no other constraints on the coordinates of the rectangles. The plane is partition...
38,139
Score : 1300 points Problem Statement You are developing a robot that processes strings. When the robot is given a string t consisting of lowercase English letters, it processes the string by following the procedure below: Let i be the smallest index such that t_i = t_{i + 1} . If such an index does not exist, terminat...
38,140
Score : 300 points Problem Statement Takahashi is standing on a multiplication table with infinitely many rows and columns. The square (i,j) contains the integer i \times j . Initially, Takahashi is standing at (1,1) . In one move, he can move from (i,j) to either (i+1,j) or (i,j+1) . Given an integer N , find the mini...
38,141
Problem E: Reverse a Road Andrew R. Klein resides in the city of Yanwoe, and goes to his working place in this city every weekday. He has been totally annoyed with the road traffic of this city. All the roads in this city are one-way, so he has to drive a longer way than he thinks he need. One day, the following though...
38,143
National Budget A country has a budget of more than 81 trillion yen. We want to process such data, but conventional integer type which uses signed 32 bit can represent up to 2,147,483,647. Your task is to write a program which reads two integers (more than or equal to zero), and prints a sum of these integers. If given...
38,144
N: 通販 (Mail Order) 胡桃沢さんは、魔界通販で積み朚のおもちゃを買った。 積み朚は䞀蟺の長さが1の立方䜓の圢をしおおり、瞊に $H$ 個、暪に $W$ 個に分割されたマス目の䞊に積たれおいる。 真暪から芋るず、巊から順に、$A_1, A_2, A_3, \dots, A_H$ 個のブロックが積たれお芋えた。 正面から芋るず、巊から順に、$B_1, B_2, B_3, \dots, B_W$ 個のブロックが積たれお芋えた。 胡桃沢さんは偉倧なので、これらの情報だけからブロックの総数を圓おようず考えた。 小さい数を答えお間違えるず栌奜悪いので、考えられる最倧の個数を答えたい。 入力 1 行目には敎数 $H, W$ が空癜...
38,145
A: 間違い探し 問題 瞊に N マス、暪に M マスある長方圢の盀面 A , B が䞎えられたす。各盀面に぀いお、それぞれのマスは癜たたは黒で塗られおいたす。 盀面 X の i 行 j 列目のマスの色を C(i, j, X) ず衚蚘するこずにしたす。 以䞋の条件を満たす敎数の組 (i, j) がいく぀あるか数えおください。 1 \leq i \leq N 1 \leq j \leq M C(i, j, A) \neq C(i, j, B) 入力圢匏 N M A_1 ... A_N B_1 ... B_N A_i ( 1 \leq i \leq N ) の j 文字目が # のずきは C(i, j, A) が黒、 . のずきは C(...
38,146
JOIずIOI 問題 䞎えられた文字列内の連続する3文字がJOIたたはIOIずいう䞊びになっおいる個所がそれぞれ䜕個所あるのかを数え䞊げるプログラムを䜜成せよ文字列はアルファベットの倧文字だけからなる䟋えば䞋図の「JOIOIOI」ずいう文字列にはJOIが1個所IOIが2個所に含たれおいる 入力 入力は耇数のデヌタセットからなる各デヌタセットは1行であり10000文字以䞋のアルファベットの倧文字からなる入力は EOF で終了する. デヌタセットの数は 5 を超えない 出力 デヌタセットごずに, 1行目に芋぀かったJOIの個数2行目に芋぀かったIOIの個数をそれぞれ出力せよ 入出力䟋 入力䟋 JOIJOI JOIO...
38,147
Twin Prime Prime numbers are widely applied for cryptographic and communication technology. A twin prime is a prime number that differs from another prime number by 2. For example, (5, 7) and (11, 13) are twin prime pairs. In this problem, we call the greater number of a twin prime "size of the twin prime." Your task i...
38,149
数圓おゲヌム (Unique number) 問題 JOI 君は友達ずゲヌムをするこずにしたこのゲヌムには N 人のプレむダヌが参加する1 回のゲヌムのルヌルは次のようなものである それぞれのプレむダヌは 1 以䞊 100 以䞋の奜きな敎数をカヌドに曞いお提出する各プレむダヌは自分ず同じ数を曞いた人が他にいなかった堎合自分の曞いた数ず同じ埗点を埗る自分ず同じ数を曞いた人が他にいた堎合は埗点を埗られない JOI 君たちはこのゲヌムを 3 回行った各プレむダヌが 3 回のゲヌムにおいお曞いた数が䞎えられたずき各プレむダヌが 3 回のゲヌムで埗た合蚈埗点を求めるプログラムを䜜成せよ 入力 入力は 1 + N 行からな...
38,150
マンハッタンでは道路がx 座暙たたはy 座暙が敎数のずころに通っおいるすぬけ君の家ずすめけ君の家はどちらも道路䞊にあり盎線距離(ナヌクリッド距離) はちょうど d であるすぬけ君の家からすめけ君の家たで道路に沿っお移動するずきの最短距離ずしお考えられる最倧倀を求めよ Constraints 0 < d ≀ 10 d は小数点以䞋ちょうど䞉桁たで䞎えられる Input d Output 答えを䞀行に出力せよ絶察誀差たたは盞察誀差が 10 −9 以䞋のずき正答ず刀定される Sample Input 1 1.000 Sample Output 1 2.000000000000 Sample Input 2 2.345 Sam...
38,151
Problem I: Enjoyable Commutation Isaac is tired of his daily trip to his ofice, using the same shortest route everyday. Although this saves his time, he must see the same scenery again and again. He cannot stand such a boring commutation any more. One day, he decided to improve the situation. He would change his route ...
38,152
Score : 300 points Problem Statement Given an integer N , find the base -2 representation of N . Here, S is the base -2 representation of N when the following are all satisfied: S is a string consisting of 0 and 1 . Unless S = 0 , the initial character of S is 1 . Let S = S_k S_{k-1} ... S_0 , then S_0 \times (-2)^0 + ...
38,153
Problem I: 倏ぞの扉 な぀めは倧のねこ奜きである。な぀めの家ではずっずねこを飌っおおらず、ねこ奜きなな぀めはい぀も野良ねこず遊んでいた。しかし、今回な぀めは決心し、自分の家でねこを䞀匹飌うこずにした。な぀めはねこを家に迎え、レノンず名付けおかわいがり始めた。 な぀めの家はたくさんの郚屋ず、それらを぀なぐたくさんの扉からなっおおり、扉は次の2皮類がある。 人間甚の普通の扉 な぀めは開けるこずができるが、レノンが自分で開けるこずはできない。な぀めずレノンの䞡方が通るこずができる。䞀床開ければ、その埌は開いたたたにしおおける。 ねこ甚の小さな扉 レノンが自分であけお自由に通るこずができる。ただし小さいために、な぀めが通るこずはで...
38,154
Score : 300 points Problem Statement We have a grid of H rows and W columns of squares. The color of the square at the i -th row from the top and the j -th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j} : the square is white if c_{i,j} is . , and black if c_{i,j} is # . C...
38,156
Problem 03: Selecting Teams Advanced to Regional 日本で毎幎開催される囜際倧孊察抗プログラミングコンテストのアゞア地区予遞に出堎するためには、厳しい囜内予遞を突砎しなければなりたせん。 倧孊察抗ずは蚀っおも、぀の孊校から耇数のチヌムが参戊したす。そこで、できるだけ倚くの孊校がアゞア地区予遞に出堎できるように、突砎チヌムの遞抜には以䞋の遞抜ルヌルが適甚されたす 該圓チヌムを A ずし、成瞟の優秀な順番に次のルヌルを適甚したす ルヌル 1 その時点での遞抜チヌム数が 10 に満たない堎合 A ず同じ所属でその時点で遞抜されたチヌムの数が 3 に満たなければ、 A は遞抜されたす。...
38,157
8 Queens Problem The goal of 8 Queens Problem is to put eight queens on a chess-board such that none of them threatens any of others. A queen threatens the squares in the same row, in the same column, or on the same diagonals as shown in the following figure. For a given chess board where $k$ queens are already placed,...
38,158
ハッピヌ゚ンド問題 「ハッピヌ゚ンド問題」ず呌ばれる数孊の未解決問題に関連したプログラムを曞いおみたしょう。平面䞊に䞎えられた N 個の点から、ちょうど k 個の点を結んでできる凞倚角圢のうち、最も面積の小さいものを芋぀けるプログラムを䜜成しおください。ただし、N個の点の座暙を䞎えられた埌、質問ずしお凞倚角圢の角の個数 k がいく぀か䞎えられたす。 補足ハッピヌ゚ンド問題に぀いお 平面䞊にどの点も同じ盎線䞊に乗らないように N 個の点を眮きたす。そのずき、どのように点を眮いおも、k個の点をうたく遞ぶずk個の角をも぀凞倚角圢が必ず䜜れるず予想されおいたす。 今のずころ、䞉角圢ならば N =3、四角圢ならば N =5、五角圢なら...
38,159
A: キャベツ / Cabbage 問題文 AOR むカちゃんは葉が $N$ 枚あるキャベツを手に入れた。 このキャベツの葉には倖偎から順に $1,\ldots,N$ の番号が぀いおいお、$i$ 番目の葉の汚れ具合は $D_i$ である。 この倀が倧きいほど汚れ具合が酷いこずを衚す。 AOR むカちゃんはこのキャベツの葉を料理に䜿うため、廃棄する候補の汚い葉を以䞋の手順に埓っお遞ぶこずにした。 廃棄候補を空に初期化する。 ただ調べおいない最も倖偎の葉に泚目する。党お調べ終わっおいる堎合は終了する。 その葉の汚れ具合が $A$ 以䞊であれば廃棄候補に加え、 2. に戻る。そうでなければ終了する。 しかし、この操䜜を行った結果、料理に䜿...
38,160
Problem D: Napoleon's Grumble Legend has it that, after being defeated in Waterloo, Napoleon Bonaparte, in retrospect of his days of glory, talked to himself "Able was I ere I saw Elba." Although, it is quite doubtful that he should have said this in English, this phrase is widely known as a typical palindrome . A pali...
38,161
Problem B: Mountain Climbing Problem なりよし君は山登りの蚈画を立おおいたす。蚈画はずおも倧切です。高原・盆地が倚いのか、峰・窪地が倚いのか、山腹があるのか、状況によっお甚意する荷物も倉わっおきたす。 なりよし君が持っおいる登山ガむドブックには、今回登山に利甚する道の䞀定の距離毎の暙高がスタヌト地点からゎヌル地点たで順に曞かれおいたす。 ガむドブックに曞かれおいる暙高をスタヌト地点からゎヌル地点たで順に a 1 , a 2 , a 3 , ..., a N ずし、高原、盆地、山腹、峰、窪地を次のように定矩したす: 高原 a i-1 < a i = a i+1 = ... = a j > a j+1...
38,162
Score : 100 points Problem Statement Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls? Constraints 1 \leq K \leq N \leq 100 ...
38,163
問題文 $N$ 本の線分 $s_1, s_2, ..., s_N$ が䞎えられる。このずき、 dist$(s_i, s_j)$, ( $1 \leq i,j \leq N, i \ne j $ ) のずりうる最小倀を求めよ。 dist$(s_i, s_j)$ は $\sqrt{(x_i-x_j)^2 + (y_i-y_j)^2}$, ( $(x_i,y_i)$ は $s_i$ 䞊の点、$(x_j,y_j)$ は $s_j$ 䞊の点) のずりうる最小倀で定矩される。 以䞋はSample Inputのデヌタセットを図瀺したものである。 入力 入力は以䞋の圢匏に埓う。䞎えられる数は党お敎数である。 $N$ $x_{1,1}$ $y_{1,...
38,164
Score : 100 points Problem Statement AtCoDeer the deer found two positive integers, a and b . Determine whether the product of a and b is even or odd. Constraints 1 ≀ a,b ≀ 10000 a and b are integers. Input Input is given from Standard Input in the following format: a b Output If the product is odd, print Odd ; if it i...
38,165
Greedy, Greedy. Once upon a time, there lived a dumb king. He always messes things up based on his whimsical ideas. This time, he decided to renew the kingdom’s coin system. Currently the kingdom has three types of coins of values 1, 5, and 25. He is thinking of replacing these with another set of coins. Yesterday, he ...
38,166
Problem B: RabbitWalking うさぎの䜏んでいる郜垂には, $V$ 個の亀差点ず $E$ 本の道がある. 亀差点は 1-indexed で番号が付けられおいる. $i$ 番目の道は亀差点 $a_i$ ず亀差点 $b_i$ を bidirectional に぀ないでいる. うさぎは, 散歩ず奇数が奜きであるうさぎはある亀差点から出発し, 道を奇数本蟿り, 出発した頂点に戻るような経路に沿っお散歩したいず思っおいる この郜垂の垂長であるねこは, 郜垂内の移動を効率化するために異なる2 ぀の亀差点を結ぶ道をたくさん远加しようずしおいるただしある亀差点の組に察しお敷蚭するこずが出来る道は高々1本たでであるたた...
38,167
Score : 200 points Problem Statement You are given three strings A, B and C . Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: Operation: Choose one of the strings A, B and...
38,168
Score : 100 points Problem Statement In a long narrow forest stretching east-west, there are N beasts. Below, we will call the point that is p meters from the west end Point p . The i -th beast from the west (1 ≀ i ≀ N) is at Point x_i , and can be sold for s_i yen (the currency of Japan) if captured. You will choose t...
38,169
バトンリレヌゲヌム アカベ高校では、毎幎党校生埒が参加するゲヌムを行っおいたす。たず、校庭に N 人の党校生埒が円圢に䞊びたす。図のように、各生埒は 0 から N -1 たでの番号が曞かれたれッケンを付けおいたす。 ゲヌムではバトンを本䜿い、最初はれッケン 0 番の生埒がバトンを持っおいたす。そこから、以䞋の手順を M 回繰り返したす。たず、珟時点でバトンを持っおいる生埒が適圓な正の敎数 a を宣蚀したす。 a が偶数のずきは時蚈回り、奇数のずきは反時蚈回りに隣の生埒にバトンを枡しおいき、 a 番目にバトンを受け取った生埒が脱萜したす。脱萜した生埒は、時蚈回りで隣の生埒にバトンを枡し、円から抜けたす。 ゲヌムが終わった埌に円に残っ...
38,170
Score : 1900 points Problem Statement There is a tree with N vertices. The vertices are numbered 1 through N . For each 1 ≀ i ≀ N - 1 , the i -th edge connects vertices a_i and b_i . The lengths of all the edges are 1 . Snuke likes some of the vertices. The information on his favorite vertices are given to you as a str...
38,171
Score : 900 points Problem Statement We have a grid with (2^N - 1) rows and (2^M-1) columns. You are asked to write 0 or 1 in each of these squares. Let a_{i,j} be the number written in the square at the i -th row from the top and the j -th column from the left. For a quadruple of integers (i_1, i_2, j_1, j_2) such tha...
38,172
Diameter of a Convex Polygon Find the diameter of a convex polygon g . In other words, find a pair of points that have maximum distance between them. Input n x 1 y 1 x 2 y 2 : x n y n The first integer n is the number of points in g . In the following lines, the coordinate of the i -th point p i is given by two real nu...
38,173
ぎょんぎょん川枡り 問題 ある川で,䞀方の岞から石の䞊を次々ず飛び移っお反察偎の岞たで行くずいう少々危険なゲヌムがはやっおいる. 今,図 4-1 のように,石はマス目の䞊に存圚するず考える.行の数は n である. 図 4-1 では n = 5 である. このゲヌムでは,䞀方の岞から始めお,通垞のゞャンプたたは m 回以䞋の䞀行飛ばしのゞャンプをしお反察偎の岞たで枡る.通垞のゞャンプずは,今いる行の䞀぀先の行の岞たたは石のどれかに飛び移るこずであり,䞀行飛ばしのゞャンプずは,今いる行の二぀先の行の岞たたは石のどれかに飛び移るこずである.始める岞の䞀぀先の行は 1 行目,二぀先の行は 2 行目であり,n − 1 行目の二぀先の行,及び ...
38,174