task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Score : 800 points Problem Statement Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows: The vertices of the tree were numbered 1,2,...,N , and the edges were numbered 1,2,...,N-1 . Edge i connected Vertex a_i and b_i . The length of each edge was an integer between 1 and 10^{1...
39,026
Score : 100 points Problem Statement There is a set A = \{ a_1, a_2, \ldots, a_N \} consisting of N positive integers. Taro and Jiro will play the following game against each other. Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro: Choose ...
39,027
Balls and Boxes 1 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes...
39,028
Score : 300 points Problem Statement If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1 . The integer has exactly N digits in base ten. (We assume 0 to be a 1 -digit integer. For other integers, leading zeros are not allowed.) The s_i -th dig...
39,029
アリの巣箱の圢状 求悟君は倏䌑みの自由研究ずしおアリの巣の芳察を行うこずにしたした。圌のおじいちゃんが孫のために甚意しおくれた芳察甚の透明ケヌスはずおもナニヌクで、図1のような圢をしおいたす。 図 このケヌスは、2枚の合同な凞倚角圢 s1、s2 ず䜕枚かの長方圢で構成されおいたす。s1、s2 以倖のいずれかの長方圢の面を床に接するように眮きたす。芳察を始めた求悟君は、入っおいる土の量が同じにもかかわらず、底面の遞び方によっお土の高さが倉わるこずに気付きたした図2。 図 求悟君は、ケヌスの眮き方によっお、どのくらい高くなるか知りたくなりたした。凞倚角圢 s1 の圢、s1 ず s2 間の距離 d 、土の䜓積 V を入力ずし、土の...
39,031
The Number of Inversions For a given sequence $A = \{a_0, a_1, ... a_{n-1}\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following program: bubbleSort(A) cnt = 0 // the number of ...
39,032
Problem E: Kuru-Kuru Robot ロボット工孊の研究者であるアシモフ博士は、新しいロボットの開発に成功した。このロボットは、床に匵り巡らせた特殊なワむダヌに沿っお自由に動くこずができる。ロボットは垞に珟圚いるワむダヌに平行な方向を向いお前進する。 すばらしいこずに、このロボットはワむダヌ䞊を移動するためにその距離にかかわらず゚ネルギヌを消費しない。しかし、ワむダヌの端点やワむダヌの亀点で向きを倉えるためにはその点を䞭心に回転する必芁があり、その回転角床だけ゚ネルギヌを消費する。 このロボットをスタヌト地点からゎヌル地点たで動かしたい。䟋えば、䞋図においおロボットを start に東向き䞋図 x 軞の正の向きで...
39,033
Score : 400 points Problem Statement For a positive integer X , let f(X) be the number of positive divisors of X . Given a positive integer N , find \sum_{K=1}^N K\times f(K) . Constraints 1 \leq N \leq 10^7 Input Input is given from Standard Input in the following format: N Output Print the value \sum_{K=1}^N K\times ...
39,034
Max Score: $1500$ Points Problem Statement There is a $50 \times 50$ field. The cell at $i$-th row and $j$-th column is denoted $(i, j)$ (0-indexed). One day, square1001 puts $250$ bombs in this field. In each cell, there is 1 or 0 bomb. You want to know where the bombs are by asking some questions. You can ask this qu...
39,035
Score : 700 points Problem Statement You are given N integers A_1 , A_2 , ..., A_N . Consider the sums of all non-empty subsequences of A . There are 2^N - 1 such sums, an odd number. Let the list of these sums in non-decreasing order be S_1 , S_2 , ..., S_{2^N - 1} . Find the median of this list, S_{2^{N-1}} . Constra...
39,036
Kth Sentence A student, Kita_masa, is taking an English examination. In this examination, he has to write a sentence of length m . Since he completely forgot the English grammar, he decided to consider all sentences of length m constructed by concatenating the words he knows and write the K -th sentence among the candi...
39,037
Score : 100 points Problem Statement Takahashi, who is A years old, is riding a Ferris wheel. It costs B yen ( B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger ar...
39,038
Problem C: Last One Problem あなたは、集合奜きな友人Aず䞀颚倉わったゲヌムをしおみる事にした。 n個の芁玠からなる重耇が蚱される非負の敎数の集合Sが䞎えられる。集合Sに含たれる各芁玠は非負の p i 進数である。集合Sに察しお 以䞋のStep1~3を1぀のタヌンずしお、あなたず盞手の二人が亀互にタヌンを繰り返す。各タヌンではこの番号の順に操䜜を行う。 Step 1: 集合Sに含たれる党おの芁玠を䞀床取り陀き、その取り陀いた各芁玠を2進数に倉換しお、0を消しお1が1぀以䞊連続する郚分に分割し、その分割された郚分を党お集合Sに加える。 Step 2: このずき集合Sが空になっおいたならば、珟圚このタヌンをプレ...
39,039
バブル゜ヌト(Bubble Sort) バブル゜ヌトずは列を゜ヌトするアルゎリズムの 1 ぀である長さ N の数列 A を昇順に゜ヌトしたいずしようバブル゜ヌトは隣り合う 2 ぀の数で倧小関係が厩れおいるものがあればそれらの䜍眮を亀換するこれを数列を前から順に走査しながら行うすなわち A i > A i+1 ずなっおいる堎所があればその 2 数を亀換するずいうこずを i = 1, 2, ... , N − 1 に察しおこの順で行うのが 1 回の走査であるこの走査を N − 1 回繰り返すこずで数列を昇順に゜ヌトできるこずが知られおいる 数列 A のバブル゜ヌトによる亀換回数ずは数列 A に䞊蚘のアルゎリ...
39,040
宅配料金 ある宅配業者の宅配料金は倧きさず重量で䞋衚のように料金が蚭定されおいたす。 A サむズ B サむズ C サむズ D サむズ E サむズ F サむズ 倧きさ 60cm以内 80cm以内 100cm以内 120cm以内 140cm以内 160cm以内 重さ 2kg以内 5kg以内 10kg以内 15kg以内 20kg以内 25kg以内 料金 600円 800円 1000円 1200円 1400円 1600円 倧きさは䞉蟺瞊、暪、高さの和です。䟋えば倧きさが120cmで、重さが15kg以内の荷物はサむズ1,200円ずなりたす。倧きさが120cm以内でも、重さが15kgを超え、20kg以内ならばサむズずなりたす。 1日...
39,041
Problem A: 期末詊隓! 私立桜が䞘女子高等孊校に通う平沢唯さんは明埌日たでに進路垌望を出さなければならないのだが、困ったこずに進路に぀いおただ䜕も決めおいなかった。 友人の和に盞談したずころ、和の第䞀志望はK倧ず知り、自分もK倧に入れるかどうか進路指導の先生に盞談にいった。 盞談された進路指導の先生であるあなたは唯さんがK倧に入れるかどうかを予想するため唯さんの期末詊隓の成瞟を参考にするこずにした。 しかし、唯さんは詊隓の山が圓たるかどうかによっお倧きく成瞟が巊右されるため、過去の期末詊隓の䞭で䞀番良かった時の点数ず䞀番悪かった時の点数を調べるこずにした。 過去の期末詊隓のデヌタは5教科の各点数のみしか残っおおらず、詊隓の...
39,042
Problem J: The Teacher’s Side of Math One of the tasks students routinely carry out in their mathematics classes is to solve a polynomial equation. It is, given a polynomial, say X 2 - 4 X + 1, to find its roots (2 ± √3). If the students’ task is to find the roots of a given polynomial, the teacher’s task is then to fi...
39,043
F : Tree / 朚 問題文 倧きさ N の根付き朚がある。 各頂点には 0 から N−1 たでの番号が付けられ、根が 0 である。 任意の蟺の䞡端の頂点に぀いお、割り圓おられた敎数は根に近いほうが小さい。初めは党おの蟺の重みは 0 である。 この朚に察する Q 個のク゚リを順に凊理せよ。ク゚リには以䞋の 2 皮類がある。 頂点 u , v の距離(パスに含たれる蟺の重みの和)を求める。 頂点 v の子孫(自身を含たない)に接続する蟺の重みを党お x 増加させる。 入力 入力は以䞋の圢匏からなる。 N Q a_0 b_0 
 a_{N−2} b_{N−2} q_0 
 q_{Q−1} a_i,b_i は i 番目の蟺が結ぶ頂点で...
39,044
Problem E: Magical Island This is a story in the epoch of magic. A clan of magicians lived in an artificial island built by magic power. One day, a crisis erupted on the island. An Empire ACM (Atlas Country of Magic) required unconditional surrender to them, otherwise an imperial force attacked by magical missiles to t...
39,045
Score : 1900 points Problem Statement Snuke has found two trees A and B , each with N vertices numbered 1 to N . The i -th edge of A connects Vertex a_i and b_i , and the j -th edge of B connects Vertex c_j and d_j . Also, all vertices of A are initially painted white. Snuke would like to perform the following operatio...
39,046
Problem C: Shopping Your friend will enjoy shopping. She will walk through a mall along a straight street, where $N$ individual shops (numbered from 1 to $N$) are aligned at regular intervals. Each shop has one door and is located at the one side of the street. The distances between the doors of the adjacent shops are ...
39,047
Problem A: Register Phase むンタヌネットをより安党に掻甚するために、堅牢なパスワヌドを䜿うこずは重芁である。それず同時に、同じパスワヌドを䜿い回さないこずも非垞に重芁である。どんなに匷いパスワヌドを䜿っおいおも、䞀箇所で平文が流出しおしたえば、砎るのは非垞に容易になっおしたう。もちろん、党おのアプリケヌションがパスワヌドをハッシュ化し、SALTを適切に䜿甚しおいれば流出しおもそのような被害は発生しないが、いただにパスワヌドを平文で保存しおいるアプリケヌションはあるのである。 さお、そろそろコンテストが始たる。チヌムのアカりントを登録しなくおは 。 問題 パスワヌドを衚す文字列が䞎えられる。その文字列が以䞋の...
39,048
Score : 100 points Problem Statement We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds? Constraints 1≀X≀10^9 1≀t≀10^9 X and t are ...
39,049
Sorting Tuples Write a program which reads $n$ items and sorts them. Each item has attributes $\{value, weight, type, date, name\}$ and they are represented by $\{$ integer, integer, upper-case letter, integer, string $\}$ respectively. Sort the items based on the following priorities. first by value (ascending) in cas...
39,050
博芧䌚 問題 JOI 垂では,ずある倧芏暡な博芧䌚を開催するこずになった. 今回の博芧䌚には 2 ぀のテヌマがあり,JOI 垂にある N 個の展瀺斜蚭でそれぞれ, 2 ぀のテヌマのうちどちらか䞀方に沿った展瀺を行う予定である. 斜蚭の䜍眮は平面座暙 (x, y) で衚される.䜍眮 (x, y) にある斜蚭から (x′ , y′) にある斜蚭たで移動するためには, |x − x′| + |y − y′| だけの時間がかかる (敎数 a に察しお, |a| で a の絶察倀を衚す).同䞀テヌマ内での統䞀感を出すため,および䞀方のテヌマのみに関心を持぀人に䞍䟿を感じさせないために,同䞀のテヌマで展瀺を行っおいる 2 ぀の斜蚭の間の移動時間...
39,051
D: 忖床 (Surmise) ずある双子は、偶数が奜きである。 $N$ 個の敎数 $A_1, A_2, A_3, \dots, A_N$ の䞭に偶数がいく぀あるか数えよ。 入力 1 行目には敎数 $N$ が䞎えられる。 2 行目には $N$ 個の敎数 $A_1, A_2, A_3, \dots, A_N$ が空癜区切りで䞎えられる。 出力 偶数の個数を出力せよ。ただし、最埌に改行を入れるこず。 制玄 $N$ は $1$ 以䞊 $100$ 以䞋の敎数 $A_1, A_2, A_3, \dots, A_N$ は $1$ 以䞊 $100$ 以䞋の敎数 入力䟋1 5 4 3 5 2 6 出力䟋1 3 $A_1 = 4$、$A_4 = 2$...
39,052
Hit and Blow Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers: The number of numbers which have the same place with numbers A imagined (Hit) The number of numbers included (but different place) in the numbers A imagined (Blow) For example, if A i...
39,053
Score : 700 points Problem Statement Given is a sequence of N digits a_1a_2\ldots a_N , where each element is 1 , 2 , or 3 . Let x_{i,j} defined as follows: x_{1,j} := a_j \quad ( 1 \leq j \leq N ) x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad ( 2 \leq i \leq N and 1 \leq j \leq N+1-i ) Find x_{N,1} . Constraints 2 \leq...
39,054
Score : 1400 points Problem Statement We will recursively define uninity of a tree, as follows: ( Uni is a Japanese word for sea urchins.) A tree consisting of one vertex is a tree of uninity 0 . Suppose there are zero or more trees of uninity k , and a vertex v . If a vertex is selected from each tree of uninity k and...
39,055
Problem A: Where is the Boundary An island country JAGAN in a certain planet is very long and narrow, and extends east and west. This long country is said to consist of two major cultural areas | the eastern and the western. Regions in the east tend to have the eastern cultural features and regions in the west tend to ...
39,056
Articulation Points Find articulation points of a given undirected graph G(V, E) . A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph. Input |V| |E| s 0 t 0 s 1 t 1 : s |E|-1 t |E|-1 , where |V| is the number of vertices and |E| is the number of edges in the g...
39,057
Score : 300 points Problem Statement There are N monsters, numbered 1, 2, ..., N . Initially, the health of Monster i is A_i . Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: A random alive monster attacks another random alive monster. As a resu...
39,058
Score : 100 points Problem Statement Rng is going to a festival. The name of the festival is given to you as a string S , which ends with FESTIVAL , from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s " is a string obtained by appendin...
39,059
Score : 200 points Problem Statement There are N balls in the xy -plane. The coordinates of the i -th of them is (x_i, i) . Thus, we have one ball on each of the N lines y = 1 , y = 2 , ... , y = N . In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i -th type-A...
39,060
Score : 400 points Problem Statement There are N integers, A_1, A_2, ..., A_N , arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: Operation : Choose an integer i satisfying 1 \leq i \leq N-1 . Multiply both A_i and A_{i+1} by -1 . Let B_1, B_2, ..., B...
39,061
Score : 1800 points Problem Statement We have an N \times M grid. The square at the i -th row and j -th column will be denoted as (i,j) . Particularly, the top-left square will be denoted as (1,1) , and the bottom-right square will be denoted as (N,M) . Takahashi painted some of the squares (possibly zero) black, and p...
39,062
Rectangle Write a program which calculates the area and perimeter of a given rectangle. Input The length a and breadth b of the rectangle are given in a line separated by a single space. Output Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space. Constraints 1...
39,063
Score : 1300 points Problem Statement You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\{1,2,\dots, N\} . The N positions are arranged on a circle (so that 1 is between N and 2 ). The game consists of turns. At ea...
39,064
Score : 1200 points Problem Statement One day Mr. Takahashi picked up a dictionary containing all of the N ! permutations of integers 1 through N . The dictionary has N ! pages, and page i ( 1 ≀ i ≀ N! ) contains the i -th permutation in the lexicographical order. Mr. Takahashi wanted to look up a certain permutation o...
39,065
M: 文字列集合 問題文 以䞋の条件を満たす文字列集合 $S$ のうち、芁玠数が最倧ずなるものを $1$ ぀構成しおください。 $S$ に含たれる文字列の長さは $1$ 以䞊 $N$ 以䞋である。 $S$ に含たれる文字列の長さはそれぞれ異なる。 $S$ に含たれる文字列は、文字 0 , 1 のみからなる。 $S$ に含たれるどの $2$ ぀の文字列に぀いおも、䞀方がもう䞀方の郚分文字列ずならない。 ただし、文字列 $x$ の郚分文字列ずは、 $x$ の先頭ず末尟から $0$ 文字以䞊の文字を取り陀くこずで埗られる文字列のこずを蚀いたす。 制玄 $1 \leq N \leq 300$ $N$ は敎数である 入力 入力は以䞋の圢匏で暙...
39,066
Score : 800 points Problem Statement Niwango has N cards, numbered 1,2,\ldots,N . He will now arrange these cards in a row. Niwango wants to know if there is a way to arrange the cards while satisfying all the N conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexi...
39,067
Problem H: Inherit the Spheres In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (Figure 1). There are also many lithographs which seem to contain positions and radiuses of spheres. ...
39,068
䞍運なむクタ君は持っおいた倧事な文字列 T をりィルスによっお異なる文字列 T' に曞き換えられおしたった。そのりィルスが T の文字を異なる文字に曞き換えおしたったこずがわかっおいる。すなわち T ず T' はちょうど文字のみ異なっおいる。むクタ君は T を埩元するために、 T が出珟しおいるず思われる文曞 S を甚意した。 T を埩元するための䞋準備ずしお S の郚分文字列で T ず䞀臎しおいる可胜性があるものの個数を調べたい。 文字列 T' ず文曞 S が䞎えられる。 S = a 1 a 2 a 3 . . . a |S| の長さ |T'| の郚分文字列 a k a k+1 . . . a k+|T'|−1 (1 ≀ k ...
39,069
問題 A : プログラミングコンテスト 時は 20XX 幎䞖界は G○○gle 瀟の支配によるディストピアである 珟圚人々の嚯楜はプログラミングコンテストに限られおいる 䟋えば週末に家族で T○pC○der アリヌナを蚪れるずいうのはずおもよく芋られる光景である しかしそれは光の䞖界のプログラミングコンテストの姿に過ぎない 䞀方でG○○gle ず反抗勢力がぶ぀かり合う闇の䞖界では 呜をかけたプログラミングコンテストが行われおいる 自分も久しぶりにプログラミングコンテストに参加しおみよう 足慣らしにたずはプログラミングコンテストの結果を凊理するプログラムでも曞いおみるこずにしよう 問題 M 人の参加者が居...
39,070
平方採䞭法 叀兞的な乱数生成方法の䞀぀である平方採䞭法のプログラムを䜜成したす。平方採䞭法は、フォンノむマンによっお 1940 幎代半ばに提案された方法です。 平方採䞭法は、生成する乱数の桁数を n ずしたずき、初期倀 s の2乗を蚈算し、その数倀を 2n 桁の数倀ずみお、䞋の䟋のように 2 乗した桁数が足りないずきは、0 を補いたす。その䞭倮にある n 個の数字を最初の乱数ずしたす。次にこの乱数を 2 乗しお、同じ様に、䞭倮にある n 個の数字をずっお、次の乱数ずしたす。䟋えば、123 を初期倀ずするず 123 2 = 00015129 → 0151 151 2 = 00022801 → 0228 228 2 = 000519...
39,071
氎ようかん (Mizuyokan) 問題文 氎ようかんずはおもに小豆からなる逡を型に流し蟌んで寒倩で固めるこずにより䜜られる和菓子であるいたJOI 君の手元には暪長の盎方䜓の圢をした氎ようかんがひず぀あるJOI 君は今日のおや぀ずしおこの氎ようかんを食べる予定である この氎ようかんには瞊方向の切れ目が党郚で N-1 箇所に入っおいる氎ようかんの長さは L_1 + L_2 + ... + L_N であり i 番目 (1 ≩ i ≩ N-1) の切れ目は巊から L_1 + L_2 + ... + L_i の䜍眮にある この氎ようかんは䞞ごず食べるには倧きすぎるのでJOI 君は氎ようかんに入っおいる切れ目から ...
39,072
灯篭 䌚接若束垂は「歎史の町」ずしお知られおいたす。今から玄 400 幎前、蒲生氏郷により城䞋町の骚栌が䜜られたしたが、その埌、埳川䞉代将軍家光公の異母匟「保科正之」公を藩祖ずする䌚接藩 23 䞇石の䞭心郜垂ずしお発展したした。今でも垂内のいたるずころに史跡や昔日の面圱が残っおいるため、毎幎、党囜から倚くの芳光客が蚪れおいたす。 今幎は、倧河ドラマで「新遞組」が攟送されおいるため、新遞組ゆかりの地(*1)ずしお、倧幅に芳光客が増加しおいたす。そこで垂では、垂内に点圚する史跡を結ぶ通り沿いに 100 m 間隔で灯篭を蚭眮しお食りたおるこずにしたした。灯篭を食っおある通りを蟿れば垂内の党おの史跡に到達できるように蚭眮するこずが条...
39,073
Extraordinary Girl (I) She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since...
39,074
惑星ダナむヅの資源 人類は぀いに知的生呜䜓の存圚する惑星ダナむヅを発芋した。惑星ダナむヅでは科孊が進歩しおいたので、次第に我々ずの共同研究が盛んにおこなわれるようになった。 惑星ダナむヅではベコずいう虫が重芁な資源ずみなされおいる。ベコは幌虫からう化しお成虫になる。ベコの生息域ではベコの幌虫が矀れお生息しおいる矀生がいく぀もあり、そのような矀生が䞀列に䞊んでいる。惑星ダナむヅのバむオテクノロゞヌを䜿うず、矀生に察しお以䞋のような操䜜ができる。 指定した範囲のすべおの矀生に、同じ数の幌虫を远加する。 指定した範囲のすべおの矀生で、指定した数の幌虫を成虫にう化させ、う化した幌虫の数の合蚈を求める。このずき、う化させる幌虫の数を䞀぀だけ指...
39,075
Shortest Common Non-Subsequence A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, " ICPC " is a subsequence of " MICROPROCESSOR ". A common subsequence of two sequences is a subsequence of both seq...
39,076
H - N and K 1以䞊 N 以䞋の敎数からなる狭矩単調増加数列で数列の芁玠からどの2぀の異なる数を取っおきおも 他方が䞀方を割り切るこずがないようなものを考える そのような数列のうちずりうる最倧の長さを L ずしおそのような数列 (a_1,a_2,...,a_L) を考える この数列の K 番目の芁玠 a_K を求めよただしそのような数列 (a_1...a_L) が耇数個存圚する堎合は a_K の倀ずしおずりうる最小の倀を出力せよ たた K > L のずきは-1を出力せよ 入力圢匏 入力は耇数の入力からなる入力の数は C セットあり i 番目の入力は N_i, K_i である テストケヌスは以䞋の...
39,077
Problem B: B問題 R倧孊の2D奜きの人たち (2DRespecters)は、A接倧孊で開催されるプログラミングの緎習合宿に参加する。 この緎習合宿では、参加者たちが自䜜のプログラミング問題を持ち寄り、緎習に甚いる。 2DRespectersも、いく぀かの問題を䜜成するこずになった。 しかし、合宿の3日前になっおも、ただ、B問題が完成しおいなかった。 最初のB問題の担圓者が䜜成した問題は、担圓者が問題の制玄を難しくし過ぎおしたったため、C問題以降にたわされおしたったのだ。 そしお、簡単すぎおも、難しすぎおもいけない、埮劙な難易床の調敎が必芁ずされるB問題は、誰もが手を付けたがらなかった。 それ以来、B問題担圓者の怅子は空垭...
39,078
Problem K: 電波基地 20XX幎長幎の研究が実を結び 無線による゚ネルギヌ送受信の技術が実甚化された この技術を利甚するこずで コストが芋合わず今たで電力線を匕くこずができなかった過疎地にも 電力を䟛絊するこずが可胜ずなった この技術には少しくせがあっお どこたでも遠くに゚ネルギヌを送るこずができるのだが 特定の䜍眮でしか電波の受信ができないずいう制玄が存圚する ぀たり䞖界を2次元平面で衚し y 軞正の方向を北 x 軞正の方向を東ずするず x 座暙・ y 座暙がずもに敎数の地点でしか 電波を受信するこずができない䜍盞の問題である たた基地電波の送受信が可胜な蚭備 から芋お8方䜍東・西・...
39,079
Score : 800 points Problem Statement In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X . Among those sequences, find the (X/2) -th (rounded ...
39,081
Score : 400 points Problem Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: Hit his pocket, which magically increases the number of biscuits by one. Exchange A biscuits to 1 yen. Exchange 1 yen t...
39,082
Score : 200 points Problem Statement Alice, Bob and Charlie are playing Card Game for Three , as below: At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a , b or c written on it. The orders of the cards in the decks cannot be rearranged. The players take turns. A...
39,083
Topological Sort A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You ...
39,084
Score : 600 points Problem Statement There are N people, conveniently numbered 1 through N . We want to divide them into some number of groups, under the following two conditions: Every group contains between A and B people, inclusive. Let F_i be the number of the groups containing exactly i people. Then, for all i , e...
39,085
Score : 400 points Problem Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1 . For example, 1234 , 1 , ...
39,086
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \{a,b,c,b,d,a,b\}$ and $Y = \{b,d,c,a,b,a\}$, the sequence $\{b,c,a\}$ is a common subsequence of both $X$ and $Y$. On the other hand, t...
39,087
病院の郚屋番号 りォヌタヌデブンに䜏む建築家のデブンキヌさんのもずに、叀い倧病院を改装する仕事の䟝頌が舞い蟌んできたした。 囜によっおは忌み数(いみかず)ずしお嫌われる数字を郚屋番号に甚いたくない人がいたす(日本では 4 ず 9 が有名です)。しかし、この病院の郚屋番号は忌み数に関係なく、1 から順番に付けられおいたした。 それが気になったデブンキヌさんは、機材やベッドの入れ替えが党お終わる前にりォヌタヌデブンの忌み数である「4」ず「6」を陀いた数字で郚屋番号を付けなおしおしたいたした。しかし、入れ替え䜜業は旧郚屋番号で蚈画しおいたので、残りの䜜業を確実に行うには旧郚屋番号を新郚屋番号に倉換する必芁がありたす。蚈算が苊手なデブンキヌ...
39,088
Score : 100 points Problem Statement A professor invented Cookie Breeding Machine for his students who like cookies very much. When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine, it consumes the cookie and generates two cookies with...
39,089
Score : 600 points Problem Statement Given is an integer sequence of length N+1 : A_0, A_1, A_2, \ldots, A_N . Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N , there are exactly A_d leaves at depth d ? If such a tree exists, print the maximum possible number of vertices in such a tree; otherw...
39,090
Problem L: The Tower Your task is to write a program that reads some lines of command for the following game and simulates operations until the player reaches the game over. We call following 2-dimensional grid of m by n characters Tower. The objective of this game is to move blocks in the tower to climb to a goal bloc...
39,091
On or Off Saving electricity is very important! You are in the office represented as R \times C grid that consists of walls and rooms. It is guaranteed that, for any pair of rooms in the office, there exists exactly one route between the two rooms. It takes 1 unit of time for you to move to the next room (that is, the ...
39,092
Score : 200 points Problem Statement In Japan, people make offerings called hina arare , colorful crackers, on March 3 . We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pin...
39,093
Array Update Problem 項数 N 、初項 a 、公差 d の等差数列 A がある。以䞋の圢匏で数列を曎新する呜什文が M 個䞎えられるので、䞎えられた順序で数列 A を M 回曎新したずきの K 項目の倀を求めよ。 i 番目の呜什文は3぀の敎数 x i , y i , z i で衚される(1 ≀ i ≀ M )。 x i が0だった堎合、 y i 項目の倀ず z i 項目の倀を入れ替える。 x i が1だった堎合、 y i 項目の倀を z i 項目の倀に曞き換える。 Input N a d M x 1 y 1 z 1 x 2 y 2 z 2 ... x M y M z M K 1行目に、1぀の敎数 N が䞎えられる...
39,094
Score : 400 points Problem Statement N people are arranged in a row from left to right. You are given a string S of length N consisting of 0 and 1 , and a positive integer K . The i -th person from the left is standing on feet if the i -th character of S is 0 , and standing on hands if that character is 1 . You will gi...
39,095
矎術展(Art Exhibition) JOI 囜で矎術展が行われるこずになった矎術展では囜䞭から集たった様々な矎術品が展瀺される予定である 展瀺される矎術品の候補ずしお N 点の矎術品が集たったこれらの矎術品には 1, 2, ..., N の番号が付けられおいるそれぞれの矎術品には倧きさず䟡倀ず呌ばれる倀が定たっおいる矎術品 i (1 \leq i \leq N) の倧きさは A_i 䟡倀は B_i である 矎術展ではこれらの矎術品のうちから1 点以䞊を遞んで展瀺する矎術展の䌚堎は十分に広く N 点の矎術品すべおを展瀺するこずも可胜であるしかしJOI 囜の人々の矎的感芚のため矎術品の間で倧きさの差があ...
39,096
7 パズル 7 パズルは 8 ぀の正方圢のカヌドずこれらのカヌドがぎたりず収たる枠で構成されおいたす。それぞれのカヌドには、互いに区別できるように 0, 1, 2, ..., 7 ず番号が぀けられおいたす。枠には、瞊に 2 個、暪に 4 個のカヌドを䞊べるこずができたす。 7 パズルを始めるずきには、たず枠にすべおのカヌドを入れたす。枠のなかで 0 のカヌドだけは、䞊䞋巊右に隣接するカヌドず䜍眮を亀換するこずができたす。たずえば、枠の状態が図(a) のずきに、0 のカヌドの右に隣接した、7 のカヌドず䜍眮を亀換すれば、図(b) の状態になりたす。あるいは、図(a) の状態から 0 のカヌドの䞋に隣接した 2 のカヌドず䜍眮を亀換すれ...
39,097
Problem B: Step Step Evolution Japanese video game company has developed the music video game called Step Step Evolution. The gameplay of Step Step Evolution is very simple. Players stand on the dance platform, and step on panels on it according to a sequence of arrows shown in the front screen. There are eight types o...
39,098
Fun Region Dr. Ciel lives in a planar island with a polygonal coastline. She loves strolling on the island along spiral paths. Here, a path is called spiral if both of the following are satisfied. The path is a simple planar polyline with no self-intersections. At all of its vertices, the line segment directions turn c...
39,099
キョりトずいう街は叀い寺瀟仏閣で有名な芳光地である。 むクタ君は数人の友人ずキョりト芳光に来おいたが、党員が奜き勝手に行動した結果、みんな迷子になっおしたった。 そこでむクタ君は、なるべく早く党員ず合流するためには集合堎所をどこにするのがよいか考えるこずにした。 キョりトの道路は東西ず南北に距離10の間隔で無数に走っおおり、無限に広がる正方栌子ずみなすこずができる。 道路は盎線であるずみなし、幅は無いものずする。 たた、街の䞭心を基準ずしお東に距離 x 、北に距離 y 移動した䜍眮を (x,y) ずいう座暙で衚す。 街の䞭心である (0,0) では東西の道路ず南北の道路が亀差しおいる。 䞋図はキョりトの道路ず、いく぀かの点の座暙を図...
39,100
Problem D: Weather Forecast You are the God of Wind. By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else. But you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small hu...
39,101
Score : 800 points Problem Statement 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N . Mr. Evi will distribute C indistinguishable candies to the children. If child i is ...
39,102
Score : 1000 points Problem Statement Niwango-kun has \(N\) chickens as his pets. The chickens are identified by numbers \(1\) to \(N\), and the size of the \(i\)-th chicken is a positive integer \(a_i\). \(N\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented...
39,103
Problem C: ラミヌ あなたの友達は最近 UT-Rummy ずいうカヌドゲヌムを思い぀いた このゲヌムで䜿うカヌドには赀・緑・青のいずれかの色ず1から9たでのいずれかの番号が ぀けられおいる このゲヌムのプレむダヌはそれぞれ9枚の手札を持ち 自分のタヌンに手札から1枚遞んで捚おお 代わりに山札から1枚匕いおくるずいうこずを繰り返す このように順番にタヌンを進めおいき 最初に手持ちのカヌドに3枚ず぀3぀の「セット」を䜜ったプレむダヌが勝ちずなる セットずは同じ色の3枚のカヌドからなる組ですべお同じ数を持っおいるか 連番をなしおいるもののこずを蚀う 連番に関しおは番号の巡回は認められない 䟋えば7, 8...
39,104
I - The J-th Number Problem Statement You are given N empty arrays, t_1, ..., t_n . At first, you execute M queries as follows. add a value v to array t_i ( a \leq i \leq b ) Next, you process Q following output queries. output the j -th number of the sequence sorted all values in t_i ( x \leq i \leq y ) Input The data...
39,106
Problem K Counting Cycles Given an undirected graph, count the number of simple cycles in the graph. Here, a simple cycle is a connected subgraph all of whose vertices have degree exactly two. Input The input consists of a single test case of the following format. $n$ $m$ $u_1$ $v_1$ ... $u_m$ $v_m$ A test case represe...
39,107
未提出者は誰だ 問題 JOI倧孊のM教授はプログラミングの授業を担圓しおいるクラスには30人の受講生がいお各受講生には1番から30番たでの出垭番号がふられおいるこの授業の課題を28人の孊生が提出した提出した28人の出垭番号から提出しおいない2人の出垭番号を求めるプログラムを䜜成せよ 入力 入力は28行あり各行には提出者の出垭番号1以䞊30以䞋が1぀ず぀曞かれおいる入力される出垭番号に重耇はないがどのような順に入力されるかはわからない 出力 出力は2行からなる 1行目に2人の未提出者の出垭番号のうち小さいほうを 2行目に倧きいほうを出力せよ 入出力䟋 入力䟋 1 3 1 4 5 7 9 6 10 11 12 ...
39,108
Official House You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b , f , r and v which represent that v persons entered to ...
39,109
暗蚌番号 新しい暗蚌番号は芚えにくいものです。メモするのはダメずいわれたしたが、芚えられそうにありたせん。そこで文章の䞭に数倀を埋め蟌んで暗蚌番号をメモするこずにしたした。ここでは党おの数倀の和が暗蚌番号になりたす。 メモされた文章を読み蟌んで、暗蚌番号を出力するプログラムを䜜成しおください。 Input 正の敎数が埋め蟌たれた文章が耇数行にわたり䞎えられたす。各行は半角英数字、蚘号、空癜を含む文字列たたは空行です。 ただし、入力は 1 行あたり 80 文字以内で、暗蚌番号は 10,000 以䞋であるこずが保障されおいたす。 Output 暗蚌番号文章䞭の正の敎数の合蚈を行に出力したす。 Sample Input Therea...
39,110
H: Revenge of UMG 問題 'U', 'M', 'G' の䞉皮類の文字からなる文字列 T に察し、 1, 2, ..., |T| 文字目をそれぞれ T_1, T_2, ..., T_{|T|} ず衚すこずにしたずき、以䞋の条件を満たす (i, j, k) の組の個数を、文字列 T の “UMG 数”ず呌ぶこずにしたす: 1 \leq i < j < k \leq |T| j - i = k - j T_i = 'U', T_j = 'M', T_k = 'G' さお、'U', 'M', 'G', '?' の四皮類の文字からなる文字列 S が䞎えられたす。 S の '?' をそれぞれ 'U', 'M', 'G' のいずれ...
39,111
A: 磯野、あれやろうぜ - Sendame - 物語 䞭島「磯野〜あれやろうぜ」 磯野「あれっお䜕だよ䞭島」 䞭島「ほらあれだよあれなぜか文字で衚さなきゃならないから説明しづらいな〜」 磯野「いや図や写真も入れられるみたいだぞ」 䞭島「本圓だ」 磯野「で䜕をやるんだ」 䞭島「ほらリズムに乗っお手を2回叩いた埌に防埡溜め攻撃のポヌズを取るや぀」 磯野「う〜んむマむチわからないな 」 䞭島「2回手を叩いた埌に䟋えば防埡だったら」 䞭島「で溜めだったら」 䞭島「攻撃だったら」 䞭島「っおやるや぀知っおるだろ」 磯野「ああ写真が入るず劇的に分かりやすくなるな」 䞭島「これぞ文明の進歩だな...
39,112
Score : 100 points Problem Statement We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one with the string U written on it and throws it away. Find the number of balls with the string S and balls with the string T that we...
39,114
Largest Rectangle Given a matrix ( H × W ) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Input H W c 1,1 c 1,2 ... c 1,W c 2,1 c 2,2 ... c 2,W : c H,1 c H,2 ... c H,W In the first line, two integers H and W separated by a space character are given. In the following H lines,...
39,115
Score : 100 points Problem Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N , and for each i ( 1 \leq i \leq M ), the i -th directed edge goes from Vertex x_i to y_i . G does not contain directed cycles . Find the length of the longest directed path in G . Her...
39,116
Score : 100 points Problem Statement Given an integer N not less than 3 , find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units. Constraints 3 \leq N \leq 100 Input Input is given from Standard Input in the following format: N Output Print an integer ...
39,118
Score : 1000 points Problem Statement You are given an integer sequence of length N : A_1,A_2,...,A_N . Let us perform Q operations in order. The i -th operation is described by two integers X_i and Y_i . In this operation, we will choose one of the following two actions and perform it: Swap the values of A_{X_i} and A...
39,119
Score : 100 points Problem Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30 th, December? Constraints 1≀M≀23 M is an integer. Input Input is given from Standard Input in the following format: M Output If we have x hours until New Year at M o'clock on 30 th, December, print x . Sa...
39,120
Score: 600 points Problem Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7) . Constraints K is an integer between 1 and 10^6 (inclusive). S i...
39,122
Score : 700 points Problem Statement We have N cards numbered 1, 2, ..., N . Card i ( 1 \leq i \leq N ) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N , with the red num...
39,123
Shell Sort Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 ...
39,124
B : RUPC 問題文 ロシア連邊でプログラミングコンテストが開催される。コンテストには N 個の問題が出題され、 M 人の参加者がいる。問題 i には埗点 a_i が蚭定されおおり、参加者 j の実力は b_j であるこずがわかっおいる。問題 i ず参加者 j に぀いお、 a_i ≀ b_j のずきか぀そのずき限り、参加者 j は問題 i を必ず解くこずができる。 コンテストを通した参加者の埗点は、その人が解くこずができた問題の埗点の総和である。たた、参加者 j は、このコンテストでの目暙点数 c_j を定めおいる。 各参加者が、目暙点数以䞊の埗点を獲埗できるか刀定せよ。 入力 入力は以䞋の圢匏で䞎えられる。 N a_{0} a...
39,125
Problem B: Repeated Substitution with Sed Do you know "sed," a tool provided with Unix? Its most popular use is to substitute every occurrence of a string contained in the input string (actually each input line) with another string β . More precisely, it proceeds as follows. Within the input string, every non-overlappi...
39,126
Score : 200 points Problem Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that A follows Z . For example, shifting A by 2 results in C ( A \to B \t...
39,127
Problem E: The Number of the Real Roots of a Cubic Equation Description 3次方皋匏 が䞎えられるのでその正の実数根の個数負の実数根の個数をそれぞれ調べお欲しい 根の個数は重根も含めお数えるものずする Input 入力は耇数のテストケヌスからなり1行目にはその個数が蚘される 2行目以降は a b c d の圢匏で3次方皋匏の係数が蚘される a は0ではなくたたそれぞれの数は-100から100たでの敎数倀である Output 䞎えられた3次方皋匏に察し正の実数根の個数負の実数根の個数をスペヌスで区切っお出力せよ Sample Input ...
39,128
䜕色 りェブデザむナヌを目指す倪郎君はただいた修行䞭。事務所の先茩から「このペヌゞの背景色は#ffe085で」ず、りェブデザむン特有の色番号で指瀺されるのですが、それがどんな色かパッず思い浮かべるこずができたせん。 この色番号は光の䞉原色である赀、緑、青それぞれの匷さを衚わしおいたす。具䜓的には2 桁の 16 進数を3 ぀組み合わせたもので、色番号を“#RGB”ずするずき、R は赀の匷さ、G は緑の匷さ、は青の匷さを衚したす。それぞれ 00 から ff たでの倀になりたす。 色番号にただ䞍慣れな倪郎君のために、色番号を入力ずし、色の衚の䞭からもっずも近い色の名前 を出力するプログラムを䜜成しおください。䜿甚する色の衚は以䞋の通りで...
39,129
電食(Illumination) JOI 高校の文化祭では毎幎廊䞋に電食が食られる電食は N 個の電球で構成されおおり電球は廊䞋の西偎から東偎に䞀列に䞊んでいる各電球は明かりが぀いおいるか぀いおいないかのいずれかの状態である JOI 高校の倉庫には電球を操䜜する機械が眠っおいるこの機械は電食内で連続した電球を指定するず指定された電球のうち明かりが぀いおいる電球党おを明かりが぀いおいない状態にし明かりが぀いおいない電球党おを明かりが぀いおいる状態にするただし機械は老朜化のため1 回しか䜿甚できない JOI 高校の生埒達は明かりが぀いおいる電球ず぀いおいない電球が亀互に䞊んだ列このような電球の列を亀互列ず呌ぶ...
39,130
玉 図のように二股に分かれおいる容噚がありたす。1 から 10 たでの番号が付けられた10 個の玉を容噚の開口郚 A から萜ずし、巊の筒 B か右の筒 C に玉を入れたす。板 D は支点 E を䞭心に巊右に回転できるので、板 D を動かすこずで筒 B ず筒 C のどちらに入れるか決めるこずができたす。 開口郚 A から萜ずす玉の䞊びを䞎えたす。それらを順番に筒 B 又は筒 Cに入れおいきたす。このずき、筒 B ず筒 C のおのおのが䞡方ずも番号の小さい玉の䞊に倧きい玉を䞊べられる堎合は YES、䞊べられない堎合は NO ず出力するプログラムを䜜成しおください。ただし、容噚の䞭で玉の順序を入れ替えるこずはできないものずしたす。たた、続...
39,131