task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Problem J String Puzzle Amazing Coding Magazine is popular among young programmers for its puzzle solving contests offering catchy digital gadgets as the prizes. The magazine for programmers naturally encourages the readers to solve the puzzles by writing programs. Let's give it a try! The puzzle in the latest issue is...
38,391
Finding Missing Cards Taro is going to play a card game. However, now he has only n cards, even though there should be 52 cards (he has no Jokers). The 52 cards include 13 ranks of each of the four suits: spade, heart, club and diamond. Input In the first line, the number of cards n ( n ≀ 52) is given. In the following...
38,392
シヌザヌ暗号 問題 ガむりス・ナリりス・カ゚サルGaius Julius Caesar)英語読みでゞュリアス・シヌザヌJulius Caesarは叀代ロヌマの軍人であり政治家であるカ゚サルは秘密の手玙を曞くずきに 'A' を 'D' に 'B' を 'E' に 'C' を 'F' にずいうように3぀ずらしお衚蚘したずいう蚘録が残っおいる 倧文字のアルファベット26文字だけからなる文字列をカ゚サルがしたように3文字ず぀ずらす倉換を斜し埗られた文字列があるこのような文字列を元の文字列に戻すプログラムを䜜成せよ 各文字の倉換前ず倉換埌の察応は次のようになる 倉換前 A B C D E F G H I J K...
38,393
G: Tree 問題 N 頂点からなる朚が䞎えられたす。朚の各頂点には 1 から N の番号が割り振られおいたす。たた、 N−1 本の蟺のうち、 i\ (= 1, 2, ..., N-1) 本目の蟺は頂点 u_i ず頂点 v_i ずを結んでいたす。 この朚の K 個の空でない郚分グラフの組であっお、各郚分グラフがいずれも連結で、どの二぀の盞異なる郚分グラフも頂点を共有しないものの個数を求めるプログラムを䜜成しおください。ただし答えがずおも倧きくなるこずがあるため、 998244353 で割ったあたりを答えおください。 なお、 K 個の郚分グラフからなる集合が同䞀のものは、 K 個の郚分グラフの順序が異なるものも同䞀芖するものずしたす...
38,394
取匕 取匕先の顧客番号ず取匕日を月ごずに蚘録したデヌタがありたす。今月のデヌタず先月のデヌタを読み蟌んで、先月からヶ月連続で取匕のある䌚瀟の顧客番号ず取匕のあった回数を出力するプログラムを䜜成しおください。ただし、月々の取匕先数は 1,000 瀟以内です。 Input 今月のデヌタず、先月のデヌタが行の空行で区切られお䞎えられたす。それぞれのデヌタは以䞋のような圢匏で䞎えられたす。 c 1 , d 1 c 2 , d 2 ... ... c i (1 ≀ c i ≀ 1,000) は顧客番号を衚す敎数、 d i (1 ≀ d i ≀ 31) は取匕日を衚す敎数です。 Output ヶ月連続で取匕のある䌚瀟に぀いお、顧客番号が小...
38,395
Score : 200 points Problem Statement There are four towns, numbered 1,2,3 and 4 . Also, there are three roads. The i -th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reac...
38,397
Diameter of a Tree Given a tree T with non-negative weight, find the diameter of the tree. The diameter of a tree is the maximum distance between two nodes in a tree. Input n s 1 t 1 w 1 s 2 t 2 w 2 : s n-1 t n-1 w n-1 The first line consists of an integer n which represents the number of nodes in the tree. Every node ...
38,399
Score : 1000 points Problem Statement There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i . Joisino has M tickets, numbered 1 through M . Every barbecue restaurant offers barbecue meals in exchange f...
38,400
Score : 500 points Problem Statement Takahashi has decided to work on K days of his choice from the N days starting with tomorrow. You are given an integer C and a string S . Takahashi will choose his workdays as follows: After working for a day, he will refrain from working on the subsequent C days. If the i -th chara...
38,401
写真に写っおいる景色は? A 君は䌚接に芳光にやっおきたした。宿泊したホテルの窓からは䌚接盆地が䞀望できたす。景色を眺めおいるず、床に写真の切れ端が萜ちおいるのに気が぀きたした。どうやら窓から倖の景色を撮ったようです。「どの蟺りを撮ったのかな」ず、A 君は窓の倖の景色ず写真が同じ倧きさになるように写真をかざしお、写真ず窓の倖の景色が䞀臎する堎所を探し始めたした。 それでは、A 君がやっおいるこずをコンピュヌタでやっおみたしょう。窓の倖の景色を n × n マスの正方圢に分割したす ( n を景色の倧きさず呌びたす)。各マスには、そのマスの画像の情報を衚す 0 以䞊の敎数が曞かれおいたす。マスの䜍眮は座暙 ( x, y ) で衚したす...
38,402
Matrix-chain Multiplication The goal of the matrix-chain multiplication problem is to find the most efficient way to multiply given $n$ matrices $M_1, M_2, M_3,...,M_n$. Write a program which reads dimensions of $M_i$, and finds the minimum number of scalar multiplications to compute the maxrix-chain multiplication $M_...
38,403
Score : 100 points Problem Statement Kyoto University Programming Contest is a programming contest voluntarily held by some Kyoto University students. This contest is abbreviated as K yoto U niversity P rogramming C ontest and called KUPC. source: Kyoto University Programming Contest Information The problem-preparing c...
38,404
Problem A: Popularity Estimation あなたはずあるアニメヌション制䜜䌚瀟の䌁画郚長である。昚今のアニメヌション制䜜䌚瀟が制䜜するものは、アニメヌションそのものにずどたらない。関連商品、䟋えば登堎キャラクタヌのフィギュアやキャラクタヌ゜ングCDなども、重芁な収益源なのである。この収益をどれだけ䌞ばせるかは、ひずえに䌁画郚長のあなたにかかっおいるのであった。 圓たり前のこずだが、こういった関連商品は闇雲に発売すればいいずいうものではない。商品の開発には倚くの時間ず予算が必芁なためだ。アニメの登堎キャラクタヌのフィギュアを発売するにしおも、倚くの売䞊が芋蟌たれる、人気があるキャラクタヌのものに限らなければなら...
38,405
Score : 200 points Problem Statement For a string S consisting of the uppercase English letters P and D , let the doctoral and postdoctoral quotient of S be the total number of occurrences of D and PD in S as contiguous substrings. For example, if S = PPDDP , it contains two occurrences of D and one occurrence of PD as...
38,406
Score : 300 points Problem Statement There are N people. The name of the i -th person is S_i . We would like to choose three people so that the following conditions are met: The name of every chosen person begins with M , A , R , C or H . There are no multiple people whose names begin with the same letter. How many suc...
38,407
Sleeping Time Miki is a high school student. She has a part time job, so she cannot take enough sleep on weekdays. She wants to take good sleep on holidays, but she doesn't know the best length of sleeping time for her. She is now trying to figure that out with the following algorithm: Begin with the numbers K , R and ...
38,408
Score: 100 points Problem Statement In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e , respectively. Two antennas can communicate directly if the distance between them is k or less, and they cann...
38,409
Divisor Problem 12以䞋の自然数 N が䞎えられるので、玄数の個数がちょうど N 個であるような最小の自然数を求めよ。 Input 1぀の自然数 N が 1 行で䞎えられる。 Constraints 1 ≀ N ≀ 12 Output 玄数の個数がちょうど N 個であるような最小の自然数を1行に出力せよ。 Sample Input 1 1 Sample Output 1 1 Sample Input 2 2 Sample Output 2 2 Sample Input 3 3 Sample Output 3 4
38,410
Problem I: Crossing Prisms Prof. Bocchan is a mathematician and a sculptor. He likes to create sculptures with mathematics. His style to make sculptures is very unique. He uses two identical prisms. Crossing them at right angles, he makes a polyhedron that is their intersection as a new work. Since he finishes it up wi...
38,411
Score : 800 points Problem Statement There are N children, numbered 1,2,\ldots,N . In the next K days, we will give them some cookies. In the i -th day, we will choose a_i children among the N with equal probability, and give one cookie to each child chosen. (We make these K choices independently.) Let us define the ha...
38,412
プログラミングコンテストの合宿で出す問題のアむディアが出ずに困っおいたむクタ君は、ある日友人に盞談した。 むクタ君「こういうアルゎリズムを䜿わないず解けないような問題が出したいんですけど、なにかありたせんかね」 友人「それではこういうものを考えたらいいんじゃないですか」 このようにしおその友人は以䞋のような問題の原案ずなるアむデアを考えおくれた。 2進数 A,B が䞎えられた時、以䞋の様なク゚リを凊理せよ。 出力ク゚リ: max{ x を2進数で衚したずきの、1の数 | A ≀ x < A+B }を出力 A倉曎ク゚リ: A の最䞋䜍ビットから i ビット目(0-origin)を反転 B倉曎ク゚リ: B の最䞋䜍ビットから i ビッ...
38,413
問題 B : (iwi) 20XX 幎の今G○○gle 瀟の䞖界的な支配により人々のコミュニケヌションは限られおおり 䟋えば自由に人ず情報をやりずりするこずは基本的に蚱されおいない 特に過去にプログラミングコンテストで名を銳せた匷豪たちは危険ず刀断され お互いバラバラにされ密かに泚意深く監芖されおいるずいう 自分もそんな䞀人であったような気がする しかし実は自分は蚘憶を倱っおしたっおいるのだ 自分が䜕ず名乗っおいたかそれすらも思い出せない 'i' ずか 'w' ずか括匧ずかを䜿っおいた気がするが それっぜいものを曞きだしおみおもしっくりこない そういえば今思い出したこずには巊右に線察称だっ...
38,414
床数分垃 健康蚺断で生埒の身長を蚈枬したした。身長のデヌタを入力ずし、床数分垃を䜜成しお出力するプログラムを䜜成しおください。床数分垃の階玚は 5 cm 刻みの 6 ぀の階玚ずし、床数は人数を *半角アスタリスクで衚瀺したす。ただし、その階玚の床数人数が 0 の堎合、階玚の芋出しのみを出力しおください。 Input 入力は以䞋の圢匏で䞎えられたす。 n h 1 h 2 : h n 1 行目に生埒の数 n (1 ≀ n ≀ 40)、2 行目以降に i 人目の身長を衚す実数 h i (150.0 ≀ h i ≀ 190.0、小数第 1 䜍たで) がそれぞれ 1 行に䞎えられたす。 Output 以䞋の圢匏で床数分垃を衚瀺しおくだ...
38,415
幹線道路 (Trunk Road) 問題文 JOI 垂は東西方向にたっすぐに䌞びる H 本の道路ず南北方向にたっすぐに䌞びる W 本の道路によっお碁盀の目の圢に区分けされおいる道路ず道路の間隔は 1 であるJOI 垂ではこれら H+W 本の道路から東西方向に 1 本南北方向に 1 本合蚈 2 本の道路を幹線道路ずしお遞ぶこずになった 北から i 本目 ( 1≩i≩H ) の道路ず西から j 本目 ( 1≩j≩W ) の道路の亀差点を亀差点 (i,j) ずする亀差点 (i,j) ず北から m 本目 ( 1≩m≩H ) の道路の距離は |i-m| であり亀差点 (i,j) ず西から n 本目 ( 1≩n≩W ...
38,416
四角すいの衚面積 1 蟺が x の正方圢を底面ずする、高さ h の四角すいの衚面積 S を出力するプログラムを䜜成しお䞋さい。ただし、頂点ず底面の䞭心を結ぶ線分は底面ず盎亀しおいるずしたす。たた、 x 、 h は 100 以䞋の正の敎数ずしたす。 Input 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 x h x, h が共に 0 のずき入力の終了を瀺したす。 Output 各デヌタセットごずに、 S 実数を行に出力しお䞋さい。出力は0.00001以䞋の誀差を含んでもよい。 Sample Input 6 4 7 9 0 0 Output for the Sample Input 96.0000...
38,417
Extraordinary Girl (II) She loves e-mail so much! She sends e-mails by her cellular phone to her friends when she has breakfast, she talks with other friends, and even when she works in the library! Her cellular phone has somewhat simple layout (Figure 1). Pushing button 1 once displays a character (’), pushing it twic...
38,418
A ず B の 2 人のプレヌダヌが 0 から 9 たでの数字が曞かれたカヌドを䜿っおゲヌムを行う最初に 2 人は䞎えられた n 枚ず぀のカヌドを裏向きにしお暪䞀列に䞊べるその埌 2 人は各自の巊から 1 枚ず぀カヌドを衚向きにしおいき曞かれた数字が倧きい方のカヌドの持ち䞻がその 2 枚のカヌドを取るこのずきその 2 枚のカヌドに曞かれた数字の合蚈がカヌドを取ったプレヌダヌの埗点ずなるものずするただし開いた 2 枚のカヌドに同じ数字が曞かれおいるずきには匕き分けずし各プレヌダヌが自分のカヌドを 1 枚ず぀取るものずする 䟋えば AB の持ち札が以䞋の入力䟋 1 から 3 のように䞊べられおいる堎...
38,419
Emergency Evacuation The Japanese government plans to increase the number of inbound tourists to forty million in the year 2020, and sixty million in 2030. Not only increasing touristic appeal but also developing tourism infrastructure further is indispensable to accomplish such numbers. One possible enhancement on tra...
38,420
G - 自由研究 き぀ねの次郎は倏䌑みの自由研究で 最倧独立集合問題 のアルゎリズムを考えおいる 最倧独立集合問題では入力ずしお無向グラフ G=(V,E) が䞎えられる G の各頂点が癜たたは黒で塗られおおりどの蟺の端点も少なくずも䞀方が癜く塗られおいるずき黒い頂点集合のこずを 独立集合 ず呌ぶ 䟋えば䞋図においお図の巊郚のようなグラフが䞎えられた時図の䞭倮郚のように色を塗るず黒い頂点集合は独立集合になっおいるが䞀方で図の右郚のように色を塗った堎合は黒い頂点集合は独立集合になっおいない 問題の目的は芁玠数が最倧であるような独立集合を求めるこずである 䟿宜䞊グラフ G の最倧の独立集合の倧きさを A(G) ず...
38,421
Problem A: スワップ暗号 R倧孊のずある2D奜きな圌は、人に芋られるず赀面するような恥ずかしい文章を日頃からよく曞いおいる。 そのため、第䞉者に自分の曞いおいる文章を芋られないために、圌が独自に考え出したスワップ暗号ずいう手法により文章を暗号化しおいる。 スワップ暗号では、次のようなステップを N 回繰り返し、暗号化を行う。 文字列の a i 番目ず b i 番目を入れ替える この2぀の文字を、 a i ず b i の差分だけアルファベット順に戻す ただし、アルファベット順で、'a'の前は'z'ずする。 䟋えば、"aojwo"ずいう文字列に察し、 a 1 =1、 b 1 =4、ずいう暗号化操䜜を行ったずするず、次のようにな...
38,422
Problem J: いにしえの数匏 あなたの友人の考叀孊者が遺跡を発掘しおいた ある日圌は怪しげな蚘号の矅列が刻たれおいる石盀を倧量に発芋した 圌はこの倧発芋に倧喜びしすぐさた石盀に刻たれおいる蚘号の解読を始めた 䜕週間にもわたる圌の解読の努力の結果 どうやらこれらの石盀には倉数・挔算子・カッコの組み合わせで成り立っおいる 数匏のようなものが刻たれおいるこずがわかった 発掘した石盀ず遺跡に関わる文献を調べおいくうちに圌はさらに それぞれの石盀で挔算子の結合芏則が異なっおおり それぞれの石盀の先頭に挔算子の結合芏則が蚘されおいるらしいこずを突きずめた しかし圌は数孊が苊手であるため挔算子の結合芏則を芋おも す...
38,423
Score : 200 points Problem Statement Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after t...
38,424
Score : 900 points Problem Statement Given are simple undirected graphs X , Y , Z , with N vertices each and M_1 , M_2 , M_3 edges, respectively. The vertices in X , Y , Z are respectively called x_1, x_2, \dots, x_N , y_1, y_2, \dots, y_N , z_1, z_2, \dots, z_N . The edges in X , Y , Z are respectively (x_{a_i}, x_{b_...
38,425
Leapfrog Problem Statement N 個のマスが円状に䞊んでいる。マスは時蚈回りに 1,\ 2,\ ... ,\ N ず番号が振られおいる。各 i ( 1 ≀ i ≀ N−1 ) に぀いお、 i 番目のマスず i+1 番目のマスは隣り合う。たた、 N 番目のマスず 1 番目のマスは隣り合う。 これらのうち M 個のマスには、互いに区別できない駒が 1 個ず぀眮かれおいる。はじめ、 x_1,\ x_2,\ ... ,\ x_M 番目のマスに駒が眮かれおいる。次の操䜜を䜕回か行い、 y_1,\ y_2,\ ... ,\ y_M 番目のマスに駒が眮かれおいるようにしたい。 時蚈回りたたは反時蚈回りに連続する 3 個のマ...
38,426
Score : 1600 points Problem Statement There are N zeros and M ones written on a blackboard. Starting from this state, we will repeat the following operation: select K of the rational numbers written on the blackboard and erase them, then write a new number on the blackboard that is equal to the arithmetic mean of those...
38,427
Bridges Find bridges of an undirected graph G(V, E) . A bridge (also known as a cut-edge) is an edge whose deletion increase the number of connected components. Input |V| |E| s 0 t 0 s 1 t 1 : s |E|-1 t |E|-1 , where |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with ...
38,428
Score : 200 points Problem Statement Katsusando loves omelette rice. Besides, he loves crÚme brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone. To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not. The i -th...
38,429
Score : 400 points Problem Statement We have N points in a two-dimensional plane. The coordinates of the i -th point (1 \leq i \leq N) are (x_i,y_i) . Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior. Here, points on the sides of the rec...
38,430
Score: 100 points Problem Statement E869120 has A 1 -yen coins and infinitely many 500 -yen coins. Determine if he can pay exactly N yen using only these coins. Constraints N is an integer between 1 and 10000 (inclusive). A is an integer between 0 and 1000 (inclusive). Input Input is given from Standard Input in the fo...
38,433
X Cubic Write a program which calculates the cube of a given integer x . Input An integer x is given in a line. Output Print the cube of x in a line. Constraints 1 ≀ x ≀ 100 Sample Input 1 2 Sample Output 1 8 Sample Input 2 3 Sample Output 2 27
38,434
Score : 1100 points Problem Statement This is an interactive task. You have to guess a secret password S . A password is a nonempty string whose length is at most L . The characters of a password can be lowercase and uppercase english letters (a, b, ... , z, A, B, ... , Z) and digits (0, 1, ... , 9). In order to guess ...
38,435
Score : 800 points Problem Statement Mr. Takahashi has in his room an art object with H rows and W columns, made up of H \times W blocks. Each block has a color represented by a lowercase English letter ( a - z ). The color of the block at the i -th row and j -th column is c_{i,j} . Mr. Takahashi would like to dismantl...
38,436
L: 朚の圩色 問題文 モデュヌロさんは朚の絵を描くのがずおもうたいです。 モデュヌロさんは長い幎月をかけお頂点が $N$ 個である朚の絵を曞きたした。 この朚の頂点には $1$ から $N$ たでの番号が぀いおおり、頂点 $a_i$ ず $b_i$ $(1 \leq i \leq N-1)$ は盎接蟺で぀ながれおいたす。 すべおの頂点には色がただ塗られおいたせん。 モデュヌロさんが曞いたこの朚の絵はたくさんの人を感動させ、有名な矎術通に食られるこずが決たりたした。 この矎術通には順に $N$ 人の人が来堎したす。モデュヌロさんは来堎者特兞ずしお、それぞれの人に $1$ 枚ず぀朚の絵のコピヌを配垃するこずにしたした。 さらに、来堎者...
38,437
氎道料金 (Water Rate) 問題 JOI 君が䜏んでいる地域には氎道䌚瀟が X 瀟ず Y 瀟の 2 ぀ある2 ぀の䌚瀟の 1 ヶ月の氎道料金は1 ヶ月の氎道の䜿甚量に応じお次のように決たる X 瀟 1 リットル あたり A 円かかる Y 瀟 基本料金は B 円である䜿甚量が C リットル以䞋ならば料金は基本料金 B 円のみがかかる䜿甚量が C リットルを超えるず基本料金 B 円に加えお远加料金がかかる远加料金は䜿甚量が C リットルを 1 リットル超えるごずに D 円である JOI 君の家では 1 ヶ月の氎道の䜿甚量が P リットルである 氎道料金ができるだけ安くなるように氎道䌚瀟を遞ぶずきJOI ...
38,438
䜓育祭Sport Meet 秋の䜓育祭が行われたす。皮目は埒競走、ボヌル運び、障害物競走、リレヌの4皮目です。参加チヌムは n チヌムで、この4皮目の合蚈タむムが最も小さいチヌムが「優勝」、次に小さいチヌムが「準優勝」、そしお、最䞋䜍より2番目のチヌムを「ブヌビヌ賞」ずしお衚地したいず思いたす。 各チヌムの成瞟を入力ずしお、「優勝」、「準優勝」、「ブヌビヌ賞」のチヌムを出力するプログラムを䜜成しおください。 ただし、チヌムにはそれぞれ 1 から n のチヌム番号が割り圓おられおいたす。 Input 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。...
38,439
Problem G: Magical Island 2 ただ魔法があたりたえのように存圚した時代であるある魔導士の䞀族は魔力によっお䜜られた正方圢の圢の島に䜏んでいた ある時この島に危機が蚪れた垝囜が倧陞間匟道魔導ミサむルを開発しこの島を照準に合わせおきたのであるこの䞖界の魔法は地属性氎属性火属性颚属性などに分類でき魔導ミサむルもその四぀の属性のいずれかに属しおいた島の四隅にはそれぞれ地の氎晶氎の氎晶火の氎晶颚の氎晶が配眮されおいお氎晶に魔力を送り蟌むこずで察応する属性の魔法攻撃を防ぐこずがきでる 魔導士達は垝囜が開発した倧陞間匟道魔導ミサむルによる攻撃をかろうじお退けるこずができたしかし垝囜は...
38,440
Problem I: Most Distant Point from the Sea The main land of Japan called Honshu is an island surrounded by the sea. In such an island, it is natural to ask a question: "Where is the most distant point from the sea?" The answer to this question for Honshu was found in 1996. The most distant point is located in former Us...
38,441
E : Arojam's Mask / 仮面 問題文 あなたは勇者である。勇者が旅をしおいる䞖界は N 個の街ず、異なる街同士を結ぶ M 本の道からなる。道 i は街 a_i ず街 b_i を結び、双方向に移動可胜である。 街 S から出発し、街 T に移動するこずが勇者の目的である。 S,T は異なる街である。勇者は 0 日目に街を出発し、ちょうど 1 日かけお 1 本の道を通っお移動するこずができる。道を䜿った移動には日数の制限 R があり、 R 日目を超えるこずはできない。 たた、勇者は任意の街で「オカリナを吹く」こずもできる。オカリナを吹くず、時は 0 日目に、䜍眮は街 S に戻される。぀たり、 R 回を超える移動を行う堎合...
38,442
Score : 1300 points Problem Statement There is a string s consisting of a and b . Snuke can perform the following two kinds of operation any number of times in any order: Choose an occurrence of aa as a substring, and replace it with b . Choose an occurrence of bb as a substring, and replace it with a . How many string...
38,443
Problem F: Ninja Legend Ninjas are professional spies in the Middle Age of Japan. They have been popular in movies and games as they have been described with extraordinary physical abilities and unrealistic abilities. You are absorbed in one of ninja games, Ninja Legend . In this game, you control in an exceptionally t...
38,444
Problem D: Space Golf You surely have never heard of this new planet surface exploration scheme, as it is being carried out in a project with utmost secrecy. The scheme is expected to cut costs of conventional rovertype mobile explorers considerably, using projected-type equipment nicknamed "observation bullets". Bulle...
38,445
Score : 400 points Problem Statement There are N towns in the State of Atcoder, connected by M bidirectional roads. The i -th road connects Town A_i and B_i and has a length of C_i . Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and ...
38,446
Problem B: Time Complexity ICPC World Finals 1日目 プログラミングコンテストではプログラムの実行時間を把握する事が重芁だ。 実行時間の芋積もりを誀り、 時間制限をオヌバヌしおしたうコヌドを曞いおしたうず、 そのぶん時間をロスしおしたう。 ICPCのようにコンピュヌタが1台しか䜿えないチヌム戊ではなおさらである。 そこで、ICPC World Finalsを前に控えたティヌ氏はプログラムの実行時間を暗算で求める蚓緎を始めるこずにした。 「logは定数のようなもの」なので、たずは倚項匏に取り組むずしよう。 問題 ある問題の答えを蚈算するプログラムず、それを実行するコンピュヌタがある。 問題の...
38,447
぀らら 問題 カナダに䜏む JOI 君の家の軒䞋には,立掟な぀ららが出来おいる.せっかくなので,JOI 君は぀ららに぀いお調べおみるこずにした. JOI 君の家の軒䞋には N 本(2 ≀ N ≀ 100000 = 10 5 )の぀ららが出来おいる.これらの぀ららは䞀盎線䞊に䞊んでおり,軒䞋の巊端から i cm(1 ≀ i ≀ N )の䜍眮に i 本目の぀ららが出来おいる.i 本目の぀ららの長さは最初 ai cm(ai は 1 以䞊の敎数)である.これらの぀ららは,次のような芏則によっお䌞びおいく: i 本目の぀ららは,i − 1 本目の぀ららず i + 1 本目の぀ららの䞡方よりも長い堎合にのみ,1 時間に぀き 1 cm ず぀䌞びる...
38,448
Permutation For given a sequence $A = \{a_0, a_1, ..., a_{n-1}\}$, print the previous permutation and the next permutation in lexicographic order. Input A sequence is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ Output Print the previous permutation, the given sequence and the next permutation in t...
38,449
Physical Experiments Ignoring the air resistance, velocity of a freely falling object $v$ after $t$ seconds and its drop $y$ in $t$ seconds are represented by the following formulas: $ v = 9.8 t $ $ y = 4.9 t^2 $ A person is trying to drop down a glass ball and check whether it will crack. Your task is to write a progr...
38,450
E-修行 ねねさんはプログラミングの修行のため、$N$ 個の敎数 $V_1, V_2, V_3, \cdots, V_N$ に぀いお調べるプログラムを䜜っおいる。 指導圹のうみこさんに蚀われお、ねねさんは 2, 3, 6 の倍数の個数を調べるプログラムを曞いた。 2 の倍数は $A$ 個、3 の倍数は $B$ 個、6 の倍数は $C$ 個だった。 うみこさんは、次は「2 の倍数でも 3 の倍数でもない数」の個数を調べるようにず蚀った。 しかし、ねねさんは疲れたので、答えだけを求めおごたかすこずにした。 $N, A, B, C$ の倀だけをもずに、「2 の倍数でも 3 の倍数でもない数」の個数が分かりたす。これを求めるプログラムを䜜っ...
38,451
Score : 1000 points Problem Statement ButCoder Inc. is a startup company whose main business is the development and operation of the programming competition site " ButCoder ". There are N members of the company including the president, and each member except the president has exactly one direct boss. Each member has a ...
38,452
Score : 100 points Problem Statement Taro and Jiro will play the following game against each other. Initially, they are given a sequence a = (a_1, a_2, \ldots, a_N) . Until a becomes empty, the two players perform the following operation alternately, starting from Taro: Remove the element at the beginning or the end of...
38,453
Coin Combination Problem II You have N coins each of which has a value a i . Find the number of combinations that result when you choose K different coins in such a way that the total value of the coins is greater than or equal to L and less than or equal to R . Constraints 1 ≀ K ≀ N ≀ 40 1 ≀ a i ≀ 10 16 1 ≀ L ≀ R ≀ 10...
38,454
Score : 200 points Problem Statement We have a bingo card with a 3\times3 grid. The square at the i -th row from the top and the j -th column from the left contains the number A_{i, j} . The MC will choose N numbers, b_1, b_2, \cdots, b_N . If our bingo sheet contains some of those numbers, we will mark them on our she...
38,455
Counting Sort Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into it...
38,457
魔法陣 人里離れた森の奥深くに、マリヌずいう名の魔女が䜏んでいたした。圌女は魔女なので、食料・氎・燃料など、生掻に必芁なものを魔法によっおたかなっおいたす。 圌女の魔法は、魔力を蟌めたいく぀かの石ず玐を䜿っお、魔法陣を描くこずによっお発動したす。この魔法陣は、石を蚭眮し、いく぀かの石のペアを玐で繋ぐこずで描かれたす。ただし、玐は匛んでいおはいけたせん。さらに、どの玐も、(䞡端を陀いお) 他の玐や石に觊れおはいけたせん。もちろん、同じ堎所に耇数の石を眮くこずもできたせん。この制玄が守られる限り、石ず石の䜍眮関係や玐の長さに制限はありたせん。たた、石は十分小さいので点ずしお扱うこずができ、玐は十分现いので線分ずしお扱うこずができたす。さ...
38,458
Score : 500 points Problem Statement Count the pairs of length- N sequences consisting of integers between 1 and M (inclusive), A_1, A_2, \cdots, A_{N} and B_1, B_2, \cdots, B_{N} , that satisfy all of the following conditions: A_i \neq B_i , for every i such that 1\leq i\leq N . A_i \neq A_j and B_i \neq B_j , for eve...
38,459
Problem D: Course Planning for Lazy Students 䌚接倧孊では2009幎床より、授業履修に関する新しい制床を開始した。新制床では必修科目を撀廃し、それぞれの進路を考慮しお科目を自由に遞択できるようになった。 しかし、どの科目も無条件で履修できるわけではなく、特定の科目を履修するためには、先修条件を満たしおいる必芁がある。䞋図に履修蚈画衚の䞀郚の䟋を瀺す 図の長方圢が぀の科目を衚し科目名ず単䜍数を含んでいる。図の矢印が先修条件を衚す。矢印の意味は、矢印の終点で指されおいる科目を履修するためには、その矢印の始点を瀺す科目を修埗しおいる必芁がある。䟋えば、Linear Algebra II (線...
38,460
Score : 200 points Problem Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visi...
38,461
A Light Road There is an evil creature in a square on N-by-M grid ( 2 \leq N, M \leq 100 ), and you want to kill it using a laser generator located in a different square. Since the location and direction of the laser generator are fixed, you may need to use several mirrors to reflect laser beams. There are some obstacl...
38,462
Score : 500 points Problem Statement An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i -th round, the game master announces: Form groups consisting of A_i children each! Then the children who are still in the game form as many groups of A_i children as possib...
38,463
Problem D: Room of Time and Spirit Problem 20XX幎、ずある科孊者がバむオテクノロゞヌによっお匷力な人造人間を開発しおしたった。この人造人間はコンピュヌタにより、戊闘の達人たちの现胞を組み合わせお䜜られおいるため非垞に匷力である。 このたたでは地球は人造人間に支配されおしたうので、 N 人の戊士たちは人造人間ず戊うこずにした。しかし今の戊士たちでは到底人造人間に敵わないため、修行をしなければならない。たた、 N 人の戊士たちはそれぞれ 1 ~ N の番号が付いおいる。 この時代、倩空郜垂AIZUには SRLU宀ず呌ばれる修行のための特殊な郚屋が存圚した。この郚屋での1幎は倖界の時間の1日ず...
38,464
Score : 600 points Problem Statement There is an infinitely large pond, which we consider as a number line. In this pond, there are N lotuses floating at coordinates 0 , 1 , 2 , ..., N-2 and N-1 . On the lotus at coordinate i , an integer s_i is written. You are standing on the lotus at coordinate 0 . You will play a g...
38,465
Problem D: Divide the Water A scientist Arthur C. McDonell is conducting a very complex chemical experiment. This experiment requires a large number of very simple operations to pour water into every column of the vessel at the predetermined ratio. Tired of boring manual work, he was trying to automate the operation. O...
38,466
Score : 300 points Problem Statement Snuke has a fair N -sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: Throw the die. The current score is the result of the die. As long as the score is between 1 and K-1 (inclusive), keep flipping the co...
38,467
Score : 700 points Problem Statement You have an integer sequence of length N : a_1, a_2, ..., a_N . You repeatedly perform the following operation until the length of the sequence becomes 1 : First, choose an element of the sequence. If that element is at either end of the sequence, delete the element. If that element...
38,468
Maze & Items Maze & Items is a puzzle game in which the player tries to reach the goal while collecting items. The maze consists of $W \times H$ grids, and some of them are inaccessible to the player depending on the items he/she has now. The score the player earns is defined according to the order of collecting items....
38,469
Score : 800 points Problem Statement Given is a string S , where each character is 0 , 1 , or ? . Consider making a string S' by replacing each occurrence of ? with 0 or 1 (we can choose the character for each ? independently). Let us define the unbalancedness of S' as follows: (The unbalancedness of S' ) = \max \{ The...
38,470
Score : 1200 points Problem Statement Imagine a game played on a line. Initially, the player is located at position 0 with N candies in his possession, and the exit is at position E . There are also N bears in the game. The i -th bear is located at x_i . The maximum moving speed of the player is 1 while the bears do no...
38,471
ギャグ (Gag) Segtree 君は $N$ 個の「ギャグ」を持っおいお、それぞれに「できばえ」 $V_i$ ずいう倀が定たっおいたす。 Segtree 君は自由な順番で党おのギャグを公開するこずにしたした。 ここで、 $i$ 番目のギャグを $j$ 番目に公開した時に埗られる「うれしさ」は $V_i - j$ ず衚されたす。 Segtree 君が埗られる「うれしさ」の和の最倧倀を求めおください。 入力 入力は以䞋の圢匏で暙準入力から䞎えられる。 $N$ $V_1$ $V_2$ $\ldots$ $V_N$ 出力 「うれしさ」の和の最倧倀を出力しおください。ただし、倀が 32bit 敎数に収たるずは限りたせん。 最埌には改行を入...
38,472
Score : 100 points Problem Statement We have three boxes A , B , and C , each of which contains an integer. Currently, the boxes A , B , and C contain the integers X , Y , and Z , respectively. We will now do the operations below in order. Find the content of each box afterward. Swap the contents of the boxes A and B S...
38,473
Score : 300 points Problem Statement You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a self-loop is an edge where a_i = b_i (1≀i≀M) , and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≀i<j≀M) . How many dif...
38,474
Optimal Tournament In 21XX, an annual programming contest "Japan Algorithmist GrandPrix (JAG)" has been one of the most popular mind sport events. You, the chairperson of JAG, are preparing this year's JAG competition. JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tourname...
38,475
Range Search (kD Tree) The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range. For n points on a plane, report a set of points which are within in a given range. Note that you do not need to consider insert and delete operations for the set. Inp...
38,476
KND Factory Problem KND君は䌚接倧孊に圚籍する孊生プログラマである。圌の䜏む町の呚蟺には N 個の町がある。圌は生クリヌムが倧奜きなので毎日生クリヌムを食べるためにある町に工堎を建蚭した。その工堎では毎日 F リットルの生クリヌムが補造される。生クリヌムは運ぶたびに、移動元の町の気枩ず移動先の町の気枩の絶察差だけ傷んでしたう。困ったこずにこの近蟺の町の気枩は寒暖蚈によっお蚈枬できない。しかしながら調査によっお、それぞれの町の気枩を倉数ずした N 個の䞀次方皋匏からなる N 元䞀次連立方皋匏を導くこずができた。あなたはこれを解くこずによっお各町の気枩を知るこずができる。たた、ある町から他の町ぞ生クリヌムを運搬する...
38,477
D: しりずり圧瞮 (Shiritori Compression) 問題 えびちゃんずかにちゃんの二人はしりずりをしたした。えびちゃんはしりずりで出た単語のメモを芋おいたす。 えびちゃんは、この単語列 w_1 , w_2 , ... , w_N から冗長な連続郚分列を、存圚しなくなるたで取り陀きたいず思っおいたす。えびちゃんの思う冗長な連続郚分列ずは以䞋のように定矩されたす。 以䞋を満たす i , j が存圚したずき、連続郚分列 w_i , ... , w_{j-1} は冗長です。 i < j なる添字 i , j に぀いお、単語 w_i ず w_j の先頭の文字が等しい。 このずき、えびちゃんは添字 i 以䞊 j-1 以䞋の単語を...
38,478
Score : 200 points Problem Statement You are given positive integers A and B . Find the K -th largest positive integer that divides both A and B . The input guarantees that there exists such a number. Constraints All values in input are integers. 1 \leq A, B \leq 100 The K -th largest positive integer that divides both...
38,479
Score : 200 points Problem Statement Find the largest square number not exceeding N . Here, a square number is an integer that can be represented as the square of an integer. Constraints 1 \leq N \leq 10^9 N is an integer. Input Input is given from Standard Input in the following format: N Output Print the largest squa...
38,480
Complex Paper Folding Dr. G, an authority in paper folding and one of the directors of Intercultural Consortium on Paper Crafts, believes complexity gives figures beauty. As one of his assistants, your job is to find the way to fold a paper to obtain the most complex figure. Dr. G defines the complexity of a figure by ...
38,481
玠数の和 p(i) を小さい方から i 番目の玠数ずしたす。䟋えば、7 は、2, 3, 5, 7 ず小さい方から 4 番目の玠数なので、 p(4) = 7 です。 n が䞎えられたずき、 i = 1 から n たでの p(i) の和 s s = p(1) + p(2) + .... + p(n) を出力するプログラムを䜜成しおください。䟋えば、 n = 9 のずき、 s = 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 = 100 ずなりたす。 Input 耇数のデヌタセットが䞎えられたす。各デヌタセットに敎数 n ( n ≀ 10000) が䞎えられたす。 n が 0 のずき入力の最埌ずしたす。デヌ...
38,482
Score : 100 points Problem Statement You will turn on the air conditioner if, and only if, the temperature of the room is 30 degrees Celsius or above. The current temperature of the room is X degrees Celsius. Will you turn on the air conditioner? Constraints -40 \leq X \leq 40 X is an integer. Input Input is given from...
38,483
ねこのあな あなたの家の近所には倚くの猫が出入りする暪穎がありたす。䞭は行き止たりで通り抜けるこずはできたせんが、近所の猫が党郚入れるくらいの奥行きがありたす。穎の幅は猫がちょうど収たるくらいなので、先に入った猫を埌から入った猫が抌しのけお奥に向かうこずはできたせん。たた、先に入った猫が、埌から入っおきた猫を抌しのけお出口から出るこずもできたせん。 猫奜きのあなたは暪穎に出入りする猫を順番に蚘録しおいきたした。蚘録をはじめたずきは暪穎の䞭には䞀匹も猫はいたせんでしたが、やがお猫たちは暪穎ぞの出入りを始めたした。同じ猫が䜕床も出入りするこずもありたした。 蚘録を終えたあなたは、正しく蚘録できたかプログラムを曞いおチェックするこずにした...
38,484
Problem E Infallibly Crack Perplexing Cryptarithm You are asked to crack an encrypted equation over binary numbers. The original equation consists only of binary digits ("0" and "1"), operator symbols ("+", "-", and "*"), parentheses ("(" and ")"), and an equal sign ("="). The encryption replaces some occurrences of ch...
38,485
Problem I: Reverse Game あるずころにオセロが趣味な女の子がいたした。時間があるずきに家族ずオセロを楜しんでいたす。 ある日、女の子はい぀ものようにオセロで遊がうずしたした。ずころが、みんな忙しくお誰も遊んでくれたせんでした。 そこでオセロのボヌドずこたを䜿っお人で遊べるゲヌムを考え出したした。 問題 瞊\( R \)マス、暪\( C \)マスのマス目党おにオセロの駒が䞊面が黒あるいは癜になるように配眮されおいる。 以䞋の図のように「あるマスを遞んで、その䞊䞋巊右斜め方向にある駒を党お裏返す」ずいう操䜜を繰り返し行うこずを考える。 党おの駒の䞊面を癜にするような操䜜の仕方の個数を求めよ。 ただし、以䞋の条件を...
38,486
Score : 100 points Problem Statement You are given a string S of length 3 consisting of a , b and c . Determine if S can be obtained by permuting abc . Constraints |S|=3 S consists of a , b and c . Input Input is given from Standard Input in the following format: S Output If S can be obtained by permuting abc , print Y...
38,487
Problem F: Mysterious Dungeons The Kingdom of Aqua Canora Mystica is a very affluent and peaceful country, but around the kingdom, there are many evil monsters that kill people. So the king gave an order to you to kill the master monster. You came to the dungeon where the monster lived. The dungeon consists of a grid o...
38,488
Score : 2200 points Problem Statement You are given an undirected graph with N vertices and M edges. Here, N-1≀M≀N holds and the graph is connected. There are no self-loops or multiple edges in this graph. The vertices are numbered 1 through N , and the edges are numbered 1 through M . Edge i connects vertices a_i and ...
38,489
Score : 2000 points Problem Statement Let us consider a grid of squares with N rows and N columns. Arbok has cut out some part of the grid so that, for each i = 1, 2, \ldots, N , the bottommost h_i squares are remaining in the i -th column from the left. Now, he wants to place rooks into some of the remaining squares. ...
38,490
Problem E: Map of Ninja House An old document says that a Ninja House in Kanazawa City was in fact a defensive fortress, which was designed like a maze. Its rooms were connected by hidden doors in a complicated manner, so that any invader would become lost. Each room has at least two doors. The Ninja House can be model...
38,491
Problem Statement One day, my grandmas left $N$ cookies. My elder sister and I were going to eat them immediately, but there was the instruction. It said Cookies will go bad; you should eat all of them within $D$ days. Be careful about overeating; you should eat strictly less than $X$ cookies in a day. My sister said "...
38,492
Score : 200 points Problem Statement There are N points in a D -dimensional space. The coordinates of the i -th point are (X_{i1}, X_{i2}, ..., X_{iD}) . The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2} . How man...
38,493
Score : 1000 points Problem Statement There is a sequence of length N : a = (a_1, a_2, ..., a_N) . Here, each a_i is a non-negative integer. Snuke can repeatedly perform the following operation: Let the XOR of all the elements in a be x . Select an integer i ( 1 ≀ i ≀ N ) and replace a_i with x . Snuke's objective is t...
38,494
Problem I: Lapin Noir ここは, 地面が正六角圢を敷き詰めたマス目になっおいる街である. 各マスは, 䞋の図のように2 ぀の敎数で衚される. ねこは(0, 0) のマスぞ行こうずしおいる. いたずら奜きの黒うさぎはこのこずを知っお, ねこの邪魔をしようず考えた. 黒うさぎはねこがいるマスぞ跳び, その呚りの6 マスのうち1 ぀たたは隣り合う2 ぀をブロックするこずができる. ねこは呚りの6 マスのうち, ブロックされおいないマスを1 ぀遞んで進む. ねこが動くたび黒うさぎはねこを远いかけ, たたブロックを行うこずができる. 黒うさぎが動くず元のブロックは解陀される. 䞋の図はブロックの様子を瀺しおいる. この街に...
38,495