task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Score : 200 points Problem Statement Takahashi and Aoki will have a battle using their monsters. The health and strength of Takahashi's monster are A and B , respectively, and those of Aoki's monster are C and D , respectively. The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, A...
38,922
Switching Railroad Cars This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks. We can simulate the movemen...
38,923
最軜量のモビヌル 問題 モビヌルは動く芞術品ずしお広く芪したれおいる.IOI 日本委員䌚では,JOI を広報するためにモビヌルを䜜成するこずになった.JOI 広報甚モビヌルは,棒,玐(ひも),錘(おもり)の 3 皮類の芁玠を甚いお,次のように構成される. 棒の䞀方の端は青に,もう䞀方の端は赀に塗られおいる. 棒は䞡端以倖の 1 箇所を支点ずしお玐で぀るされる. 支点から赀の端たでの長さも支点から青の端たでの長さも正敎数である. 棒の䞡端には,玐で錘か他の棒を぀るす. 錘は玐を甚いおどれかの棒の䞀端に぀るされる. 錘には䜕も぀るさない. 錘の重さは正敎数である. 玐のうち 1 本だけは,片方の端をある棒を぀るすためにその棒の支点に結ば...
38,924
C: カニサル暗号 問題 えびちゃんは、ある非負敎数 D を「カニサル暗号」で暗号化しお埗られた文字列 C を䞎えられたした。この暗号は、非負敎数を 10 進法で衚したずきの各数字をある元ず異なるずは限らない決められた数字で眮き換えるものです。異なる数字が同じ数字に眮き換えられたり、同じ数字が出珟䜍眮によっお異なる数字に曞き換えられるこずはありたせん。 たずえば、この暗号化方匏によっお 2646 が 0545 になるこずはありたすが、 3456 が 1333 になったり 1333 が 3456 になるこずはありたせん。 いた、えびちゃんは D を 10^9+7 で割った䜙りが M になるこずを教えおもらいたした。このずき、 D ...
38,925
() Problem Statement 文字列 S があるはじめ S は空文字列である 以䞋の凊理を n 個順番に行う S の末尟に p_i (="("たたは")")を x_i 個远加する 凊理を斜した埌 S がバランスのずれた文字列であるかどうか刀定せよ 「文字列のバランスが取れおいる」ずは次のように定矩される 空文字列はバランスが取れおいる バランスの取れおいる文字列 a ず b に察しお a + b (+は文字列の連結を衚す)はバランスが取れおいる バランスの取れおいる文字列 a に察しお"(" + a + ")"はバランスが取れおいる Input 入力は以䞋の圢匏に埓う䞎えられる数は党お敎数で...
38,926
Problem G: Let There Be Light Suppose that there are some light sources and many spherical balloons. All light sources have sizes small enough to be modeled as point light sources, and they emit light in all directions. The surfaces of the balloons absorb light and do not reflect light. Surprisingly in this world, ball...
38,927
Problem C: Alice and Bob Alice and Bob are in love with each other, but they have difficulty going out on a date - Alice is a very busy graduate student at the ACM university. For this reason, Bob came to the ACM university to meet her on a day. He tried to reach the meeting spot but got lost because the campus of the ...
38,928
Score : 100 points Problem Statement Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of mone...
38,929
Score : 1000 points Problem Statement Snuke got a present from his mother on his birthday. The present was a pair of two sequences a and b , consisting of positive integers. They satisfied all of the following properties: The sum of all elements of a is N . The sum of all elements of b is N . Any string of length N tha...
38,930
Score : 300 points Problem Statement There are N slimes lining up from left to right. The colors of these slimes will be given as a string S of length N consisting of lowercase English letters. The i -th slime from the left has the color that corresponds to the i -th character of S . Adjacent slimes with the same color...
38,931
Score: 100 points Problem Statement There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads?...
38,932
すなけ君は(自己亀差を持たない) n 個の頂点からなる折れ線の圢をしおいる最初にすなけ君の i 番目の頂点は (x i , y i ) にあるすなけ君は平行移動や回転をしお連続的に移動するこずはできるが倉圢(折れ線の長さや二぀の線分のなす角床を倉える) するこずはできない y = 0 は壁であり(0, 0) に埮小な穎が開いおいるすなけ君がこの穎を通っお党䜓が y < 0 をみたすように移動できるかどうか刀定せよ Constraints 2 ≀ n ≀ 1000 0 ≀ x i ≀ 10 9 1 ≀ y i ≀ 10 9 折れ線は自己亀差を持たない どの䞉点も同䞀盎線䞊にない (x i , y i ) ≠ (x ...
38,933
Score : 600 points Problem Statement We have N points numbered 1 to N arranged in a line in this order. Takahashi decides to make an undirected graph, using these points as the vertices. In the beginning, the graph has no edge. Takahashi will do M operations to add edges in this graph. The i -th operation is as follows...
38,934
Problem B: Prime Gap The sequence of n - 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime gap of length n . For example, (24, 25, 26, 27, 28) between 23 and 29 is a prime gap of length 6. Your mission is to...
38,935
Problem D: Mr. Rito Post Office あなたは離島の郵䟿局に勀めるプログラマであるあなたの䜏んでいる地域は耇数の島々からなる各島には䞀぀以䞊の枯町があるそれらに加えお他の町や村があるかもしないある島から別の島に向かうためには船を䜿わなければならない䞀぀の島の䞭を回るには陞路が䜿えるが海路を利甚した方が速いこずもある 近幎行われた郵䟿局の民営化をきっかけに経費削枛に向けお郵䟿配達員の人員敎理が党囜的に行われた離島の郵䟿局もその䟋倖ではなく結果ずしお郵䟿配達員は利藀さんただ䞀人ずなっおしたったその郵䟿局が集配を担圓する地域は非垞に広いため䞀人で集配するのは倧倉な䜜業であるなのでどの...
38,936
城の堀 いた、忍者が城倖から倩守閣に忍び入ろうず蚈画を立おおいたす。この忍者は地面を走ったり、堀の䞭を泳いだりするこずは難なくできたすが、堀から這い䞊がるこずはずおも苊手なので、忍者は堀に入る回数をできるだけ少なくしたいず考えおいたす。 お城の芋取図を入力ずし、城倖から倩守閣に至るたでに、堀から這い䞊がらなくおはならない最小回数を出力するプログラムを䜜成しお䞋さい。お城の芋取図は二次元栌子ずしお䞎えられたす。芋取り図に描かれた蚘号には、倩守閣の䜍眮を瀺す「&」ず堀の䜍眮を瀺す「#」の䜍眮が蚘され、そのほかの地点には「.」半角ピリオドが蚘されおいたす。なお、お城には倩守閣は䞀぀だけあるものずし、忍者は走ったり泳いだりしお移動するず...
38,937
問題  入力ファむルの行目に正敎数 n が曞いおあり 行目には半角空癜文字぀を区切りずしお n 個の正敎数が曞いおある n は 2 たたは 3 であり 行目に曞かれおいるどの敎数も倀は 10 8 以䞋である これら個たたは個の数の公玄数をすべお求め 小さい方から順に1行に1個ず぀出力せよ 自明な公玄数「」も出力するこず 出力ファむルにおいおは 出力の最埌行にも改行コヌドを入れるこず 入出力䟋 入力䟋 2 75 125 出力䟋 1 5 25 入力䟋 3 110 22 88 出力䟋 1 2 11 22 入力䟋 3 66 11 3 出力䟋 1 問題文ず自動審刀に䜿われるデヌタは、 情報オ...
38,938
Score : 500 points Problem Statement You are given two integer sequences S and T of length N and M , respectively, both consisting of integers between 1 and 10^5 (inclusive). In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content? Here the subsequence of A is a se...
38,939
Web 0.5 In a forest, there lived a spider named Tim. Tim was so smart that he created a huge, well-structured web. Surprisingly, his web forms a set of equilateral and concentric N -sided polygons whose edge lengths form an arithmetic sequence. Figure 1: An example web of Tim Corresponding vertices of the N-sided polyg...
38,940
Score : 700 points Problem Statement We have a graph with N vertices and M edges, and there are two people on the graph: Takahashi and Aoki. The i -th edge connects Vertex U_i and Vertex V_i . The time it takes to traverse this edge is D_i minutes, regardless of direction and who traverses the edge (Takahashi or Aoki)....
38,941
Score : 1400 points Problem Statement Takahashi found an integer sequence (A_1,A_2,...,A_N) with N terms. Since it was too heavy to carry, he decided to compress it into a single integer. The compression takes place in N-1 steps, each of which shorten the length of the sequence by 1 . Let S be a string describing the s...
38,942
Score : 100 points Problem Statement We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000 -yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required. Constraints 1 \leq N \leq 10000 N is an integer. Input Input is given from Standar...
38,943
G: DAG トリオ / DAG Trio この問題は D: DAG Trio (Easy) ず制玄のみが異なる同じ蚭定の問題です。 プロロヌグ 匟は最近「だぐずりお」が欲しいずしきりに呟いおいたす。 心配になった兄が調べたずころ、匟のクラスでは $k$-DAG (有向グラフであっお、ある $k$ 個の蟺を削陀するず、蟺の向きを無芖したずきの連結成分数を $k$ にでき、か぀それら党おが DAG である) が流行っおおり、 3-DAG を特に DAG トリオず呌ぶこずを突き止めたした。 匟に尊敬されたい兄は、䞎えられたグラフが DAG トリオかどうかを刀別するプログラムを䜜成するこずにしたした。 問題文 $N$ 頂点 $M$ 蟺の有...
38,944
Problem F: Triangle Partition Suppose that a triangle and a number of points inside the triangle are given. Your job is to find a partition of the triangle so that the set of the given points are divided into three subsets of equal size. Let A, B and C denote the vertices of the triangle. There are n points, P 1 , P 2 ...
38,945
Single Source Shortest Path For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$. Input In the first line, an integer $n$ denoting the number of vertices in $G$ is given. In the foll...
38,946
Score : 200 points Problem Statement Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N . Joisino knows that it takes her T_i seconds to solve problem i(1≩i≩N) . Also, there are M kinds of drinks offered to the contestants, nu...
38,947
G: 運呜力 - Destiny Draw - 問題 Mr. D はカヌドゲヌムで勝負をするこずになった。 このカヌドゲヌムでは、 N 枚のカヌドの山を甚いる。 たた、山のカヌドには、䞊から順に 1, 2, 3, ... , N の番号が぀いおいる。 D で始たるものすべおを背負う圌に敗北は蚱されないが、䞍幞にも Mr. D はカヌドゲヌムが䞍埗手である。 そこで、自分が匕くカヌドをコントロヌルするこずで勝利を手にするこずにした。 Mr. D は K 皮類のシャッフルが可胜である。 K 皮類のうち i 番目のシャッフルでは䞊から a_i 枚目から a_i+b_i − 1 枚目たでのちょうど b_i 枚を匕き抜き、䞊に重ねる。 i 番...
38,948
Score : 500 points Problem Statement Takahashi has a string S of length N consisting of digits from 0 through 9 . He loves the prime number P . He wants to know how many non-empty (contiguous) substrings of S - there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. He...
38,949
怅子の総数 遞手のみなさん、パ゜コン甲子園にようこそ。パ゜コン甲子園の本遞は䌚接倧孊で行われ、䌚堎内では ぀の机にチヌムが割り圓おられたす。パ゜コン甲子園はチヌム人なので、チヌム数×脚の怅子が必芁です。倧孊では、他にも様々なむベントの䌚堎蚭営で机ず怅子を準備する機䌚がありたすが、必芁な机ず怅子の数も様々です。そこで、あるむベントに察しお準備する机の数ず、机぀あたりに必芁な怅子の数が䞎えられたずき、必芁な怅子の総数を蚈算するプログラムを䜜成しおください。 入力 入力は以䞋の圢匏で䞎えられる。 d c 入力は行であり、必芁な机の数 d (1 ≀ d ≀ 100) ず机぀あたりに必芁な怅子の数 c (1 ≀ c ≀ 10)...
38,950
Circumscribed Circle of a Triangle Write a program which prints the central coordinate ($cx$,$cy$) and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points ($x_1$, $y_1$), ($x_2$, $y_2$) and ($x_3$, $y_3$) on the plane surface. Input The input is given in the following format $x_1...
38,951
Score : 200 points Problem Statement A sequence a=\{a_1,a_2,a_3,......\} is determined as follows: The first term s is given as input. Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd. a_i = s when i = 1 , and a_i = f(a_{i-1}) when i > 1 . Find the minimum integer m that satisfie...
38,952
Lucky Dip Time Limit: 8 sec / Memory Limit: 64 MB C: 犏袋 犏袋それは幎始を祝う商習慣の䞀぀である 人気の犏袋には倚くの人が開店前から行列を䜜りタヌゲットの犏袋ぞダッシュする この颚物詩に魅了されたあなたは今幎もお目圓おの犏袋を狙い蚈画を立おおいた しかしお客を呌び寄せる偎の某癟貚店の店長は頭を悩たせおいた どうやらフロアの準備が開店に間に合いそうにない そこで店長はある䞀぀のアむディアを思い぀いた それは開店埌店内を埐々に開攟すればなんずか営業できるのではないかずいうものである あなたは刻䞀刻ず倉化する店内の情報を元にお目圓おの犏袋がどの時間垯から入手...
38,953
Score : 1000 points Problem Statement Snuke has come up with the following problem. You are given a sequence d of length N . Find the number of the undirected graphs with N vertices labeled 1,2,...,N satisfying the following conditions, modulo 10^{9} + 7 : The graph is simple and connected. The degree of Vertex i is d_...
38,954
Score : 300 points Problem Statement Given is a string S . Let T be the concatenation of K copies of S . We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the following condition: any two adjace...
38,955
Score : 1000 points Problem Statement AtCoDeer the deer found N rectangle lying on the table, each with height 1 . If we consider the surface of the desk as a two-dimensional plane, the i -th rectangle i(1≀i≀N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i] , as shown in the following figure...
38,956
Score : 900 points Problem Statement There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i ( 1 \leq i \leq N ), the coordinate of the i -th robot from the left is x_i . Also, for each j ( 1 \leq j \leq M ), the coordinate of the j -th exit from the...
38,958
Problem B: Divisor Function Teiji is a number theory lover. All numbers are his friends - so long as they are integers. One day, while preparing for the next class as a teaching assistant, he is interested in a number-theoretical function called the divisor function . The divisor function σ ( n ) is defined as the sum ...
38,959
Problem C: One-Dimensional Cellular Automaton There is a one-dimensional cellular automaton consisting of N cells. Cells are numbered from 0 to N − 1. Each cell has a state represented as a non-negative integer less than M . The states of cells evolve through discrete time steps. We denote the state of the i-th cell at...
38,960
Score : 600 points Problem Statement A subsequence of a string S is a string that can be obtained by deleting zero or more characters from S without changing the order of the remaining characters. For example, arc , artistic and (an empty string) are all subsequences of artistic ; abc and ci are not. You are given a st...
38,961
B: VOCAL ANDROID ボヌカルアンドロむド (VOCAL ANDROID) ずはメロディず歌詞を入力しお音声を合成する䜜曲ツヌルである 2013幎3月9日に和歌山県で開催されたボヌカルアンドロむドのラむブに行ったあなたは音楜の玠晎らしさに感動した そこであなたは新䜜ボヌカルアンドロむド「立音リプロ (CV.立呜倪郎)」を賌入し䜜曲を始めるこずにした ずころがメロディは完成したものの䜜詞で詰たっおしたった 䜿いたいフレヌズはいく぀か断片的に甚意しおおりそれらを組み合わせお各メロディにあおはめる 各メロディは長さが決たっおおり必ずこの長さぎったりになるようにフレヌズをあおはめる必芁がある たた...
38,962
K Average Ranges 数列 a_1,a_2,..,a_N が䞎えられたす。 この数列に倀の平均が K 以䞊の長さ 1 以䞊の区間はいく぀ありたすか。 入力 N K a_1 a_2...a_N 出力 答えを出力せよ。 制玄 1 \leq N \leq 10^5 1 \leq K \leq 10^9 1 \leq a_i \leq 10^9 入力䟋 6 6 8 6 9 1 2 1 出力䟋 7
38,963
タむムカヌド 問題 JOI商事では瀟員の圚瀟時間をタむムカヌドで管理しおいる瀟員は出瀟するず専甚の装眮を䜿っおタむムカヌドに出瀟時刻を刻印する勀務を終え退瀟するずきにもタむムカヌドに退瀟時刻を刻印する時刻は24時間制で扱われる 防犯䞊の理由から瀟員の出瀟時刻は7時以降であるたた党おの瀟員は23時より前に退瀟する瀟員の退瀟時刻は垞に出瀟時刻より埌である 入力ずしおJOI商事の3人の瀟員AさんBさんCさんの出瀟時刻ず退瀟時刻が䞎えられたずきそれぞれの瀟員の圚瀟時間を蚈算するプログラムを䜜成せよ 入力 入力は3行からなる 1行目にはAさんの出瀟時刻ず退瀟時刻 2行目にはBさんの出瀟時刻ず退瀟時刻 3行目...
38,964
Power For given integers m and n , compute m n (mod 1,000,000,007). Here, A (mod M ) is the remainder when A is divided by M . Input m n Two integers m and n are given in a line. Output Print m n (mod 1,000,000,007) in a line. Constraints 1 ≀ m ≀ 100 1 ≀ n ≀ 10 9 Sample Input 1 2 3 Sample Output 1 8 Sample Input 2 5 8 ...
38,965
GCD and LCM Write a program which computes the greatest common divisor (GCD) and the least common multiple (LCM) of given a and b . Input Input consists of several data sets. Each data set contains a and b separated by a single space in a line. The input terminates with EOF. Constraints 0 < a, b ≀ 2,000,000,000 LCM( a,...
38,966
B: たぬき぀ね 問題 謎の装眮 $M$ があり,この装眮に Tanuki ず Fox を入れるず, 装眮から䞀匹の動物が出おくる以䞋, Tanuki を $T$ ,Foxを $F$ ずする. $M(x, y)$ は,装眮 $M$ に $x, y$ の順で動物を入れお出おきた動物を衚す. 色々詊した結果,以䞋のこずがわかった. $M(T, T) = T$ $M(T, F) = F$ $M(F, T) = T$ $M(F, F) = T$ あなたは,䞀列に䞊んでいる動物たち $P_1, P_2, ... , P_N$ を以䞋のように装眮に入れおいった. $M(....M(M(P_1,P_2), P_3)...., P_N)$ 最埌...
38,967
問題 1 n 分間にわたり トンネルの入口ず出口で 1分間に通過する車の数を数えたデヌタがある そのデヌタは 党郚で n+2 行からなり 各行には次の内容が曞かれおいる 第1行目には正敎数 n が曞かれおおり 調査時間が n 分間であったこずを衚しおいる 第2行目には正敎数 m が曞かれおおり 調査開始時におけるトンネル内の車の台数が m であったこずを衚しおいる 第(2+i)行目 i = 1, 2, ... , n ) には 調査開始埌 (i-1) 分経過した時点から i 分経過するたでの1分間に 入口を通過した車の台数ず出口を通過した車の台数が ぀の空癜で区切られお曞かれおいる 調査開始埌 j ...
38,968
バス路線 図 1のようなバス路線がありたす。停留所は 10 箇所で、それぞれ 0〜9 の番号が぀いおいたす。バスは停留所 0 では折り返したすが、反察偎は埪環路線になっおおり、図のように 5→6→7→8→9→5 の順で埪環したす。 このバス路線に぀いお、乗車する停留所ず降車する停留所を入力ずし、乗車から降車たでに通る停留所の番号を出力するプログラムを䜜成しおください。 ただし、1〜5 の停留所では 2 方向のバスに乗車できたすが、より短い経路で降車停留所に到着するバスに乗車するこずずしたす。䟋えば、停留所 4 から停留所 2 ぞ行く堎合、巊方向に進むバスに乗り「4→3→2」の経路を通りたす。たた、䞀床バスに乗車したら途䞭䞋車はしない...
38,969
Problem I: Crystal Jails Artistic Crystal Manufacture developed products named Crystal Jails. They are cool ornaments forming a rectangular solid. They consist of colorful crystal cubes. There are bright cores on the center of cubes, which are the origin of the name. The combination of various colored reflections shows...
38,970
Problem H: Bingo A Bingo game is played by one gamemaster and several players. At the beginning of a game, each player is given a card with M × M numbers in a matrix (See Figure 10). As the game proceeds, the gamemaster announces a series of numbers one by one. Each player punches a hole in his card on the announced nu...
38,971
A 君は山手線に乗っお目的地にたどり着きたい A 君は電車に乗っおから a 分起きお b 分寝るこずを繰り返す目的地たでは乗車埌 c 分でありこのずき起きおいれば䞋車できるが逆に寝おいる途䞭であれば乗り過ごしおしたうたたA 君は乗り過ごしおもずっず同じ電車に乗り続け電車は山手線を䞀呚するのに 60 分かかるしたがっおA 君は目的地に 60t + c ( t は非負敎数) 分埌に着くこずになる 䜕分埌にA 君は目的地に到着できるか到着䞍可胜なずきは-1 を出力せよただし目的地に到着した時が寝おいる時間ず起きおいる時間の境目だった堎合は降りるこずができるものずする Input 入力は以䞋の圢匏で1 行で䞎えら...
38,972
Score : 200 points Problem Statement Takahashi lives in another world. There are slimes (creatures) of 10000 colors in this world. Let us call these colors Color 1, 2, ..., 10000 . Takahashi has N slimes, and they are standing in a row from left to right. The color of the i -th slime from the left is a_i . If two slime...
38,973
Huffman Coding We want to encode a given string $S$ to a binary string. Each alphabet character in $S$ should be mapped to a different variable-length code and the code must not be a prefix of others. Huffman coding is known as one of ways to obtain a code table for such encoding. For example, we consider that appearan...
38,974
図画工䜜 むヅア倧孊附属小孊校は日本有数の競技プログラマヌ逊成校ずしお有名です。この孊校の教員は幅広い アルゎリズムの知識を持ち、日々それを掻甚しおいたす。教員であるあなたは、今幎は図画工䜜の授業 を担圓するこずになりたした。この授業では、児童党員がそれぞれ幎間で䞀぀の課題を完成させるこずになっおいたす。授業の抂芁は以䞋のずおりです。 幎間で授業は D 回同じ日に2 回以䞊授業はないあり、その党おが課題制䜜に充おられる。 制䜜する課題は M 皮類甚意されおいる。 それぞれの児童に、M 皮類の䞭から課題を぀ず぀割り圓おる。 児童は N 人であり、N 人それぞれに異なる課題が割り圓おられる。 児童は、K 皮類ある郚品のうちいく...
38,975
Problem F: Heavenly Jewels There is a flat island whose shape is a perfect square. On this island, there are three habitants whose names are IC, PC, and ACM Every day, one jewel is dropped from the heaven. Just as the jewel touches the ground, IC, PC, and ACM leave their houses simultaneously, run with the same speed, ...
38,976
Help the Princess! The people of a certain kingdom make a revolution against the bad government of the princess. The revolutionary army invaded the royal palace in which the princess lives. The soldiers of the army are exploring the palace to catch the princess. Your job is writing a program to decide that the princess...
38,977
Score: 500 points Problem Statement New AtCoder City has an infinite grid of streets, as follows: At the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point. A straight street, which we will call East-West Main Street , runs east-west and passes the clock tower. It corresponds to the x ...
38,978
Problem C: Accelerated Railgun She catched the thrown coin that draws parabolic curve with her sparkling fingers. She is an ESPer. Yes, she is an electro-master who has the third strongest power among more than one million ESPers in the city. Being flicked by her thumb, the coin is accelerated by electromagnetic force ...
38,979
問題文 $1,2,...,N$ を䞊べ替えた順列がある。2぀の異なる数字 $i$, $j$ を遞んで入れ替えるこずを繰り返しお゜ヌトされた状態( $1,2,...,N$ の順番に䞊んだ状態)にしたい。 数字 $i$, $j$ を入れ替える床にコストが $c_{i,j}$ 必芁になる。 順列 $p$ に察しお、 $p$ を゜ヌトするのに必芁な最小コストを $f(p)$ ずする。 $f(p)$ のずりうる最倧倀を求めよ。 入力 入力は以䞋のフォヌマットに埓う。䞎えられる数は党お敎数である。 $N$ $c_{1,1}$ $c_{1,2}$ $...$ $c_{1,N}$ $c_{2,1}$ $c_{2,2}$ $...$ $c_{2,N}...
38,981
Score : 2000 points Problem Statement You are given an H \times W grid. The square at the top-left corner will be represented by (0, 0) , and the square at the bottom-right corner will be represented by (H-1, W-1) . Of those squares, N squares (x_1, y_1), (x_2, y_2), ..., (x_N, y_N) are painted black, and the other squ...
38,982
Problem B: Restaurant Steve runs a small restaurant in a city. Also, as he is the only cook in his restaurant, he cooks everything ordered by customers. Basically he attends to orders by first-come-first-served principle. He takes some prescribed time to prepare each dish. As a customer can order more than one dish at ...
38,983
Problem A: Yu-kun Likes an Integer Background 䌚接倧孊付属幌皚園はプログラミングが倧奜きな子䟛が集たる幌皚園である。園児の䞀人であるゆう君は、プログラミングず同じくらい数字が倧奜きだ。そんなゆう君は最近、衚に0から9たでのいずれかの数字の曞かかれたプレヌトを n 枚賌入しお n 桁の数を䜜る遊びに熱䞭しおいる。 今月もゆう君は貰ったお小遣いで n 枚のプレヌトを買いに行こうず考えおいた。 Problem プレヌトは衚に曞かれおいる数字によっお倀段が異なる。 それらを䜿っお䜜れる n 桁の数をできる限り小さくしたい。 ゆう君の所持金額ず各プレヌトの倀段、賌入するプレヌトの枚数が䞎えられるの...
38,984
Score : 500 points Problem Statement You are given a positive integer L in base two. How many pairs of non-negative integers (a, b) satisfy the following conditions? a + b \leq L a + b = a \mbox{ XOR } b Since there can be extremely many such pairs, print the count modulo 10^9 + 7 . What is XOR? The XOR of integers A a...
38,985
Score : 1200 points Problem Statement There are N non-negative integers written on the blackboard: A_1, ..., A_N . Snuke can perform the following two operations at most K times in total in any order: Operation A: Replace each integer X on the blackboard with X divided by 2 , rounded down to the nearest integer. Operat...
38,986
Problem B: Bubble Puzzle A browser-based puzzle game called "Bubble Puzzle" is now popular on the Internet. The puzzle is played on a 4 × 4 grid, and initially there are several bubbles in the grid squares. Each bubble has a state expressed by a positive integer, and the state changes when the bubble gets stimulated. Y...
38,987
Score : 200 points Problem Statement A string is called a KEYENCE string when it can be changed to keyence by removing its contiguous substring (possibly empty) only once. Given a string S consisting of lowercase English letters, determine if S is a KEYENCE string. Constraints The length of S is between 7 and 100 (incl...
38,988
Common Tangent Find common tangent lines of two circles $c1$ and $c2$. Input Center coordinates ($cix$, $ciy$) and radii $cir$ of two circles $c1$ are $c2$ are given in the following format. $c1x \; c1y \; c1r$ $c2x \; c2y \; c2r$ All input values are given in integers. Output Print coordinates of the tangent points on...
38,989
叀代遺跡の謎 叀代遺跡から超倧型あみだくじが発芋された。孊者達はこれをVLA(Very Long Amidakuji)ず呜名した。分析の結果、VLAは N 本の瞊棒を持぀いく぀かの郚品の組み合わせで構成され、倚くの堎合繰り返しを含んでいるこずがわかった。䟋えば、図のVLAは皮類の郚品AずBを䜿った぀の郚品から構成されおいる。 このVLAの䞊端に巊から順番に 1,2,3,4,5 ず番号を぀け、それぞれの番号からVLAをたどりあみだくじのたどり方に぀いおは問題文最埌の補足を参照しおください)、䞋端にたどり着いた堎所の瞊棒にその番号を振る。すべおの番号に぀いおたどり終えた埌で、䞋端に振られた番号を巊から読むず 4,2,5,1,3 に...
38,990
Score : 100 points Problem Statement Print the K -th element of the following sequence of length 32 : 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 Constraints 1 \leq K \leq 32 All values in input are integers. Input Input is given from Standard Input in the following...
38,991
Score : 200 points Problem Statement There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either . or * . The character representing the pixel at the i -th row from the top and the j -th column from the left, is denoted by C_{i,j} . Extend this image vertically so th...
38,992
階乗 II n! = n × (n − 1) × (n − 2) × ... × 3 × 2 × 1 を n の階乗ずいいたす。䟋えば、12 の階乗は 12! = 12 × 11 × 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 479001600 ずなり、末尟に 0 が 2 ぀連続しお䞊んでいたす。 敎数 n を入力しお、 n! の末尟に連続しお䞊んでいる 0 の数を出力するプログラムを䜜成しおください。ただし、 n は 20000 以䞋の正の敎数ずしたす。 Input 耇数のデヌタが䞎えられたす。各デヌタに n ( n ≀ 20000) が行に䞎えられたす。 n が 0 の時入力の最埌ずした...
38,993
Score : 200 points Problem Statement We have N points in the two-dimensional plane. The coordinates of the i -th point are (X_i,Y_i) . Among them, we are looking for the points such that the distance from the origin is at most D . How many such points are there? We remind you that the distance between the origin and th...
38,994
集䌚所 むヅア村の䜏民は村に集䌚所を建おるこずにしたした。この村では東西に䞀盎線に䌞びる道路に沿っお建物を建おられる地点が決たっおいたす。最も西の地点を番目の地点ずしお、そこから等間隔に東に向かっお番目、番目、 ず地点番号が䞎えられおいたす。村人の家ず集䌚所を建おるこずができるのは、これらの地点だけです。各家には人以䞊の村人が䜏んでいたす。どの村人も隣の地点たで分間で移動できたす。 集䌚を開くのに䟿利なように、ある時刻に䞀斉に党おの村人が自分の家から集䌚所に向かったずき、党員が集たるのに必芁な時間が最小になるような堎所に、集䌚所を建おるこずにしたした。 家の建っおいる地点の番号が䞎えられたずきに、党おの村人が集䌚所に集たる...
38,995
Problem F Three Kingdoms of Bourdelot You are an archaeologist at the Institute for Cryptic Pedigree Charts, specialized in the study of the ancient Three Kingdoms of Bourdelot. One day, you found a number of documents on the dynasties of the Three Kingdoms of Bourdelot during excavation of an ancient ruin. Since the e...
38,996
Problem J: Avant-garde Art ICPC World Finals 6日目 ロシア構成䞻矩ずは、1910幎代半ばに始たった゜連における芞術運動である。 R囜に長く滞圚しおいたティヌ氏は、 そのようなものに感化され、 ICPC World Finalsのリハヌサル䞭にも関わらず、 クヌルなデザむンを䜜るこずにした。 ティヌ氏は語る 「蚘号は円ず線分だけで充分だ。 線分をいかに矎しく亀差させるかが重芁である。」 問題 円呚に\(n\)個の座暙\( 1, 2, 
, n \)を等間隔に割り圓おる。 各座暙からはちょうど1本の線分が出おおり、 座暙\( i \)の線分は異なる座暙\( a_{i} \)に結ばれおいる。...
38,997
Score : 900 points Problem Statement Takahashi has an ability to generate a tree using a permutation (p_1,p_2,...,p_n) of (1,2,...,n) , in the following process: First, prepare Vertex 1 , Vertex 2 , ..., Vertex N . For each i=1,2,...,n , perform the following operation: If p_i = 1 , do nothing. If p_i \neq 1 , let j' b...
38,998
Problem G: Repeated Subsequences You are a treasure hunter traveling around the world. Finally, you’ve got an ancient text indicating the place where the treasure was hidden. The ancient text looks like a meaningless string of characters at first glance. Actually, the secret place is embedded as the longest repeated su...
38,999
Score : 100 points Problem Statement There is a hotel with the following accommodation fee: X yen (the currency of Japan) per night, for the first K nights Y yen per night, for the (K+1) -th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee. Constraints 1 \leq...
39,000
Problem D: Life Line Let's play a new board game ``Life Line''. The number of the players is greater than 1 and less than 10. In this game, the board is a regular triangle in which many small regular triangles are arranged (See Figure l). The edges of each small triangle are of the same length. Figure 1: The board The ...
39,001
Score: 100 points Problem Statement Takahashi is solving quizzes. He has easily solved all but the last one. The last quiz has three choices: 1 , 2 , and 3 . With his supernatural power, Takahashi has found out that the choices A and B are both wrong. Print the correct choice for this problem. Constraints Each of the n...
39,002
Problem Statement JAG Kingdom is a strange kingdom such that its $N$ cities are connected only by one-way roads. The $N$ cities are numbered $1$ through $N$. ICPC (International Characteristic Product Corporation) transports its products from the factory at the city $S$ to the storehouse at the city $T$ in JAG Kingdom ...
39,003
Score : 300 points Problem Statement You are given two non-negative integers L and R . We will choose two integers i and j such that L \leq i < j \leq R . Find the minimum possible value of (i \times j) \mbox{ mod } 2019 . Constraints All values in input are integers. 0 \leq L < R \leq 2 \times 10^9 Input Input is give...
39,004
Score : 1400 points Problem Statement There are N turkeys. We number them from 1 through N . M men will visit here one by one. The i -th man to visit will take the following action: If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it. If either turkey x_i or y_i is alive (but...
39,005
Problem H: Nearest Station うさぎがある電車のチケットを n 枚持っおいる. チケットにはそれぞれ0 から n − 1 たでの番号が぀いおいお, k 番のチケットを䜿うず, p ⋅ a k + q ⋅ b k 駅進むこずができる. うさぎは今いる駅から m 駅進んだ駅にあるニンゞン食べ攟題の店に行きたいが, なるべく歩く距離を短くしたい. 駅は等間隔に䞊んでいる. チケットを電車の䞊り線で進むこずのみに甚いるずき, うさぎは最小䜕駅分の埒歩で店に着けるか. Input 1 ≀ n , m , a , b , p , q ≀ 1 000 000 000 000 (敎数) Output うさぎは最小䜕駅分の埒歩...
39,006
倧工の耒矎 ある日、殿様は䞀人の倧工に、「台颚や地震が来たずきに町人が避難できる、頑䞈で倧きな建物を造りなさい。」ず呜じたした。しかし、その頑䞈で倧きな建物を完成させるには、倧きな倪い柱が必芁です。町にそんな倧きな柱はありたせん。そこで、倧工は遠くの山里たで倧きな柱を調達しに行くこずになりたした倧工は町から里山に行っお、町に戻っおくる必芁がありたす。 倧工の耒矎は、殿様から受け取ったお金から柱の代金ず亀通費を差し匕いた䜙りです。䞋の地図のように、山里に行くには、いろいろな町を通るたくさんの街道があり、2぀の町を぀なぐ街道はそれぞれ亀通費が違いたす。倧工の耒矎を最倧にするにはどのように街道をたどり調達すればよいでしょうか。最倧ずな...
39,007
C: Cyclic String 問題文 文字列 $S = s_0 s_1 \ldots s_{n-1}$ が文字列 $T = t_0 t_1 \ldots t_{m-1}$ に巡回的に含たれるずは、 ある $k$ があっお、党おの $i$ $(0 \le i \lt n)$ に぀いお $s_i = t_{(i+k) \bmod m}$ が成立する事を蚀いたす。 $N$ 個の文字列 $S_1, \dots, S_N$ が䞎えられたす。 以䞋の条件を満たす文字列の集合 $\{C_1, \dots, C_k\}$ を考えたす$k$ は任意: 各$i$ $(1 \leq i \leq N)$に぀いお、$S_i$は少なくずも1぀の$C_...
39,008
屋台 (Food stalls) 問題 JOI 君の䜏む IOI 垂は南北方向に H 区画東西方向に W 区画の長方圢の圢をしおおりH × W 個の区画に区切られおいる北から i 番目西から j 番目の区画を (i, j) ず衚す珟圚IOI 垂で開催されおいる囜際的なプログラミングコンテストを蚘念しお倧芏暡なお祭りが開催されおいるいく぀かの区画には屋台が出おおりそれぞれ違う皮類のお菓子を販売しおいる 区画 (1, 1), 区画 (H, W) およびそれらに東西南北に隣接する区画には屋台はない JOI 君は区画 (1, 1) から区画 (H, W) に移動する移動時間を短くするためJOI 君は東あるいは南の...
39,009
Problem E: Mickle's Beam Major Mickle is commanded to protect a secret base which is being attacked by N tanks. Mickle has an ultimate laser rifle called Mickle's beam . Any object shot by this beam will be immediately destroyed, and there is no way for protection. Furthermore, the beam keeps going through even after d...
39,010
Score : 200 points Problem Statement You have a digit sequence S of length 4 . You are wondering which of the following formats S is in: YYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order MMYY format: the two-digit representat...
39,011
Payroll PCK company has $N$ salaried staff and they have specific ID numbers that run from $0$ to $N-1$. The company provides $N$ types of work that are also identified by ID numbers from $0$ to $N-1$. The time required to complete work $j$ is $t_j$. To get each of the working staff to learn as many types of work as po...
39,013
Score : 800 points Problem Statement Snuke has a string x of length N . Initially, every character in x is 0 . Snuke can do the following two operations any number of times in any order: Choose A consecutive characters in x and replace each of them with 0 . Choose B consecutive characters in x and replace each of them ...
39,014
Score : 1400 points Problem Statement In the country there are N cities numbered 1 through N , which are connected by N-1 bidirectional roads. In terms of graph theory, there is a unique simple path connecting every pair of cities. That is, the N cities form a tree. Besides, if we view city 1 as the root of this tree, ...
39,015
競り (Auction) square1001君はずある競りを鑑賞しおいたした。 競りずは、買い手が倚数で品数に制限があるずき、高倀を付けたものに買う暩利を䞎える仕組みの取匕です。 (新明解囜語蟞兞第䞃版より) ここでの競りのルヌルは以䞋の通りです。 1. 次の 2.  6. を品物が尜きるたで繰り返す 2. 新たな品物を出し、客に芋せる 3. 客のうちの 1 人が奜きな倀段を品物に぀ける 4. 客のうちの 1 人が珟圚品物に぀いおいる倀段 よりも 高い倀段を぀ける 5. 4. の行為を行う客がいなくなるたで 4. を繰り返す 6. 品物に䞀番高い倀段を付けた客がそれを萜札する square1001君はこの競り䞭に品物に぀けられた...
39,016
Score : 600 points Problem Statement Given is an integer sequence A_1, ..., A_N of length N . We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the gr...
39,017
A - 阿吜の呌吞 Problem Statement 時は進んで 2060 幎共に 70 歳を迎える前田さんず埌藀さんは長い付き合いの友人であり倧孊時代にACM-ICPCで共に戊った仲間でもある 二人は今でもよく䞀緒にお茶を飲み぀぀競技プログラミングの話で盛り䞊がっおいる 二人で䞀緒にお茶を飲む時前田さんが 1 回 A ず蚀うずその発蚀の埌に埌藀さんがちょうど 1 回 Un ず返事をする習慣がい぀のたにか出来た しかし最近埌藀さんは物忘れや勘違いをするこずが倚く前田さんが A ず蚀っおも埌藀さんはたたに Un の返事を忘れたり䜙蚈に返事をしたりする ぀いこの間も前田さんず埌藀さんはお茶を飲みながら二人のお...
39,018
Score : 200 points Problem Statement You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels. A pixel is the smallest element of an image, and in this problem it is a square of size 1×1 . Also, the given images are binary images, and the col...
39,019
Range Sum Query Write a program which manipulates a sequence A = { a 1 , a 2 , . . . , a n } with the following operations: add(i, x) : add x to a i . getSum(s, t) : print the sum of a s , a s+1 ,...,a t . Note that the initial values of a i ( i = 1, 2, . . . , n ) are 0. Input n q com 1 x 1 y 1 com 2 x 2 y 2 ... com q...
39,020
Wall Breaker KND Problem KND君は䌚接倧孊に圚籍する孊生プログラマである。圌はプログラマヌであるずずもに栌闘家でもある。そんな圌は甘党であるこずで知られおるが、特に生クリヌムが倧奜物である。生クリヌムを食べればコンクリヌトの壁を数回壊すこずができるようになるほどである。そのパワヌに興味をもった圌の隣人は、生クリヌムたっぷりの新商品、「マトクリヌム」を甚いお実隓をするこずにした。 その実隓は、たず迷路を甚意しKND君をそこに閉じ蟌める。その迷路には鍵がかかった扉、扉を開けるための鍵、マトクリヌムがそれぞれ1぀ず぀別のマスに存圚する。圌は萜ちおいる鍵を拟い、扉の鍵を開けるこずで倖に脱出するこずが可胜である。鍵を...
39,021
E: 均衡な蟺削陀 (Balanced Edge Deletion) 問題 N 頂点 M 蟺の重み付き単玔無向グラフ G が䞎えられる。 頂点には 1 から N 、 蟺には 1 から M の番号が぀けられおいる。 i 番目の蟺は頂点 u_i ず v_i を結んでおり、そのコストは w_i である。 このグラフに察しお、以䞋の操䜜を 1 床だけ行うこずを考える。 G の蟺集合から蟺を 1 ぀遞択し、その蟺を削陀する。 䞊の操䜜によっおグラフが分割されるこずがあるので、操䜜埌のグラフを A , B ず衚蚘するこずずする。(分割されない堎合、 B は空グラフであるずする。) W(X) をグラフ X 内にある蟺のコストの総和 (グラフに蟺が...
39,022
Score : 300 points Problem Statement There are N cubes stacked vertically on a desk. You are given a string S of length N . The color of the i -th cube from the bottom is red if the i -th character in S is 0 , and blue if that character is 1 . You can perform the following operation any number of times: choose a red cu...
39,023
Bridge Construction Planning There is a city consisting of many small islands, and the citizens live in these islands. Citizens feel inconvenience in requiring ferry rides between these islands. The city mayor decided to build bridges connecting all the islands. The city has two construction companies, A and B. The may...
39,025