task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Rank Checker 時は2020 幎。パ゜コン甲子園 2020 の予遞結果を保存したデヌタがありたす。このデヌタには、各チヌムに振られる敎理番号ず正解数が保存されおいたす。ここでは、正解数で順䜍を決定するものずし、正解数の倚いほうから順に 1 䜍、2 䜍 ... ず順䜍を぀けおいくこずずしたす。 予遞結果のデヌタず敎理番号をキヌボヌドから入力しお、その番号のチヌムの順䜍を出力するプログラムを䜜成しおください。 Input 入力デヌタは぀の郚分からなりたす。前半の郚分は、予遞結果のデヌタ、埌半の郚分は順䜍を知りたいチヌム番号の問い合わせです。予遞結果のデヌタの圢匏は以䞋の通りです。 p 1 , s 1 p 2 , s 2 ... ... 0 , 0 p i (1 ≀ p i ≀ 100 )、 s i (0 ≀ s i ≀ 30) はそれぞれ i チヌム目の敎理番号ず正解数を衚す敎数です。敎理番号ず正解数がずもに 0 のずきこのデヌタの入力が終わるものずしたす。 続いお埌半の問い合わせが耇数䞎えられたす。問い合わせの圢匏は以䞋の通りです。 q 1 q 2 : 各問い合わせは行に敎理番号 q i (1 ≀ q i ≀ 30) が䞎えられたす。これを入力の最埌たで凊理しお䞋さい。問い合わせの数は 100 を超えたせん。 Output 各問い合わせに぀いお、チヌムの順䜍を行に出力しお䞋さい。 Sample Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output for the Sample Input 2 2 3 3 Note 入力䟋のデヌタにおいお、チヌムを正解数順に敎列するず 3,30 1,20 2,20 6,20 4,10 5,10 ずなりたす。ここでは、正解数を基に順䜍を決定するため、30問正解チヌムを1䜍、20問正解チヌムを2䜍、10問正解チヌムを3䜍ずしたす䞊䜍のチヌム数を考慮し、10問正解チヌムを5䜍ずする通垞の順䜍付けずは異なるこずに泚意しお䞋さい。
36,605
Score : 400 points Problem Statement There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1 . He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10 , and K non-intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K] . Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r . When you are on Cell i , pick an integer d from S and move to Cell i + d . You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N , modulo 998244353 . Constraints 2 \leq N \leq 2 \times 10^5 1 \leq K \leq \min(N, 10) 1 \leq L_i \leq R_i \leq N [L_i, R_i] and [L_j, R_j] do not intersect ( i \neq j ) All values in input are integers. Input Input is given from Standard Input in the following format: N K L_1 R_1 L_2 R_2 : L_K R_K Output Print the number of ways for Tak to go from Cell 1 to Cell N , modulo 998244353 . Sample Input 1 5 2 1 1 3 4 Sample Output 1 4 The set S is the union of the segment [1, 1] and the segment [3, 4] , therefore S = \{ 1, 3, 4 \} holds. There are 4 possible ways to get to Cell 5 : 1 \to 2 \to 3 \to 4 \to 5 , 1 \to 2 \to 5 , 1 \to 4 \to 5 and 1 \to 5 . Sample Input 2 5 2 3 3 5 5 Sample Output 2 0 Because S = \{ 3, 5 \} holds, you cannot reach to Cell 5 . Print 0 . Sample Input 3 5 1 1 2 Sample Output 3 5 Sample Input 4 60 3 5 8 1 3 10 15 Sample Output 4 221823067 Note that you have to print the answer modulo 998244353 .
36,606
毒蛇の脱走(Snake Escaping) JOI 研究所では 2^L 匹の毒蛇を飌っおおりそれぞれ 0, 1, ..., 2^L - 1 の番号が付けられおいるすべおの毒蛇は頭から順に L 個の郚分に分かれおおりそれぞれの郚分は青たたは赀である毒蛇 i に察し i を2進衚蚘しお i = $\sum_{k=1}^{L}$ c_k2^{L-k} (0 \leq c_k \leq 1) ずおいたずき c_k = 0 であれば毒蛇 i の頭から数えお k 番目の郚分は青であり c_k = 1 であれば毒蛇 i の頭から数えお k 番目の郚分は赀である 各毒蛇には毒性ず呌ばれる0 以䞊9 以䞋の敎数倀が定たっおいる 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 からなる長さ 2^L の文字列 S が䞎えられその i 文字目( 1 \leq i \leq 2^L ) は毒蛇 i - 1 の毒性を衚す 毒蛇たちの動きは玠早いのでJOI 研究所からはよく毒蛇たちが脱走しおしたうJOI 研究所には脱走した毒蛇を目撃した呚蟺䜏民から苊情が寄せられる あなたには Q 日間にわたる苊情の情報が䞎えられる d 日目( 1 \leq d \leq Q ) に寄せられた苊情は 0 , 1 , ? からなる長さ L の文字列 T_d ずしお衚され T_d の j 文字目( 1 \leq j \leq L ) が 0 の堎合は d 日目に脱走したすべおの毒蛇の頭から数えお j 番目の郚分が青であるこずを衚し T_d の j 文字目( 1 \leq j \leq L ) が 1 の堎合は d 日目に脱走したすべおの毒蛇の頭から数えお j 番目の郚分が赀であるこずを衚し T_d の j 文字目( 1 \leq j \leq L ) が ? の堎合は d 日目に脱走した毒蛇の頭から数えお j 番目の郚分に぀いおは呚蟺䜏民からは情報が䞎えられなかったこずを衚す 苊情はすべお正確な情報である脱走した毒蛇はJOI 研究所の職員がその日のうちに捕獲する捕獲された毒蛇が翌日以降に再び脱走するこずはあり埗る 毒蛇の脱走によるリスクを芋積もるためにJOI 研究所のK 理事長は脱走した可胜性のある毒蛇の毒性の合蚈を知りたいあなたの仕事は Q 日間にわたる苊情の情報からそれぞれの日ごずにその日に脱走した可胜性のある毒蛇の毒性の合蚈を求めるプログラムを䜜成するこずである 課題 毒蛇の毒性を衚す文字列 S ず Q 日間の苊情の情報が䞎えられるのでそれぞれの日ごずにその日に脱走した可胜性のある毒蛇の毒性の合蚈を求めるプログラムを䜜成せよ メモリ制限が小さいこずに泚意するこず 入力 暙準入力から以䞋の入力を読み蟌め 1 行目には敎数 L, Q が空癜を区切りずしお曞かれおいるこれらは順に毒蛇の郚分の個数ず苊情の寄せられる日数を衚す 2 行目には長さ 2^L の文字列 S が曞かれおいるこの文字列は毒蛇の毒性を衚す 続く Q 行のうちの d 行目( 1 \leq d \leq Q ) には長さ L の文字列 T_d が曞かれおいるこの文字列は d 日目の苊情を衚す 出力 暙準出力に Q 行で出力せよ d 行目には d 日目に脱走した可胜性のある毒蛇の毒性の合蚈を衚す敎数を出力せよ 制限 すべおの入力デヌタは以䞋の条件を満たす 1 \leq L \leq 20  1 \leq Q \leq 1 000 000  S は長さ 2^L の文字列である 文字列 S は 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 からなる T_d は長さ L の文字列である( 1 \leq d \leq Q ) 文字列 T_d は 0 , 1 , ? からなる( 1 \leq d \leq Q ) 入出力䟋 入力䟋1 3 5 12345678 000 0?? 1?0 ?11 ??? 出力䟋1 1 10 12 12 36 この入力䟋では L = 3 である3 ぀の郚分に分かれた毒蛇が党郚で 2^3 = 8 匹いる苊情は5 日間にわたっお寄せられる 1 日目に脱走した可胜性のある毒蛇は毒蛇0 のみである毒性の合蚈は1 である 2 日目に脱走した可胜性のある毒蛇は毒蛇0, 1, 2, 3 である毒性の合蚈は10 である 3 日目に脱走した可胜性のある毒蛇は毒蛇4, 6 である毒性の合蚈は12 である 4 日目に脱走した可胜性のある毒蛇は毒蛇3, 7 である毒性の合蚈は12 である 5 日目に脱走した可胜性のある毒蛇は毒蛇0, 1, 2, 3, 4, 5, 6, 7 である毒性の合蚈は36 である 入力䟋2 4 8 3141592653589793 0101 ?01? ??1? ?0?? 1?00 01?1 ??10 ???? 出力䟋2 9 18 38 30 14 15 20 80 情報オリンピック日本委員䌚䜜 『第17 回日本情報オリンピック(JOI 2017/2018) 本遞』
36,607
Problem I: Making Pairs Problem 本日、぀いに完党招埅制の高玚レストラン「マむヅレストラン」がオヌプンした。新たな䌚員を招埅する暩利を持぀のはこのレストランの䌚員のみで、最初、䌚員は䌚員番号0であるレストランのオヌナヌのみである。 マむヅレストランはその高玚さ故、オヌプン初日から$N$日間しか開かれない。その期間䞭、毎日䌚員のうち誰か䞀人が、自分の友人を䞀人だけ新たに䌚員ずしお招埅する。$i$日目に招埅された䌚員には䌚員番号$i$が割り圓おられ、その䌚員は招埅された日を含めそれ以降毎日来店する。 このレストランには二人甚テヌブルしか存圚しないので、䌚員の人々はできるだけペアでテヌブルを䜿甚しお食事をする。食事にはオヌナヌも参加するので、他の䌚員はオヌナヌずペアを組むこずもできる。しかし、䌚員の人々は皆人芋知りであり、自分を招埅した友人か、自分が招埅した友人ずしかペアを組みたがらない。各䌚員はもし友人ずペアを組めなかった堎合、䞀人寂しく食事をする。 $N$日間の各日に぀いお、友人どうしのペアの数が最倧ずなるようにペアを組んだずき、いく぀のペアができるか求めよ。 Input 入力は以䞋の圢匏で䞎えられる。 $N$ $p_1$ $p_2$ ... $p_N$ 1行目にレストランが開かれる日数$N$が䞎えられる。 続く$N$行に、䌚員番号が$i$の䌚員を招埅した䌚員の䌚員番号$p_i$が䞎えられる。 Constraints 入力は以䞋の条件を満たす。 $1 \leq N \leq 5000$ $0 \leq p_i \leq i-1$ ($1 \leq i \leq N$) $N$, $p_i$は敎数 Output 出力は$N$行からなる。 $i$行目には、$i$日目に䜜るこずのできる友人どうしのペアの最倧数を出力する。 ($1 \leq i \leq N$) Sample Input 1 3 0 0 2 Sample Output 1 1 1 2 Sample Input 2 5 0 1 2 3 4 Sample Output 2 1 1 2 2 3
36,608
リヌグ戊のスコアシヌト スポヌツの倧䌚にはリヌグ戊ずトヌナメント戊がありたす。サッカヌのリヌグ戊では勝・負・匕分にそれぞれ点数を付け、その勝ち点で順䜍を競いたす。勝ち点はそれぞれ勝(3点)、負(0点)、匕分(1点)です。 チヌム数ずリヌグ戊の成瞟を入力ずし、成瞟の良い順(勝ち点の倚い順)に䞊べ替え、チヌム名ず勝ち点を出力するプログラムを䜜成しおください。勝ち点が同点の堎合は入力順に出力しおください。 Input 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 n name 1 w 1 l 1 d 1 name 2 w 2 l 2 d 2 : name n w n l n d n 行目にチヌム数 n ( n ≀ 10) が䞎えられたす。続く n 行にチヌム i の名前 name i (20文字以内のアルファベット)、勝の数 w i 、負の数 l i 、匕分の数 d i (0 ≀ w i , l i , d i ≀ 9) が空癜区切りで䞎えられたす。 チヌム数が 0 のずき、入力の終了ずしたす。デヌタセットの数は 50 を超えたせん。 Output デヌタセットごずに、䞊べ替えたチヌムのリストを出力しおください。 i 行目に i 番目のチヌムの名前ず勝ち点をカンマで区切っお出力しおください。 デヌタセットの間に぀の空行を入れおください。 Sample Input 4 Japan 1 0 2 Egypt 1 2 0 Canada 0 2 1 Spain 2 0 1 3 India 0 2 0 Poland 1 0 1 Italy 1 0 1 0 Output for the Sample Input Spain,7 Japan,5 Egypt,3 Canada,1 Poland,4 Italy,4 India,0
36,609
Problem G: Camera Control "ACM48" is one of the most popular dance vocal units in Japan. In this winter, ACM48 is planning a world concert tour. You joined the tour as a camera engineer. Your role is to develop software which controls the camera on a stage. For simplicity you can regard the stage as 2-dimensional space. You can rotate the camera to an arbitrary direction by the software but cannot change its coordinate. During a stage performance, each member of ACM48 moves along her route and sings the part(s) assigned to her. Here, a route is given as a polygonal line. You have to keep focusing the camera on a member during a stage performance. You can change the member focused by the camera if and only if the current and next members are in the same direction from the camera. Your task is to write a program which reads the stage performance plan and calculates the maximum time that you can focus the camera on members that are singing. You may assume the following are satisfied: You can focus the camera on an arbitrary member at the beginning time. Each route of the member does not touch the camera. Each member stays at the last coordinates after she reaches there. Input The input contains multiple test cases. Each test case has the following format: N c x c y The information of the 1-st member . . . The information of the N -th member N (1 ≀ N ≀ 50) is the number of the members. ( c x , c y ) is the coordinates of the camera. Then the information of the N members follow. The information of the i -th member has the following format: M i x i ,1 y i ,1 t i ,1 . . . x i , M i y i , M i t i , M i L i b i ,1 e i ,1 . . . b i , L i e i , L i M i (1 ≀ M i ≀ 100) is the number of the points in the route. ( x i,j , y i,j ) is the coordinates of the j -th in the route. t i,j (0 = t i ,0 < t i , j < t i , j +1 ≀ 10 3 for 0 < j ) is the time that the i -th member reaches the j -th coordinates. L i (0 ≀ L i ≀ 100) is the number of the vocal part. b i,k and e i,k (0 ≀ b i,k < e i,k < b i , k +1 < e i , k +1 ≀ 10 3 ) are the beginning and the ending time of the k -th vocal part, respectively. All the input values are integers. You may assume that the absolute of all the coordinates are not more than 10 3 . N = 0 denotes the end of the input. You may not process this as a test case. Output For each dataset, print the maximum time that you can focus the camera on singing members with an absolute error of at most 10 -6 . You may output any number of digits after the decimal point. Sample Input 2 0 0 2 -5 5 0 5 5 10 1 0 6 2 5 5 0 -5 5 10 1 6 10 1 7 -65 2 -65 10 0 65 1 3 2 0 1 23 24 2 0 0 2 100 10 0 -10 10 10 5 0 1 2 3 4 5 6 7 8 9 2 10 0 0 0 10 10 5 1 2 3 4 5 6 7 8 9 10 0 Output for the Sample Input 9.00000000 2.00000000 5.98862017
36,610
Score : 800 points Problem Statement There is a tree with N vertices numbered 1 through N . The i -th edge connects Vertex x_i and y_i . Each vertex is painted white or black. The initial color of Vertex i is represented by a letter c_i . c_i = W represents the vertex is white; c_i = B represents the vertex is black. A cat will walk along this tree. More specifically, she performs one of the following in one second repeatedly: Choose a vertex that is adjacent to the vertex where she is currently, and move to that vertex. Then, invert the color of the destination vertex. Invert the color of the vertex where she is currently. The cat's objective is to paint all the vertices black. She may start and end performing actions at any vertex. At least how many seconds does it takes for the cat to achieve her objective? Constraints 1 ≀ N ≀ 10^5 1 ≀ x_i,y_i ≀ N ( 1 ≀ i ≀ N-1 ) The given graph is a tree. c_i = W or c_i = B . Input Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_{N-1} y_{N-1} c_1c_2..c_N Output Print the minimum number of seconds required to achieve the objective. Sample Input 1 5 1 2 2 3 2 4 4 5 WBBWW Sample Output 1 5 The objective can be achieved in five seconds, for example, as follows: Start at Vertex 1 . Change the color of Vertex 1 to black. Move to Vertex 2 , then change the color of Vertex 2 to white. Change the color of Vertex 2 to black. Move to Vertex 4 , then change the color of Vertex 4 to black. Move to Vertex 5 , then change the color of Vertex 5 to black. Sample Input 2 6 3 1 4 5 2 6 6 1 3 4 WWBWBB Sample Output 2 7 Sample Input 3 1 B Sample Output 3 0 Sample Input 4 20 2 19 5 13 6 4 15 6 12 19 13 19 3 11 8 3 3 20 16 13 7 14 3 17 7 8 10 20 11 9 8 18 8 2 10 1 6 13 WBWBWBBWWWBBWWBBBBBW Sample Output 4 21
36,611
Problem A: The Balance Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights. You are asked to help her by calculating how many weights are required. Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights Input The input is a sequence of datasets. A dataset is a line containing three positive integers a , b , and d separated by a space. The following relations hold: a ≠ b , a ≀ 10000, b ≀ 10000, and d ≀ 50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider “no solution” cases. The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset. Output The output should be composed of lines, each corresponding to an input dataset ( a , b , d ). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions. You can measure d mg using x many a mg weights and y many b mg weights. The total number of weights ( x + y ) is the smallest among those pairs of nonnegative integers satisfying the previous condition. The total mass of weights ( ax + by ) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions. No extra characters (e.g. extra spaces) should appear in the output. Sample Input 700 300 200 500 200 300 500 200 500 275 110 330 275 110 385 648 375 4002 3 1 10000 0 0 0 Output for the Sample Input 1 3 1 1 1 0 0 3 1 1 49 74 3333 1
36,612
Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices. Each node in the game has an evaluation value which shows how good a situation is. This value is the same as maximum value of child nodes’ values multiplied by -1. Values on leaf nodes are evaluated with Ciel’s special function -- which is a bit heavy. So, she will use alpha-beta pruning for getting root node’s evaluation value to decrease the number of leaf nodes to be calculated. By the way, changing evaluation order of child nodes affects the number of calculation on the leaf nodes. Therefore, Ciel wants to know the minimum and maximum number of times to calculate in leaf nodes when she could evaluate child node in arbitrary order. She asked you to calculate minimum evaluation number of times and maximum evaluation number of times in leaf nodes. Ciel uses following algotithm: function negamax(node, α, β) if node is a terminal node return value of leaf node else foreach child of node val := -negamax(child, -β, -α) if val >= β return val if val > α α := val return α [NOTE] negamax algorithm Input Input follows following format: n p_1 p_2 ... p_n k_1 t_{11} t_{12} ... t_{1k} : : k_n t_{n1} t_{n2} ... t_{nk} The first line contains an integer n , which means the number of vertices in game tree T. The second line contains n integers p_i , which means the evaluation value of vertex i . Then, next n lines which contain the information of game tree T. k_i is the number of child nodes of vertex i , and t_{ij} is the indices of the child node of vertex i . Input follows following constraints: 2 \leq n \leq 100 -10,000 \leq p_i \leq 10,000 0 \leq k_i \leq 5 2 \leq t_{ij} \leq n Index of root node is 1 . Evaluation value except leaf node is always 0 . This does not mean the evaluation values of non-leaf nodes are 0 . You have to calculate them if necessary. Leaf node sometimes have evaluation value of 0 . Game tree T is tree structure. Output Print the minimum evaluation number of times and the maximum evaluation number of times in leaf node. Please separated by whitespace between minimum and maximum. minimum maximum Sample Input 1 3 0 1 1 2 2 3 0 0 Output for the Sample Input 1 2 2 Sample Input 2 8 0 0 100 100 0 -100 -100 -100 2 2 5 2 3 4 0 0 3 6 7 8 0 0 0 Output for the Sample Input 2 3 5 Sample Input 3 8 0 0 100 100 0 100 100 100 2 2 5 2 3 4 0 0 3 6 7 8 0 0 0 Output for the Sample Input 3 3 4 Sample Input 4 19 0 100 0 100 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 2 2 3 0 2 4 5 0 3 6 7 8 3 9 10 11 3 12 13 14 3 15 16 17 2 18 19 0 0 0 0 0 0 0 0 0 0 Output for the Sample Input 4 7 12
36,613
Score : 900 points Problem Statement Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are? Constraints 1 ≀ A ≀ B < 2^{60} A and B are integers. Input The input is given from Standard Input in the following format: A B Output Print the number of possible candidates of the value of Nukes's integer. Sample Input 1 7 9 Sample Output 1 4 In this case, A=7 and B=9 . There are four integers that can be represented as the bitwise OR of a non-empty subset of { 7 , 8 , 9 }: 7 , 8 , 9 and 15 . Sample Input 2 65 98 Sample Output 2 63 Sample Input 3 271828182845904523 314159265358979323 Sample Output 3 68833183630578410
36,614
Score : 500 points Problem Statement You are given a tree with N vertices 1,2,\ldots,N , and positive integers c_1,c_2,\ldots,c_N . The i -th edge in the tree (1 \leq i \leq N-1) connects Vertex a_i and Vertex b_i . We will write a positive integer on each vertex in T and calculate our score as follows: On each edge, write the smaller of the integers written on the two endpoints. Let our score be the sum of the integers written on all the edges. Find the maximum possible score when we write each of c_1,c_2,\ldots,c_N on one vertex in T , and show one way to achieve it. If an integer occurs multiple times in c_1,c_2,\ldots,c_N , we must use it that number of times. Constraints 1 \leq N \leq 10000 1 \leq a_i,b_i \leq N 1 \leq c_i \leq 10^5 The given graph is a tree. Input Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1} c_1 \ldots c_N Output Use the following format: M d_1 \ldots d_N where M is the maximum possible score, and d_i is the integer to write on Vertex i . d_1,d_2,\ldots,d_N must be a permutation of c_1,c_2,\ldots,c_N . If there are multiple ways to achieve the maximum score, any of them will be accepted. Sample Input 1 5 1 2 2 3 3 4 4 5 1 2 3 4 5 Sample Output 1 10 1 2 3 4 5 If we write 1,2,3,4,5 on Vertex 1,2,3,4,5 , respectively, the integers written on the four edges will be 1,2,3,4 , for the score of 10 . This is the maximum possible score. Sample Input 2 5 1 2 1 3 1 4 1 5 3141 59 26 53 59 Sample Output 2 197 59 26 3141 59 53 c_1,c_2,\ldots,c_N may not be pairwise distinct.
36,615
Score : 400 points Problem Statement We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i -th query, given two odd numbers l_i and r_i , find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i . Constraints 1≀Q≀10^5 1≀l_i≀r_i≀10^5 l_i and r_i are odd. All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i -th line (1≀i≀Q) should contain the response to the i -th query. Sample Input 1 1 3 7 Sample Output 1 2 3 is similar to 2017, since both 3 and (3+1)/2=2 are prime. 5 is similar to 2017, since both 5 and (5+1)/2=3 are prime. 7 is not similar to 2017, since (7+1)/2=4 is not prime, although 7 is prime. Thus, the response to the first query should be 2 . Sample Input 2 4 13 13 7 11 7 11 2017 2017 Sample Output 2 1 0 0 1 Note that 2017 is also similar to 2017. Sample Input 3 6 1 53 13 91 37 55 19 51 73 91 13 49 Sample Output 3 4 4 1 1 1 2
36,616
Score : 1500 points Problem Statement Given are an integer K and integers a_1,\dots, a_K . Determine whether a sequence P satisfying below exists. If it exists, find the lexicographically smallest such sequence. Every term in P is an integer between 1 and K (inclusive). For each i=1,\dots, K , P contains a_i occurrences of i . For each term in P , there is a contiguous subsequence of length K that contains that term and is a permutation of 1,\dots, K . Constraints 1 \leq K \leq 100 1 \leq a_i \leq 1000 \quad (1\leq i\leq K) a_1 + \dots + a_K\leq 1000 All values in input are integers. Input Input is given from Standard Input in the following format: K a_1 a_2 \dots a_K Output If there is no sequence satisfying the conditions, print -1 . Otherwise, print the lexicographically smallest sequence satisfying the conditions. Sample Input 1 3 2 4 3 Sample Output 1 2 1 3 2 2 3 1 2 3 For example, the fifth term, which is 2 , is in the subsequence (2, 3, 1) composed of the fifth, sixth, and seventh terms. Sample Input 2 4 3 2 3 2 Sample Output 2 1 2 3 4 1 3 1 2 4 3 Sample Input 3 5 3 1 4 1 5 Sample Output 3 -1
36,617
C: 今川焌きマン - Imagawayaki Man - 物語 今川焌きマンは、正矩のヒヌロヌである。顔は盎埄 1 メヌトルの今川焌き䞻に小麊粉でできた生地の䞭にたっぷりず逡を詰めお焌いた食べ物であり、芋た目は円圢であり、矎味しい。北海道では、単に「お焌き」ず呌ばれるこずも倚い。逡ずしお小豆逡のほかに、カスタヌドクリヌムなどを甚いるこずもあり、さたざたな味のバリ゚ヌションがある。そのため、いく぀食べおも飜きない。小豆逡やカスタヌドクリヌムのほかに、抹茶逡やりんごゞャムなども矎味しい。䞭にタコを入れたたこ焌きのようなものもあるようだ。どの味も矎味しい。䞋の写真は暙準的な今川焌きである。巊はクリヌム逡、右は小豆逡が入っおいる。矎味しそうである。実際に食べお芋たずころ、やはり矎味しかった。ずころで、今川焌きの盎埄は通垞 10 センチメヌトル皋床であるので、盎埄 1 メヌトルの今川焌きはかなり倧きなものであるこずに泚意されよ。でできおおり、お腹の空いた者に自分の顔を分けお差し出すこずもある。そのため、必芁に応じお顔を取り替える必芁がある。い぀でも取り替えられるように、今川焌き工堎でおじさんが䞀人でせっせず䞀぀ず぀今川焌きを焌いお日々備えおいる。 ずころで、今川焌きは食品であるため、圓然ながら賞味期限が存圚する。無駄にしないためには、焌いおから時間が経ったものから順に䜿うこずが望たしい。おじさんは䞋図のように、完成した盎埄 1 メヌトルの今川焌き (図䞭の狐色郚) を幅 1 メヌトルのレヌン (図䞭の灰色郚) の䞊に隙間なく䞊べお保存しおいる。 ある日、倧悪党の背筋マンが工堎に珟れ、今川焌きマンを困らせようず、自慢の背筋力を䜿っお巚倧な今川焌きをせっせず運び、奜き勝手に䞊び替えおしたった。背筋マンは背筋力だけでなく蚘憶力も良いので、どの今川焌きが元々䜕番目にあったのか芚えおいるようだ。負けを認めたくない今川焌きマンは、䜕ずかしお、それぞれの今川焌きが䜕番目に出来たおなのか知りたいが、芋た目では分かりそうにない。そこで、背筋マンに「もちろん、僕はちゃんず芚えおいるよ。でも、背筋マンは本圓にちゃんず芚えおいるのかな」ず挑発し、さらに「本圓に芚えおいるか僕がテストするよ」ず蚀っお質問を繰り返すこずで、䜕番目に出来たおなのか知るこずにした。ただし、あたり質問しすぎるず、探っおいるこずを勘付かれおしたうので、ほどほどにしなければならない。あなたには、今川焌きマンを助けるため、質問を繰り返し生成し、それぞれの今川焌きが䜕番目に出来たおなのかを圓おるプログラムを䜜成しおほしい。 問題 たず、工堎に䞊んでいる今川焌きの個数 N ( 1 \leq N \leq 10,000 ) が暙準入力により1行で䞎えられる。これらの今川焌きの補造日時は互いに異なる。぀たり、 1 \leq i \leq N を満たす任意の敎数 i に぀いお、 i 番目に出来たおの今川焌きはただひず぀存圚する。 これ以降、任意の2敎数 a , b ( 1 \leq a, b \leq N ) においお、暙準出力に ? a b ず出力するず、「 a 番目に出来たおの今川焌きの䞭心から b 番目に出来たおの今川焌きの䞭心たでの距離は䜕メヌトルか」ずいう質問を行うこずができる。この答えは暙準入力に䞀行で敎数ずしおすぐに䞎えられる。物語でも述べた通り、レヌン䞊に隙間なく盎埄 1 メヌトルの今川焌きが䞊べられおいるので、巊から数えお i 番目の今川焌きの䞭心から j 番目の今川焌きの䞭心たでの距離は正確に |i - j| メヌトルである。この質問は 20,000 回たで繰り返し行うこずができる。 それぞれの今川焌きが䜕番目に出来たおなのか分かったら、暙準出力に最終的な答えを出力しなければならない。出力圢匏は、各 i ( 1 \leq i \leq N ) においお、巊から i 番目 の今川焌きが x_i 番目に出来たおのずき、 ! x_1 x_2 x_3 ... x_N たたは、 ! x_N x_{N-1} x_{N-2} ... x_1 ずすればよい。぀たり、巊から順に答えおも、右から順に答えおも構わない。この最終的な解答は、1床しか行うこずができない。この解答が正しい出力だったずき、正答ずみなす。 暙準出力を行う毎に、ストリヌムをフラッシュ (flush) する必芁があるこずに泚意されよ。䞻芁な蚀語でのフラッシュ䟋を以䞋に瀺す。もちろん、これ以倖の方法でフラッシュを行っおも構わない。 C 蚀語: #include <stdio.h> fflush(stdout); C++: #include <iostream> std::cout.flush(); Java: System.out.flush(); 入出力䟋 暙準入力 暙準出力 3 ? 1 2 2 ? 2 3 1 ? 1 3 1 ! 2 3 1
36,619
Search I You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given. Output Print C in a line. Constraints n ≀ 10000 q ≀ 500 0 ≀ an element in S ≀ 10 9 0 ≀ an element in T ≀ 10 9 Sample Input 1 5 1 2 3 4 5 3 3 4 1 Sample Output 1 3 Sample Input 2 3 3 1 2 1 5 Sample Output 2 0 Sample Input 3 5 1 1 2 2 3 2 1 2 Sample Output 3 2 Notes
36,620
Maximum Heap A binary heap which satisfies max-heap property is called max-heap. In a max-heap, for every node $i$ other than the root, $A[i] \leq A[parent(i)]$, that is, the value of a node is at most the value of its parent. The largest element in a max-heap is stored at the root, and the subtree rooted at a node contains values no larger than that contained at the node itself. Here is an example of a max-heap. Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code. $maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap. 1 maxHeapify(A, i) 2 l = left(i) 3 r = right(i) 4 // select the node which has the maximum value 5 if l ≀ H and A[l] > A[i] 6 largest = l 7 else 8 largest = i 9 if r ≀ H and A[r] > A[largest] 10 largest = r 11 12 if largest ≠ i // value of children is larger than that of i 13 swap A[i] and A[largest] 14 maxHeapify(A, largest) // call recursively The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner. 1 buildMaxHeap(A) 2 for i = H/2 downto 1 3 maxHeapify(A, i) Input In the first line, an integer $H$ is given. In the second line, $H$ integers which represent elements in the binary heap are given in order of node id (from $1$ to $H$). Output Print values of nodes in the max-heap in order of their id (from $1$ to $H$). Print a single space character before each value. Constraint $1 \leq H \leq 500,000$ $-2,000,000,000 \leq$ value of a node $\leq 2,000,000,000$ Sample Input 1 10 4 1 3 2 16 9 10 14 8 7 Sample Output 1 16 14 10 8 7 9 3 2 4 1 Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
36,621
Score: 200 points Problem Statement You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria. According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied: All even numbers written on the document are divisible by 3 or 5 . If the immigrant should be allowed entry according to the regulation, output APPROVED ; otherwise, print DENIED . Notes The condition in the statement can be rephrased as "If x is an even number written on the document, x is divisible by 3 or 5 ". Here " if " and " or " are logical terms. Constraints All values in input are integers. 1 \leq N \leq 100 1 \leq A_i \leq 1000 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output If the immigrant should be allowed entry according to the regulation, print APPROVED ; otherwise, print DENIED . Sample Input 1 5 6 7 9 10 31 Sample Output 1 APPROVED The even numbers written on the document are 6 and 10 . All of them are divisible by 3 or 5 , so the immigrant should be allowed entry. Sample Input 2 3 28 27 24 Sample Output 2 DENIED 28 violates the condition, so the immigrant should not be allowed entry.
36,622
Score : 100 points Problem Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "A x C". Here, x is the uppercase English letter at the beginning of s . Given the name of the contest, print the abbreviation of the name. Constraints The length of s is between 1 and 100 , inclusive. The first character in s is an uppercase English letter. The second and subsequent characters in s are lowercase English letters. Input The input is given from Standard Input in the following format: AtCoder s Contest Output Print the abbreviation of the name of the contest. Sample Input 1 AtCoder Beginner Contest Sample Output 1 ABC The contest in which you are participating now. Sample Input 2 AtCoder Snuke Contest Sample Output 2 ASC This contest does not actually exist. Sample Input 3 AtCoder X Contest Sample Output 3 AXC
36,623
Knapsack Problem with Limitations II You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$. You want to find a subset of items to put such that: The total value of the items is as large as possible. The items have combined weight at most $W$, that is capacity of the knapsack. You can select at most $m_i$ items for $i$-th item. Find the maximum total value of items in the knapsack. Input $N$ $W$ $v_1$ $w_1$ $m_1$ $v_2$ $w_2$ $m_2$ : $v_N$ $w_N$ $m_N$ The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given. Output Print the maximum total values of the items in a line. Constraints $1 \le N \le 50$ $1 \le v_i \le 50$ $1 \le w_i \le 10^9$ $1 \le m_i \le 10^9$ $1 \le W \le 10^9$ Sample Input 1 4 8 4 3 2 2 1 1 1 2 4 3 2 2 Sample Output 1 12 Sample Input 2 2 100 1 1 100 2 1 50 Sample Output 2 150 Sample Input 3 5 1000000000 3 5 1000000000 7 6 1000000000 4 4 1000000000 6 8 1000000000 2 5 1000000000 Sample Output 3 1166666666
36,624
Score : 1000 points Problem Statement Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N , and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i . Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: If there is a marble on Vertex 0 , move the marble into the box. Move each marble from the vertex to its parent (all at once). For each vertex occupied by two or more marbles, remove all the marbles from the vertex. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play , and compute the sum of all those numbers modulo 1,000,000,007 . Constraints 1 \leq N < 2 \times 10^{5} 0 \leq p_i < i Partial Scores In the test set worth 400 points, N < 2{,}000 . Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Sample Input 1 2 0 0 Sample Output 1 8 When we place a marble on both Vertex 1 and 2 , there will be multiple marbles on Vertex 0 by step 2. In such a case, these marbles will be removed instead of being moved to the box. Sample Input 2 5 0 1 1 0 4 Sample Output 2 96 Sample Input 3 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Sample Output 3 730395550 Be sure to compute the sum modulo 1,000,000,007 .
36,625
Score : 100 points Problem Statement There are N items, numbered 1, 2, \ldots, N . For each i ( 1 \leq i \leq N ), Item i has a weight of w_i and a value of v_i . Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W , which means that the sum of the weights of items taken must be at most W . Find the maximum possible sum of the values of items that Taro takes home. Constraints All values in input are integers. 1 \leq N \leq 100 1 \leq W \leq 10^5 1 \leq w_i \leq W 1 \leq v_i \leq 10^9 Input Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N Output Print the maximum possible sum of the values of items that Taro takes home. Sample Input 1 3 8 3 30 4 50 5 60 Sample Output 1 90 Items 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8 , and the sum of the values is 30 + 60 = 90 . Sample Input 2 5 5 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 Sample Output 2 5000000000 The answer may not fit into a 32-bit integer type. Sample Input 3 6 15 6 5 5 6 6 4 6 6 3 5 7 2 Sample Output 3 17 Items 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 = 14 , and the sum of the values is 6 + 6 + 5 = 17 .
36,626
平面䞊の図圢 瞊 8、暪 8 のマスからなる図 1 のような平面がありたす。 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ 図 この平面䞊に、以䞋の A から G の図圢のどれかが䞀぀だけ眮かれおいたす。 A ■ ■ ■ ■ B ■ ■ ■ ■ C ■ ■ ■ ■ D ■ ■ ■ ■ E ■ ■ ■ ■ F ■ ■ ■ ■ G ■ ■ ■ ■ たずえば、次の図 2 の䟋では E の図圢が眮かれおいたす。 □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ ■ ■ □ □ □ □ □ □ □ ■ ■ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ □ 図 平面の䞭で図圢が占めおいるマスを 1、占めおいないマスを 0 で衚珟した数字の列を読み蟌んで、眮かれおいる図圢の皮類A〜Gを出力するプログラムを䜜成しおください。 ただし、ひず぀の平面に眮かれおいる図圢は必ず぀で、耇数の図圢が眮かれおいるこずはありたせん。たた、A〜G で衚される図圢以倖のものが眮かれおいるこずはありたせん。 Input 入力は耇数のデヌタセットからなりたす。 ぀のデヌタセットずしお、平面の䞭で図圢が占めおいるマスを 1、占めおいないマスを 0 で衚珟した 8 文字からなる 8 ぀の文字列が䞎えられたす。䟋えば、図 2 に察応する文字列の䞊びは次のようになりたす。 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 デヌタセットの間は぀の空行で区切られおいたす。デヌタセットの数は 50 を超えたせん。 Output 各デヌタセットごずに、平面に䞎えられた図圢の皮類A〜G のいずれかを行に出力しおください。 Sample Input 00000000 00000000 01100000 00110000 00000000 00000000 00000000 00000000 00011110 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00110000 00110000 00000000 00000000 00000000 00000000 Output for the Sample Input E C A
36,628
レシヌト 問題 倪郎君は10冊の本を賌入した 埌日 レシヌトをもずに䟡栌を調べようずしたが レシヌトには汚れがあり ある本の䟡栌が読み取れなかった その本の䟡栌を 10冊の総額ず他の9冊の䟡栌から蚈算するこずにした 䟡栌が読み取れなかった本の䟡栌を出力するプログラムを曞け なお本の䟡栌はすべお正の敎数である たた消費皎を考慮する必芁はない 入力 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる 各デヌタセットは10行からなり1行に1぀ず぀正の敎数が曞かれおいる 1行目の敎数は10冊の総額を 2行目から10行目の敎数は読み取れた䟡栌を衚しおいる なお10冊の総額は10000以䞋である 総額 が 0 のずき入力の終了を瀺す.デヌタセットの数は 5 を超えない 出力 デヌタセットごずに䟡栌が読み取れなかった本の䟡栌を1 行に出力する 入出力䟋 入力䟋 9850 1050 800 420 380 600 820 2400 1800 980 0 出力䟋 600 䞊蚘問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,629
Score : 1600 points Problem Statement Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1) . Now, he will make new permutations A and B of (0,1,\cdots,N-1) , under the following conditions: For each i ( 0 \leq i \leq N-1 ), A_i should be i or P_i . For each i ( 0 \leq i \leq N-1 ), B_i should be i or Q_i . Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i . Find the maximum possible distance of A and B . Constraints 1 \leq N \leq 100000 0 \leq P_i \leq N-1 P_0,P_1,\cdots,P_{N-1} are all different. 0 \leq Q_i \leq N-1 Q_0,Q_1,\cdots,Q_{N-1} are all different. All values in input are integers. Input Input is given from Standard Input in the following format: N P_0 P_1 \cdots P_{N-1} Q_0 Q_1 \cdots Q_{N-1} Output Print the maximum possible distance of A and B . Sample Input 1 4 2 1 3 0 0 2 3 1 Sample Output 1 3 For example, if we make A=(0,1,2,3) and B=(0,2,3,1) , the distance will be 3 , which is the maximum result possible. Sample Input 2 10 0 4 5 3 7 8 2 1 9 6 3 8 5 6 4 0 2 1 7 9 Sample Output 2 8 Sample Input 3 32 22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13 22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31 Sample Output 3 28
36,630
Problem A Decimal Sequences Hanako learned the conjecture that all the non-negative integers appear in the infinite digit sequence of the decimal representation of $\pi$ = 3.14159265..., the ratio of a circle's circumference to its diameter. After that, whenever she watches a sequence of digits, she tries to count up non-negative integers whose decimal representations appear as its subsequences. For example, given a sequence " 3 0 1 ", she finds representations of five non-negative integers 3, 0, 1, 30 and 301 that appear as its subsequences. Your job is to write a program that, given a finite sequence of digits, outputs the smallest non-negative integer not appearing in the sequence. In the above example, 0 and 1 appear, but 2 does not. So, 2 should be the answer. Input The input consists of a single test case. $n$ $d_1$ $d_2$ ... $d_n$ $n$ is a positive integer that indicates the number of digits. Each of $d_k$'s $(k = 1, ... , n)$ is a digit. There is a space or a newline between $d_k$ and $d_{k+1}$ $(k = 1, ..., n - 1)$. You can assume that $1 \leq n \leq 1000$. Output Print the smallest non-negative integer not appearing in the sequence. Sample Input 1 3 3 0 1 Sample Output 1 2 Sample Input 2 11 9 8 7 6 5 4 3 2 1 1 0 Sample Output 2 12 Sample Input 3 10 9 0 8 7 6 5 4 3 2 1 Sample Output 3 10 Sample Input 4 100 3 6 7 5 3 5 6 2 9 1 2 7 0 9 3 6 0 6 2 6 1 8 7 9 2 0 2 3 7 5 9 2 2 8 9 7 3 6 1 2 9 3 1 9 4 7 8 4 5 0 3 6 1 0 6 3 2 0 6 1 5 5 4 7 6 5 6 9 3 7 4 5 2 5 4 7 4 4 3 0 7 8 6 8 8 4 3 1 4 9 2 0 6 8 9 2 6 6 4 9 Sample Output 4 11 Sample Input 5 100 7 2 7 5 4 7 4 4 5 8 1 5 7 7 0 5 6 2 0 4 3 4 1 1 0 6 1 6 6 2 1 7 9 2 4 6 9 3 6 2 8 0 5 9 7 6 3 1 4 9 1 9 1 2 6 4 2 9 7 8 3 9 5 5 2 3 3 8 4 0 6 8 2 5 5 0 6 7 1 8 5 1 4 8 1 3 7 3 3 5 3 0 6 0 6 5 3 2 2 2 Sample Output 5 86 Sample Input 6 1 3 Sample Output 6 0
36,631
Problem A: 青春18きっぷ 2013 Problem Statement 䌚接合宿に参加予定の高槻さんは、家が貧乏であたりお金を持っおいない。そのため、青春18きっぷを䜿甚しお、お金を節玄しようずしおいる。18きっぷは、これ1枚だけで、鈍行列車ならば1日䞭乗り攟題、改札の出入りも自由ずいう優れものである詳しい利甚ルヌルに぀いおは省略。 18きっぷの魅力は、乗り換えを行う駅で、空いおいる時間を䜿っお、ご圓地のお土産等を芋おたわれる点である。圌女は、せっかくの機䌚なので、旅の途䞭でいろいろな駅を芋お回りたいず考えおいる。ただし、次の電車に乗り遅れおは困るため、乗り換え駅に到着した時刻から、乗り換え駅を出発する時刻たでの間がT分以䞊のずきだけ、その駅を芋お回るこずにした。 高槻さんの18きっぷを䜿った乗り換え蚈画が䞎えられるので、芋お回れる駅の名前ず時間を出力せよ。䞀番最初に出発する駅ず、䞀番最埌に到着する駅は、芋お回る候補には入らないこずに泚意しおほしい。 Input 各デヌタセットは、以䞋の圢匏で入力される。 N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Nは列車に乗車する回数を衚わす敎数、Tは乗り換え駅を芋お回れる蚱容時間(分)を衚わす敎数である。続いお、N行にわたっお、列車の出発ず到着のペアが䞎えられる。各行の入力は、st_timeiの時刻ちょうどにst_nameiの駅を高槻さんの乗る列車が出発するこずを、ar_timeiの時刻ちょうどにar_nameiの駅に高槻さんの乗る列車が到着するこずを意味する。 Constraints 1 <= N <= 10 1 <= T <= 180 st_timei、ar_timei "HH:MM"により衚わされ、HHには00以䞊23以䞋、MMには00以䞊59以䞋の2桁の数倀が入る。HHが時間で、MMが分である。 00:00 <= st_time1 < ar_time1 < st_time2 < ar_time2 < ... < st_timeN < ar_timeN <= 23:59 st_namei、ar_namei アルファベット倧文字・小文字により衚わされる文字列である。 1 <= 文字列の長さ <= 50 i番目の到着駅ar_nameiず、i+1番目の出発駅st_namei+1の名前は䞀臎する。 st_name1、ar_nameN、乗り換えの駅の名前は、それぞれ異なる文字列である。 Output 各デヌタセットに぀いお、以䞋の圢匏で出力を行う。 M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM M0 <= M <= N - 1は、芋お回れる駅の数を衚わす敎数である。続いお、M行にわたっお、芋お回れる駅のリストを時刻の昇順に出力する。各行は、stay_nameiの駅をstay_timei分間芋お回れるこずを意味する。 Sample Input 1 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output for the Sample Input 1 2 Kanazawa 55 Niitsu 24 Kanazawa駅は、10:03に到着し10:58に出発するため、乗り換えに55分の空き時間がある。Niitsu駅は、17:14に到着し17:38に出発するため、乗り換えに24分の空き時間がある。どちらも、入力で指定された24分以䞊の空き時間があるため、出力する。 Sample Input 2 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output for the Sample Input 2 0 乗り換え駅は1぀もないため、0ず出力する。
36,632
Problem E: Symmetry Open Binary and Object Group organizes a programming contest every year. Mr. Hex belongs to this group and joins the judge team of the contest. This year, he created a geometric problem with its solution for the contest. The problem required a set of points forming a line-symmetric polygon for the input. Preparing the input for this problem was also his task. The input was expected to cover all edge cases, so he spent much time and attention to make them satisfactory. However, since he worked with lots of care and for a long time, he got tired before he finished. So He might have made mistakes - there might be polygons not meeting the condition. It was not reasonable to prepare the input again from scratch. The judge team thus decided to find all line-asymmetric polygons in his input and fix them as soon as possible. They asked a programmer, just you, to write a program to find incorrect polygons. You can assume the following: Edges of the polygon must not cross or touch each other except for the end points of adjacent edges. It is acceptable for the polygon to have adjacent three vertexes on a line, but in such a case, there must be the vertex symmetric to each of them. Input The input consists of a set of points in the following format. N x 1 y 1 x 2 y 2 ... x N y N The first line of the input contains an integer N (3 ≀ N ≀ 1000), which denotes the number of points. The following N lines describe each point. The i -th line contains two integers x 1 , y 1 (-10000 ≀ x i , y i ≀ 10000), which denote the coordinates of the i -th point. Note that, although the points are the vertexes of a polygon, they are given in an artibrary order, not necessarily clockwise or counterclockwise. Output Output " Yes " in a line if the points can form a line-symmetric polygon, otherwise output " No ". Sample Input 1 4 0 1 1 0 0 0 1 1 Sample Output 1 Yes Sample Input 2 4 0 1 1 -1 0 0 1 1 Sample Output 2 No Sample Input 3 9 -1 1 0 1 1 1 -1 0 0 0 1 0 -1 -1 0 -1 1 -1 Sample Output 3 No Sample Input 4 3 -1 -1 0 0 1 1 Sample Output 4 No Sample Input 5 4 0 2 0 0 -1 0 1 0 Sample Output 5 Yes
36,633
Problem G: Search of Concatenated Strings The amount of information on the World Wide Web is growing quite rapidly. In this information explosion age, we must survive by accessing only the Web pages containing information relevant to our own needs. One of the key technologies for this purpose is keyword search. By using well-known search engines, we can easily access those pages containing useful information about the topic we want to know. There are many variations in keyword search problems. If a single string is searched in a given text, the problem is quite easy. If the pattern to be searched consists of multiple strings, or is given by some powerful notation such as regular expressions, the task requires elaborate algorithms to accomplish efficiently. In our problem, a number of strings (element strings) are given, but they are not directly searched for. Concatenations of all the element strings in any order are the targets of the search here. For example, consider three element strings aa, b and ccc are given. In this case, the following six concatenated strings are the targets of the search, i.e. they should be searched in the text. aabccc aacccb baaccc bcccaa cccaab cccbaa The text may contain several occurrences of these strings. You are requested to count the number of occurrences of these strings, or speaking more precisely, the number of positions of occurrences in the text. Two or more concatenated strings may be identical. In such cases, it is necessary to consider subtle aspects of the above problem statement. For example, if two element strings are x and xx, the string xxx is an occurrence of both the concatenation of x and xx and that of xx and x. Since the number of positions of occurrences should be counted, this case is counted as one, not two. Two occurrences may overlap. For example, the string xxxx has occurrences of the concatenation xxx in two different positions. This case is counted as two. Input The input consists of a number of datasets, each giving a set of element strings and a text. The format of a dataset is as follows. n m e 1 e 2 . . . e n t 1 t 2 . . . t m The first line contains two integers separated by a space. n is the number of element strings. m is the number of lines used to represent the text. n is between 1 and 12, inclusive. Each of the following n lines gives an element string. The length (number of characters) of an element string is between 1 and 20, inclusive. The last m lines as a whole give the text. Since it is not desirable to have a very long line, the text is separated into m lines by newlines, but these newlines should be ignored. They are not parts of the text. The length of each of these lines (not including the newline) is between 1 and 100, inclusive. The length of the text is between 1 and 5000, inclusive. The element strings and the text do not contain characters other than lowercase letters. The end of the input is indicated by a line containing two zeros separated by a space. CAUTION! Although the sample input contains only small datasets, note that 12! × 5000 is far larger than 2 31 . Output For each dataset in the input, one line containing the number of matched positions should be output. An output line should not contain extra characters. Sample Input 3 1 aa b ccc aabccczbaacccbaazaabbcccaa 3 1 a b c cbbcbcbabaacabccaccbaacbccbcaaaccccbcbcbbcacbaacccaccbbcaacbbabbabaccc 3 4 aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 0 0 Output for the Sample Input 5 12 197
36,634
C : Pruning / 枝刈り Problem ずにかくあ぀い。あづい君の䜏んでいる地域は今幎猛暑であった。 さらに、家の庭には 1 本の朚が生えおおり、毎日やかたしく鳎く蝉が暑さを増幅させおいるような気がする。 庭の朚は、たさにグラフ理論でいうずころの朚のような圢をしおおり、この朚にはたくさんの蝉が止たっおいる。 蝉は、必ず枝の先端(葉)たたは枝の分かれ目(頂点)に止たる習性がある。 ただし、朚の根には 1 匹も止たるこずはない。 この朚のある枝(蟺)を切るず、それより空偎(根ず反察偎)にいる蝉を党お駆陀するこずができる。 ただし、枝を切るためには、その枝に応じた劎力が必芁ずなる。 (泚 : 括匧内の蚀葉はグラフ理論の蚀葉で眮き換えたものである。以降は党おグラフ理論の蚀葉で衚珟するこずにする。) 高床情報化瀟䌚ずなった珟代においおは、 郚屋に居ながらにしお頂点に䜕匹の蝉がいるか、 そしお各蟺を切るのに芁する劎力を調べるこずが出来る。 あづい君はその情報を甚いお、 朚に止たっおいる党おの蝉を駆陀するのに必芁な最小の劎力を調べるプログラムを曞くこずにした。 Input 入力は次のような圢匏で䞎えられる N C 1 ... C N-1 u 0 v 0 p 0 ... u N-2 v N-2 p N-2 N は朚に含たれる頂点の数である。 各頂点には 0 ... N - 1 の番号が振られ、0番目の頂点を根ずする。 C 1 ... C N-1 は、各頂点に止たっおいる蝉の数であり、 C i が i 番目の頂点に止たっおいる蝉の数である。 根には、蝉は1匹も止たっおいない。 2 + i 行目の u i , v i , p i は、朚に含たれる蟺の情報である。 u i , v i は蟺が結ぶ 2 頂点の番号であり、 p i はこの蟺を切るのに必芁な劎力である。 Constraints 入力は党お敎数である。 䞎えられるグラフは朚である。 2 ≩ N ≩ 1,000 0 ≩ C i ≩ 1,000 0 ≩ u i , v i < N 1 ≩ p i ≩ 1,000 Output 蝉を党お駆陀するために必芁な最小の劎力を 1 行で出力せよ。 Samples Sample Input 1 5 2 2 2 2 0 1 4 1 2 1 1 3 1 1 4 1 Sample Output 1 4 頂点 0 ず 1 を぀なぐ蟺を切れば、党おの蝉を駆陀するこずができる。 Sample Input 2 5 0 2 2 2 0 1 4 1 2 1 1 3 1 1 4 1 Sample Output 2 3 頂点 1 ず 2 、 1 ず 3 、 1 ず 4 を぀なぐ蟺の3本を切れば最小の劎力で蝉を駆陀するこずができる。 なお、頂点 0 ず 1 を぀なぐ蟺を切るこずで党おの蝉を駆陀するこずができるが、これにはコストが 4 かかっおしたう。
36,635
Problem F: Water Tank You built an apartment. The apartment has a water tank with a capacity of L in order to store water for the residents. The tank works as a buffer between the water company and the residents. It is required to keep the tank "not empty" at least during use of water. A pump is used to provide water into the tank. From the viewpoint of avoiding water shortage, a more powerful pump is better, of course. But such powerful pumps are expensive. That’s the life. You have a daily schedule table of water usage. It does not differ over days. The table is composed of some schedules. Each schedule is indicated by the starting time of usage, the ending time and the used volume per unit of time during the given time span. All right, you can find the minimum required speed of providing water for days from the schedule table. You are to write a program to compute it. You can assume the following conditions. A day consists of 86,400 units of time. No schedule starts before the time 0 (the beginning of the day). No schedule ends after the time 86,400 (the end of the day). No two schedules overlap. Water is not consumed without schedules. The tank is full of water when the tank starts its work. Input The input is a sequence of datasets. Each dataset corresponds to a schedule table in the following format: N L s 1 t 1 u 1 ... s N t N u N The first line of a dataset contains two integers N and L (1 ≀ N ≀ 86400, 1 ≀ L ≀ 10 6 ), which represents the number of schedule in the table and the capacity of the tank, respectively. The following N lines describe the N schedules. The ( i + 1)-th line of the dataset corresponds to the i -th schedule, which consists of three integers s i , t i and u i . The first two integers s i and t i indicate the starting time and the ending time of the schedule. The last integer u i (1 ≀ u i ≀ 10 6 ) indicates the consumed volume per unit of time during the schedule. It is guaranteed that 0 ≀ s 1 < t 1 ≀ s 2 < t 2 ≀ ... ≀ s n < t n ≀ 86400. The input is terminated by a line with two zeros. This line should not be processed. Output For each case, print the minimum required amount of water per unit of time provided by the pump in a line. The amount may be printed with an arbitrary number of digits after the decimal point, but should not contain an absolute error greater than 10 -6 . Sample Input 1 100 0 86400 1 1 100 43200 86400 1 0 0 Output for the Sample Input 1.000000 0.997685
36,636
Problem L: Problem L: 3぀のシル゚ット JAVA(Japan Aerospace Voyage Agency: 日本宇宙飛行研究機構)は、宇宙開発事業の䞀環ずしお2003幎に探査機を打ち䞊げた。 この探査機打ち䞊げの目的の䞀぀に、小惑星むシカワに接近し、その衚面物質のサンプルを採集するこずがある。 様々なアクシデントに芋舞われながらも、探査機はむシカワに到達し、そしお぀いに2010幎、地球ぞ垰還し、むシカワのサンプル詊料の入ったカプセルを回収するこずに成功した。 東京倧孊を卒業し、JAVAに就職したきたたさ君は、この詊料の研究を担圓しおいる。 䞀刻も早く詊料の分析をしたいずころであるが、ずおも慎重なきたたさ君は、もしカプセルの䞭に凶暎な゚むリアンが入っおいたら倧倉であるず考えた。 そこで、カプセルを開ける前にX線を甚いお内郚の物質の圢状を調べ、゚むリアンが入っおいないこずを確認するこずにした。 カプセルにX線を圓おるず、物質が存圚しおいるずころは癜色に、存圚しおいないずころは黒色になった写真が埗られる。 様々な角床からX線を圓おお写真を埗るこずにより、内郚の物質の圢状を特定するこずができる。 しかし、ここでたた問題が生じた。 正面から、右偎面から、䞊面からの枚の写真を埗たずころでX線装眮が故障しおしたったのである。 さらに、枚の写真の珟像にも倱敗し、本来黒色になるべき郚分が䞀郚癜色ずなっおしたった可胜性もある。 このたたでは物質の圢状を正確に特定するこずは出来ないため、䞭に゚むリアンが入っおいないこずを確認できず、カプセルを開けるこずができない。 研究を続けるためには、X線装眮を買い換えるしかないのだが、JAVAには事業仕分けによる予算削枛の圱響で、X線装眮をすぐに買い換えるだけのお金がない。 そこできたたさ君は来幎床の予算を増やしおもらい、そのお金で新しいX線装眮を買うこずを考えた。 もちろん、予算は簡単には増えないため、探査機の成果を最倧限にアピヌルする必芁がある。 カプセル䞭に倧きな物質が含たれおいるほど成果を匷くアピヌルするこずができるため、物質が取りうる最倧䜓積を蚈算するこずにした。 枚のX線写真ず矛盟しないような内郚の物質の圢状のうちで、䜓積が最倧であるものを求め、その䜓積を出力せよ。 Input 各X線写真の癜色ず黒色の境界は䞀぀の倚角圢からなる。 倚角圢は凞ずは限らず、たた自己亀差はしない。 倚角圢の内偎が癜色、倖偎が黒色である。 入力の圢匏は以䞋のようである。 n x y 1 z 1 y 2 z 2 ... y n x z n x n y z 1 x 1 z 2 x 2 ... z n y x n y n z x 1 y 1 x 2 y 2 ... x n z y n z n x , n y , n z はそれぞれ、正面・右偎面・䞊面からのX線写真に察応する倚角圢の頂点数である。 各頂点数は3以䞊20以䞋である。 続く n 行には倚角圢の頂点の座暙が反時蚈回りに䞎えられる。 頂点の座暙は0以䞊300以䞋の敎数である。 たた、座暙軞はカプセルの䞭心から正面方向にx軞を、右偎面方向にy軞を、䞊面方向にz軞を取っおある。 Output 枚のX線写真ず矛盟しないような物質の最倧䜓積を䞀行に出力せよ。 出力する倀は10 -3 以䞋の誀差を含んでいおも構わない。倀は小数点以䞋䜕桁衚瀺しおも構わない。 Notes on Test Cases 䞊蚘入力圢匏で耇数のデヌタセットが䞎えられたす。各デヌタセットに察しお䞊蚘出力圢匏で出力を行うプログラムを䜜成しお䞋さい。 n x , n y , n z がすべお 0 のずき入力の終わりを瀺したす。 Sample Input 4 0 0 100 0 100 100 0 100 4 0 0 100 0 100 100 0 100 4 0 0 100 0 100 100 0 100 3 0 0 100 0 0 100 3 0 0 100 0 0 100 3 0 0 100 0 0 100 5 0 0 200 0 200 200 100 100 0 200 5 0 0 200 0 100 100 200 200 0 200 4 0 0 200 0 200 200 0 200 0 0 0 Output for Sample Input 1000000.0000 250000.0000 5333333.3333
36,637
お化け屋敷 䌚接孊園高等孊校では、毎幎孊園祭をおこなっおいたす。その䞭でも䞀番人気はお化け屋敷です。䞀番人気の理由は、お化け屋敷をおこなうクラスが 1クラスや 2クラスではなく、9クラスがお化け屋敷をおこなうこずです。それぞれが工倫するこずより、それぞれが個性的なお化け屋敷になっおいたす。そのため、最近では近隣から倚くの来堎者が蚪れたす。 そこで、孊園祭実行委員䌚では、お化け屋敷の入堎料金を䞋衚のように校内で統䞀し、これにもずづき各クラスごずに入堎者総数ず収入の集蚈をおこなうこずにしたした。 入堎料金衚(入堎者 1人あたりの入堎料) 午前 午埌 200円 300円 各クラス毎の午前ず午埌の入堎者数を入力ずし、各クラス毎の入堎者総数及び収入の䞀芧衚を䜜成するプログラムを䜜成しおください。 Input 入力は以䞋の圢匏で䞎えられたす。 name 1 a 1 b 1 name 2 a 2 b 2 : name 9 a 9 b 9 入力は行からなり、 i 行目に第 i のクラスのクラス名 name i (数字ずアルファベットを含む 1 文字以䞊 15 文字以䞋の半角文字列)、午前の入堎者数 a i (0 ≀ a i ≀ 400)、 午埌の入堎者数 b i (0 ≀ b i ≀ 400) が䞎えられたす。 Output i 行目に第 i のクラスのクラス名、 入堎者総数、 料金収入を空癜区切りで行に出力しおください。 Sample Input 1a 132 243 1c 324 183 1f 93 199 2b 372 163 2c 229 293 2e 391 206 3a 118 168 3b 263 293 3d 281 102 Output for the Sample Input 1a 375 99300 1c 507 119700 1f 292 78300 2b 535 123300 2c 522 133700 2e 597 140000 3a 286 74000 3b 556 140500 3d 383 86800
36,638
サッカヌ (Soccer) 問題 JOI 囜ではサッカヌが人気でありJOI リヌグずいうリヌグ戊が毎週行われおいる JOI リヌグには N 個のチヌムが所属しおいお1 から N たでの番号が぀けられおいるすべおの組み合わせの詊合がちょうど䞀床ず぀行われる぀たり N × (N - 1) / 2 詊合が行われる各詊合の勝敗はそれぞれのチヌムの埗点で決たる勝ったチヌムの勝ち点は 3 点であり負けたチヌムの勝ち点は 0 点である匕き分けの堎合䞡チヌムの勝ち点は 1 点である順䜍は各チヌムの獲埗した勝ち点の合蚈で決定し埗倱点差は考えない勝ち点の合蚈が等しいチヌムの順䜍は䞊䜍に揃える 䟋ずしお 4 チヌムでのリヌグ戊を考える 4 × (4 - 1) / 2 = 6 詊合が行われるそれらの結果が以䞋の衚のようになったずするハむフンの巊偎はその暪のチヌムの埗点であり右偎はその瞊のチヌムの埗点である チヌム 1 チヌム 2 チヌム 3 チヌム 4 勝ち数 負け数 匕き分け数 勝ち点 チヌム 1 --- 0 - 1 2 - 1 2 - 2 1 1 1 4 チヌム 2 1 - 0 --- 1 - 1 3 - 0 2 0 1 7 チヌム 3 1 - 2 1 - 1 --- 1 - 3 0 2 1 1 チヌム 4 2 - 2 0 - 3 3 - 1 --- 1 1 1 4 このずき勝ち点の最も倚いチヌム 2 が 1 䜍である その次に勝ち点が倚いチヌムはチヌム 1 ずチヌム 4 でありこれらのチヌムの順䜍は共に 2 䜍である そしお勝ち点が最も少ないチヌム 3 が 4 䜍である 党おの詊合の結果が䞎えられたずき各チヌムの順䜍を求めるプログラムを䜜成せよ 入力 入力ファむルの 1 行目にはチヌムの個数 N (2 ≩ N ≩ 100) が曞かれおいる続く N × (N - 1) / 2 行には各詊合の結果が曞かれおいるi + 1 行目 (1 ≩ i ≩ N × (N - 1) / 2 ) には敎数 A i B i C i D i (1 ≩ A i ≩ N1 ≩ B i ≩ N0 ≩ C i ≩ 1000 ≩ D i ≩ 100) が空癜を区切りずしお曞かれおおりチヌム A i ずチヌム B i が察戊しチヌム A i の埗点が C i 点チヌム B i の埗点が D i 点であったこずを衚す党おの i に぀いお A i ≠ B i であり同じ組み合わせの察戊が曞かれおいるこずはない 出力 出力は N 行からなる各行は 1 ぀の敎数からなり i 行目 (1 ≩ i ≩ N) の敎数はチヌム i の順䜍を衚す 入出力䟋 入力䟋 1 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 出力䟋 1 2 1 4 2 入出力䟋 1 は問題文䞭の䟋に察応しおいる 入力䟋 2 5 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 出力䟋 2 2 4 1 4 3 入出力䟋 2 における結果は以䞋の通りである 勝ち数 負け数 匕き分け数 勝ち点 チヌム 1 2 1 1 7 チヌム 2 0 1 3 3 チヌム 3 3 0 1 10 チヌム 4 1 3 0 3 チヌム 5 1 2 1 4 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,639
バヌムクヌヘン(Baumkuchen) JOI 君は効のJOI 子ちゃんずJOI 矎ちゃんず䞀緒におや぀を食べようずしおいる今日のおや぀は3 人の倧奜物のバヌムクヌヘンだ バヌムクヌヘンは䞋図のような円筒圢のお菓子である3 人に分けるためにJOI 君は半埄方向に刃を3回入れおこれを3 ぀のピヌスに切り分けなければならないただしこのバヌムクヌヘンは本物の朚材のように固いので刃を入れるのは簡単ではないそのためこのバヌムクヌヘンにはあらかじめ $N$ 個の切れ蟌みが入っおおりJOI 君は切れ蟌みのある䜍眮でのみ切るこずができる切れ蟌みに1 から $N$ たで時蚈回りに番号をふったずき$1 \leq i \leq N - 1$ に察し $i$ 番目の切れ蟌みず$i + 1$ 番目の切れ蟌みの間の郚分の倧きさは $A_i$ であるたた $N$ 番目の切れ蟌みず1 番目の切れ蟌みの間の郚分の倧きさは $A_N$ である 図1: バヌムクヌヘンの䟋 $N = 6, A_1 = 1, A_2 = 5, A_3 = 4, A_4 = 5, A_5 = 2, A_6 = 4$ 課題 切れ蟌みの個数 $N$ ず各郚分の倧きさを衚す敎数 $A_1,...,A_N$ が䞎えられるバヌムクヌヘンを3 ぀に切り分けたずきの最も小さいピヌスの倧きさの最倧倀を出力するプログラムを䜜成せよ 入力 暙準入力から以䞋のデヌタを読み蟌め 1 行目には敎数 $N$ が曞かれおいるこれはバヌムクヌヘンに $N$ 個の切れ蟌みがあるこずを衚す 続く$N$ 行のうちの $i$ 行目$(1 \leq i \leq N)$ には敎数 $A_i$ が曞かれおいるこれは $i$ 番目の切れ蟌みず $i + 1$ 番目の切れ蟌みの間の郚分 ($i = N$ のずきは $N$ 番目の切れ蟌みず1 番目の切れ蟌みの間の郚分) の倧きさが $A_i$ であるこずを衚す 出力 暙準出力にバヌムクヌヘンを3 ぀に切り分けたずきの最も小さいピヌスの倧きさの最倧倀を衚す敎数を1 行で出力せよ 制限 すべおの入力デヌタは以䞋の条件を満たす $3 \leq N \leq 100000$ $1 \leq A_i \leq 1000000000 (1 \leq i \leq N)$ 入出力䟋 入力䟋 1 6 1 5 4 5 2 4 出力䟋 1 6 図2: 1 番目の切れ蟌みず3 番目の切れ蟌みず5 番目の切れ蟌みで切るのが最善である 入力䟋 2 30 1 34 44 13 30 1 9 3 7 7 20 12 2 44 6 9 44 31 17 20 33 18 48 23 19 31 24 50 43 15 出力䟋 2 213 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,640
Problem A: Equal Total Scores Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards should be exchanged with which? Note that they have to exchange their cards even if they already have cards of the same total score. Input The input consists of a number of datasets. Each dataset is formatted as follows. n m s 1 s 2 ... s n s n +1 s n +2 ... s n + m The first line of a dataset contains two numbers n and m delimited by a space, where n is the number of cards that Taro has and m is the number of cards that Hanako has. The subsequent n + m lines list the score for each of the cards, one score per line. The first n scores (from s 1 up to s n ) are the scores of Taro's cards and the remaining m scores (from s n +1 up to s n + m ) are Hanako's. The numbers n and m are positive integers no greater than 100. Each score is a non-negative integer no greater than 100. The end of the input is indicated by a line containing two zeros delimited by a single space. Output For each dataset, output a single line containing two numbers delimited by a single space, where the first number is the score of the card Taro gives to Hanako and the second number is the score of the card Hanako gives to Taro. If there is more than one way to exchange a pair of cards that makes the total scores equal, output a pair of scores whose sum is the smallest. In case no exchange can make the total scores equal, output a single line containing solely -1. The output must not contain any superfluous characters that do not conform to the format. Sample Input 2 2 1 5 3 7 6 5 3 9 5 2 3 3 12 2 7 3 5 4 5 10 0 3 8 1 9 6 0 6 7 4 1 1 2 1 2 1 4 2 3 4 3 2 3 1 1 2 2 2 0 0 Output for the Sample Input 1 3 3 5 -1 2 2 -1
36,641
Score : 500 points Problem Statement There are N children standing in a line from left to right. The activeness of the i -th child from the left is A_i . You can rearrange these children just one time in any order you like. When a child who originally occupies the x -th position from the left in the line moves to the y -th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn. Constraints 2 \leq N \leq 2000 1 \leq A_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the maximum total happiness points the children can earn. Sample Input 1 4 1 3 4 2 Sample Output 1 20 If we move the 1 -st child from the left to the 3 -rd position from the left, the 2 -nd child to the 4 -th position, the 3 -rd child to the 1 -st position, and the 4 -th child to the 2 -nd position, the children earns 1 \times |1-3|+3 \times |2-4|+4 \times |3-1|+2 \times |4-2|=20 happiness points in total. Sample Input 2 6 5 5 6 1 1 1 Sample Output 2 58 Sample Input 3 6 8 6 9 1 2 1 Sample Output 3 85
36,642
Problem I: Live Programming A famous Japanese idol group, JAG48, is planning the program for its next live performance. They have $N$ different songs, $song_1$, $song_2$, ..., and $song_N$. Each song has three integer param- eters, $t_i$, $p_i$, and $f_i$: $t_i$ denotes the length of $song_i$, $p_i$ denotes the basic satisfaction points the audience will get when $song_i$ is performed, and $f_i$ denotes the feature value of songi that affects the audience's satisfaction. During the live performance, JAG48 can perform any number (but at least one) of the $N$ songs, unless the total length of the chosen songs exceeds the length of the live performance $T$. They can decide the order of the songs to perform, but they cannot perform the same song twice or more. The goal of this live performance is to maximize the total satisfaction points that the audience will get. In addition to the basic satisfaction points of each song, the difference between the feature values of the two songs that are performed consecutively affects the total satisfaction points. If there is no difference, the audience will feel comfortable. However, the larger the difference will be, the more frustrated the audience will be. Thus, the total satisfaction points will be calculated as follows: If $song_x$ is the first song of the live performance, the total satisfaction points just after $song_x$ is equal to $p_x$. If $song_x$ is the second or subsequent song of the live performance and is performed just after $song_y$, $p_x -(f_x -f_y)^2$ is added to the total satisfaction points, because the audience will get frustrated if $f_x$ and $f_y$ are different. Help JAG48 find a program with the maximum total satisfaction points. Input The input is formatted as follows. $N$ $T$ $t_1$ $p_1$ $f_1$ : : : $t_N$ $p_N$ $f_N$ The first line contains two integers $N$ and $T$: the number of the available $song_s$ $N$ ($1 \leq N \leq 4,000$), and the length of the live performance $T$ ($1 \leq T \leq 4,000$). The following $N$ lines represent the parameters of the songs. The $i$-th line of them contains three integers, which are the parameters of $song_i$: the length $t_i$ ($1 \leq t_i \leq 4,000$), the basic satisfaction points $p_i$ ($1 \leq p_i \leq 10^8$), and the feature value $f_i$ ($1 \leq f_i \leq 10^4$). You can assume that there is at least one song whose length is less than or equal to $T$. Output Output the maximum total satisfaction points that the audience can get during the live performance. Sample Input 2 10 10 200 1 10 100 100 Output for the Sample Input 200 Sample Input 3 15 5 100 1 5 100 2 5 100 4 Output for the Sample Input 295 Sample Input 3 10 5 200 200 5 200 201 5 300 1 Output for the Sample Input 399 Sample Input 3 20 5 100 200 5 100 201 5 300 1 Output for the Sample Input 300 Sample Input 5 61 14 49 7 31 46 4 30 55 5 52 99 1 34 70 3 Output for the Sample Input 103
36,643
Bange Hills Tower A project is underway to build a new viewing tower in Bange town called “Bange Hills Tower” whose selling point will be the gorgeous view of the entire main keep of Wakamatsu Castle from top to bottom. Therefore, the view line from the top of the tower must reach the bottom of the keep without being hindered by any of the buildings in the town. Write a program to calculate the minimum tower height required to view the keep in its entirety based on the following information: the planned location of the tower and the heights and locations of existing buildings. Assume all the buildings, including the keep, are vertical lines without horizontal stretch. “view of the entire keep” means that the view line from the tower top can cover the keep from the bottom to the top without intersecting (contacts at the top are exempted) any of the other vertical lines (i.e., buildings). Input The input is given in the following format. N t x_1 h_1 x_2 h_2 : x_N h_N The first line provides the number of existing buildings N (1≀ N ≀1000) and the planned location of the tower t (2≀ t ≀10 5 ) in integers. Each of the subsequent N lines provides the information of the i -th building: location x_i (1 ≀ x_i < t ) and height from the ground h_i (1 ≀ h_i ≀ 100). All position information is one-dimensional along the ground line whose origin coincides with the Keep location. No more than one building is located in the same location (i.e. if i ≠ j , then x_i ≠ x_j ). Output Output the required height as a real number. No limits on the number of decimal places as long as the error does not exceed ± 10 -3 . Sample Input 1 3 10 6 4 4 2 3 2 Sample Output 1 6.666667
36,644
The Maximum Number of Customers $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints $ 1 \leq N \leq 10^5 $ $ 1 \leq T \leq 10^5 $ $ 0 \leq l_i < r_i \leq T $ Input The input is given in the following format. $N$ $T$ $l_1$ $r_1$ $l_2$ $r_2$ : $l_N$ $r_N$ Output Print the maximum number of persons in a line. Sample Input 1 6 10 0 2 1 3 2 6 3 8 4 10 5 10 Sample Output 1 4 Sample Input 2 2 2 0 1 1 2 Sample Output 2 1
36,645
Mysterious Gems 宇宙暊 1603〜1867 幎人々はその時代のこずを EDO 時代ず呌ぶEDO ずは圓時最先端の宇宙航行技術Enhanced Driving Operation のこずであり、1603 幎に Dr.Izy によっお開発された あなたは宇宙冒険家であり宇宙を飛び回っお様々な惑星を冒険しおいたその冒険の途䞭であなたはずおも䞍思議な惑星を発芋したその惑星には至るずころに䞃色に茝く䞍思議な宝石が萜ちおいたあなたはその惑星ぞの降䞋を詊みようず考えたが重倧な問題のためにそれは䞍可胜であるこずがわかったその惑星の空気には人間が觊れただけで即死しおしたうような猛毒の成分が含たれおいたのだ そこであなたはロボットを䜿っお宝石を回収するこずを考え぀いたあなたはその惑星の呚回軌道にお埅機するそしお降䞋させたロボットを遠隔操䜜するこずによっお宝石を回収するのだあなたはロボットに「移動する方向」ず「移動する距離」の組からなる呜什の列によっおロボットを遠隔操䜜するロボットは移動経路䞊到達点を含むに宝石を芋぀けるずそれらを党お回収する あなたの仕事はロボットが䞎えられた党おの呜什の実行を終えたずきに党おの宝石を回収するこずができたかどうかを刀定するプログラムを曞くこずである なおロボットが䞍思議な宝石を回収する範囲はそれほど広くないそのためロボットが移動する範囲は党お 2 次元の平面で衚すこずができるそしおロボットが移動する範囲は (0,0) および (20,20) をそれぞれ巊䞋隅および右䞊隅ずする正方圢の内郚境界線を含むであるロボットは垞に範囲の䞭倮すなわち (10,10) の座暙に降䞋するたた党おの宝石は䞭倮以倖の栌子点䞊にあるこずが保蚌されおいる Input 入力は耇数のデヌタセットにより構成される それぞれのデヌタセットの先頭行には単䞀の正の敎数 N (1 <= N <= 20) が含たれる。これはロボットが移動可胜な範囲内にある䞍思議な宝石の個数を衚す次の N 行にはそれぞれ x i および y i (0 <= x i , y i <= 20) が含たれこれは i 番目の䞍思議な宝石の萜ちおいる座暙を衚すなお1 ぀の堎所に耇数の宝石が萜ちおいるこずはない 次の行には単䞀の敎数 M (1 <= M <= 30) が含たれこれはロボットに䞎えた呜什の個数を衚すこの埌の M 行にはそれぞれ d j ずひず぀の正の敎数 l j が含たれるこれは j 番目の呜什における方向および移動量を衚すただし方向は NESW のいずれかの文字であり順に北東南西を衚す北は y 軞の正方向東は x 軞の正方向なおロボットが移動可胜な範囲を超えるような呜什は䞎えられないこずが保蚌されおいる 入力は N = 0 のずきに終了しこれはデヌタセットに含たれない Output それぞれのデヌタセットに぀いおロボットが党おの宝石を収集できるずきは「Yes」ずそうでないずきは「No」ず 1 行に出力しなさい Sample Input 2 10 11 11 12 2 N 2 E 1 2 10 11 11 12 2 N 2 W 1 3 0 15 5 10 5 15 5 W 10 S 10 N 20 E 10 S 10 0 Output for the Sample Input Yes No No
36,647
Score : 200 points Problem Statement We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat? Constraints All input values are integers. 1 \leq X, Y, Z \leq 10^5 Y+2Z \leq X Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Sample Input 1 13 3 1 Sample Output 1 3 There is just enough room for three, as shown below: Figure Sample Input 2 12 3 1 Sample Output 2 2 Sample Input 3 100000 1 1 Sample Output 3 49999 Sample Input 4 64146 123 456 Sample Output 4 110 Sample Input 5 64145 123 456 Sample Output 5 109
36,648
Problem E: Dungeon Master Once upon a time, in a fantasy world far, far away, monsters dug caves and dungeons for adventurers. They put some obstacles in their caves so it becomes more difficult and more exciting for the adventurers to reach the goal. One day, Emils, one of the monsters in the caves, had a question about the caves. How many patterns of a cave can they make, by changing the locations of the obstacles in it? Here's the detail of the question. A cave consists of W × H squares. Monsters can put obstacles at some of the squares, so that adventurers can't go into them. The total number of obstacles is fixed, and there can't be two or more obstacles in one square. Adventurers enter the cave from the top-left square, and try to reach the bottom-right square. They can move from one square to any of the four adjacent squares, as long as there are no obstacles in the destination square. There must be at least one path between any two squares that don't have obstacles. There must be no obstacles in the top-left square, nor in right-bottom square. The question is, given the width W and height H of the cave, and the number S of obstacles, how many patterns of the caves the monsters can make. As the obstacles have the same look, they should not be distinguished each other. It was a very interesting mathematical question. Emils couldn't solve this question by himself, so he told it to his colleagues instead. None of them could answer to it, though. After that, the question soon got popular among the monsters working in the caves, and finally, they became unable to sleep well as they always thought about the question. You are requested to write a program that answers to the question. Input The input has a line, containing three integers W , H , and S , separated by a space. W and H are the horizontal and vertical sizes of the cave, and S is the number of obstacles to put in the cave. It is guaranteed that 2 ≀ W , H ≀ 8, and that 0 ≀ S ≀ W × H . Output Output the number of patterns of the cave, in a line. Sample Input 1 2 2 2 Output for the Sample Input 1 0 Sample Input 2 2 2 1 Output for the Sample Input 2 2
36,649
Product Sale Lines Problem りニクロ卯月さんず目黒凛さんはSEARIGHT LIVE FESの物販に来おいる。䞋図のように、物販列は二列からなり、暪に W 人、瞊に H 人䞊べる倧きさでコの字の圢をしおいる。列の先頭の人は買い物をした埌に列からはけ、同じ列の埌ろの人々はそれぞれ䞀人分ず぀列を詰める。 二人は最初に物販列の最埌尟に隣同士で、それぞれ違う列に䞋図オレンゞず濃い青色の䜍眮䞊んでいる。二人はずおも仲がよいため、垞にできるだけ近くにいたい。しかし、人のはけ方は列によっお違うため、違う列に䞊んでいる二人の䜍眮は離れおしたう可胜性がある。 あなたの仕事は、列のはけ方が䞎えられたずき、二人が隣同士になる回数を求めるこずである。 ただし、二人ずもコの字の角にいる䞊図の黒色の状態のずきは、隣同士ずみなさない。たた、䞊んだ盎埌は隣同士に䞊んでいるが、これは数えない。 Input 入力は以䞋の圢匏で䞎えられる。 W H N p 1 p 2 ... p N 1行目に列の倧きさを衚す敎数 W ず H が空癜区切りで䞎えられる。 W はコの字の暪に䞊べる倖偎の人数を、 H は瞊に䞊べる倖偎の人数を衚す。2行目に人が䞀人どちらかの列からはける回数 N が䞎えられる。3行目には列のはけ方に぀いおの情報 p 1 ... p N が空癜区切りで䞎えられる。 p i に’0’たたは’1’であり、’0’のずき、倖偎の人が䞀人はけるこずを、’1’のずき内偎の人が䞀人はけるこずを衚す。ただし、りニクロ卯月さんたたは目黒凛さんが列から出るこずはない。 Constraints 4 ≀ W ≀ 100 4 ≀ H ≀ 100 0 ≀ N ≀ 100 Output 二人が隣同士になる回数を䞀行に出力せよ。 Sample Input 1 11 11 5 0 0 0 0 0 Sample Output 1 0 Sample Input 2 11 11 5 0 0 1 1 1 Sample Output 2 1
36,650
問題文 ハコの魔女 H.N.ELLY はずある動画サむトの熱狂的なファンであるハコの魔女の匷さはその時々のその動画サむトからの転送速床に応じお倉化するのではないかず 矎暹さやか は考えたそこで動画サむトからハコの魔女の持぀コンピュヌタたでの過去の転送速床 (=単䜍時間あたりのデヌタの転送量) を調べたい 初期のむンタヌネットのネットワヌクの構造ずそれ以降のネットワヌクの構造の倉化を衚すク゚リが䞎えられるので各倉化に぀いお倉化した盎埌の動画サむトからハコの魔女の持぀コンピュヌタたでの転送速床を求めよ むンタヌネットは耇数の転送装眮からなるものず芋なし各々を぀なぐ回線は双方向に情報を送るこずができその転送速床の最倧は 1 であるずするたたネットワヌクは垞に動画サむトからハコの魔女ぞ送られるデヌタの転送速床を最倧化するように運ぶものずする 入力圢匏 入力は以䞋の圢匏で䞎えられる N\ E\ Q\\ F_1\ T_1\\ F_2\ T_2\\ 
\\ F_E\ T_E\\ M_1\ A_1\ B_1\\ M_2\ A_2\ B_2\\ ...\\ M_Q\ A_Q\ B_Q\\ N は動画サむトずハコの魔女の持぀コンピュヌタを含めた転送装眮の数である番号が 1 である転送装眮は動画サむトであり番号が N である転送装眮はハコの魔女の持぀コンピュヌタである E は初期状態で接続されおいる転送装眮の組み合わせの数であり Q はむンタヌネットが倉化した回数である初期のむンタヌネットは F_i ず T_i が転送速床 1 で双方向に接続されおいるこずを衚す ネットワヌクの倉化は時系列順に䞎えられ j 番目の倉化は M_j が 1 であれば A_j,\ B_j 間が぀ながれたこずを衚し M_j が 2 であれば A_j,\ B_j 間の接続が切れたこずを衚す 出力圢匏 各倉化の盎埌における動画サむトからハコの魔女の持぀コンピュヌタたでの転送速床を出力せよ 制玄 2 \leq N \leq 500 0 \leq E \leq 20,000 1 \leq Q \leq 1,000 1 \leq F_i \leq N,\ 1 \leq T_i \leq N,\ F_i \neq T_i \ (1 \leq i \leq E) すべおの \{F_i, T_i\} のペアは異なる 1 \leq M_j \leq 2,\ 1 \leq A_j \leq N\ ,\ 1 \leq B_j \leq N\ ,\ A_j \neq B_j (1 \leq j \leq Q) ネットワヌクのどの段階においおも次のこずが成り立぀ : どの 2 ぀の転送装眮の間も高々 1 ぀の回線でしか繋がれおいない 2 ぀の転送装眮の間が既に繋がれおいる状態でそれらの間を接続するようなク゚リが来たり 2 ぀の転送装眮の間が回線で繋がれおいない状態でそれらの間の接続を切るようなク゚リが来るこずはない 入出力䟋 入力䟋 1 2 1 2 1 2 2 1 2 1 2 1 出力䟋1 0 1 最初の倉化の埌ハコの魔女のコンピュヌタず動画サむトは繋がらなくなっおいるので転送速床は 0 である 2 床目の倉化の埌は䞡者は盎接繋がっおおり転送速床は 1 になる 入力䟋 2 3 0 4 1 2 3 1 2 1 1 3 1 2 2 3 出力䟋 2 0 1 2 1 入力䟋 3 6 4 8 1 2 1 3 4 6 5 6 1 2 4 1 3 5 1 2 5 1 3 4 2 2 4 2 3 5 1 2 4 2 2 1 出力䟋 3 1 2 2 2 2 2 2 1 入力䟋 4 12 38 6 1 2 1 3 1 4 1 5 2 3 2 4 2 5 2 6 2 7 2 8 2 12 3 4 3 5 3 6 3 7 3 8 4 5 4 6 4 7 4 8 5 6 5 7 5 8 6 7 6 8 6 9 6 10 6 12 7 8 7 9 7 10 8 9 8 10 9 10 9 11 9 12 10 11 11 12 2 6 12 2 9 12 1 9 12 1 6 12 2 6 12 1 6 12 出力䟋 4 3 2 3 4 3 4 Problem Setter: Flat35
36,651
Problem C: Live Schedule YOKARI TAMURAは党囜的に有名なアヌティストである。今月YOKARIは D 日間にわたっおラむブツアヌを行う。ツアヌのスケゞュヌルの決定においおこの囜を C 皮類の地域でわける。YOKARIがある地域でラむブを行うこずにより利益を埗られ、これは正の敎数で衚される。YOKARIは原則ずしお 1 日に最倧 1 ぀たでラむブを行う。ただし、ある地域でラむブを行った埌、隣接する地域でラむブを行える堎合はその地域で同じ日に再びラむブを行うこずができる。この条件を満たす限り、地域を移動しながら䜕床もラむブを行うこずができる。たた、同じ日に同じ地域でラむブを 2 床以䞊行うこずはできない。さらに、同じ日に 2 回以䞊のラむブを行う日の数はツアヌ期間䞭合蚈 X 以䞋でなければならない。 あなたはYOKARIの関係者であり、圌女のラむブツアヌのスケゞュヌルを仮決めしなくおはならない。どの日にどの地域でラむブを行えばもっずも有益だろうか。ただし 1 回のラむブごずにYOKARIには非負の敎数で衚される負担がかかり、ツアヌ期間䞭の合蚈負担は W 以内でなければならない。あなたの仕事は各ラむブでYOKARIにかかる負担ず期埅される利益を読み蟌み、スケゞュヌルを仮決めしお、利益合蚈の最倧倀を出力するこずである。 Input 入力は耇数のテストケヌスからなる。 ひず぀のテストケヌスは以䞋の圢匏に埓う。 C D W X E 1,1 E 1,1 
 E 1,D E 2,1 E 2,1 
 E 2,D 
 E C,1 E C,2 
 E C,D F 1,1 F 1,1 
 F 1,D F 2,1 F 2,1 
 F 2,D 
 F C,1 F C,2 
 F C,D C は地域の皮類数、D はツアヌ期間の長さ、W はこのツアヌでYOKARIに蚱容される負担の合蚈の最倧倀、X はツアヌ期間䞭にラむブを同じ日に 2 床以䞊行える合蚈日数の䞊限である。 E i,j ( 1 ≀ i ≀ C か぀ 1 ≀ j ≀ D ) は地域 i で j 日目にラむブを行うこずで期埅される利益である。E i,j が 0 のずき地域 i で j 日目にラむブを行えないこずを瀺す。 F i,j ( 1 ≀ i ≀ C か぀ 1 ≀ j ≀ D ) は地域 i で j 日目にラむブを行うこずでYOKARIにかかる負担である。E i,j が 0 のずき、この倀は0である。 地域 i は地域 i + 1 ず i - 1 それぞれに隣接する。ただし地域 1 ず地域 C ( C > 2 ) は隣接しない。 入力の終わりは、4個の0がそれぞれ䞀文字の空癜で区切られる䞀行で瀺される。 Constraints 入力はすべお敎数 1 ≀ C ≀ 15 1 ≀ D ≀ 30 0 ≀ W ≀ 50 0 ≀ X ≀ 5 0 ≀ E i,j ≀ 1,000 0 ≀ F i,j ≀ 10 テストケヌスの数は 100 を超えない。 Output 各ケヌスに付き、スケゞュヌルを仮決めしお期埅される利益合蚈の最倧倀を 1 行に出力せよ。 Sample Input 5 5 10 2 1 1 0 1 1 0 9 1 0 1 1 1 1 9 1 1 1 9 0 1 1 1 1 1 0 1 1 0 1 1 0 9 1 0 1 1 1 1 9 1 1 1 1 0 1 1 1 1 1 0 1 1 10 0 3 7 1 1 5 0 3 6 1 2 10 1 6 7 5 6 2 1 10 1 4 8 3 7 2 1 10 0 4 8 3 7 2 1 5 0 4 8 3 6 0 0 0 0 Sample Output 18 3 0 7 12 8 4
36,652
Separate String You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$. For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \{a, ab, b\}$. $a,b,a,b$ $a,b,ab$ $ab,a,b$ $ab,ab$ Your task is to count the number of ways to separate $t$. Because the result can be large, you should output the remainder divided by $1,000,000,007$. Input The input consists of a single test case formatted as follows. $N$ $s_1$ : $s_N$ $t$ The first line consists of an integer $N$ ($1 \leq N \leq 100,000$) which is the number of the elements of $S$. The following $N$ lines consist of $N$ distinct strings separated by line breaks. The $i$-th string $s_i$ represents the $i$-th element of $S$. $s_i$ consists of lowercase letters and the length is between $1$ and $100,000$, inclusive. The summation of length of $s_i$ ($1 \leq i \leq N$) is at most $200,000$. The next line consists of a string $t$ which consists of lowercase letters and represents the string to be separated and the length is between $1$ and $100,000$, inclusive. Output Calculate the number of ways to separate $t$ and print the remainder divided by $1,000,000,007$. Sample Input 1 3 a b ab abab Output for Sample Input 1 4 Sample Input 2 3 a b c xyz Output for Sample Input 2 0 Sample Input 3 7 abc ab bc a b c aa aaabcbccababbc Output for Sample Input 3 160 Sample Input 4 10 a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Output for Sample Input 4 461695029
36,653
FizzBuzz 「Fizz Buzz」ず蚀われる数字を䜿ったゲヌムがありたす。このゲヌムは耇数のプレむダヌで数字を1 から順にひず぀ず぀数え䞊げおいくもので、各プレむダヌは盎前のプレむダヌが発蚀した次の数字をひず぀だけ発蚀したす。その時、3 で割り切れる堎合は 「Fizz」, 5 で割り切れる堎合は 「Buzz」、䞡者で割り切れる堎合は「FizzBuzz」ず数の代わりに発蚀しなければなりたせん。䟋えば、最初の 16 たでの発蚀は以䞋のようになりたす。 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, ・・・ 倪郎君は友達ず「Fizz Buzz」をしお遊ぶこずにしたした。倪郎君たちはルヌルを次のように決めたした。 「間違えた人は脱萜する。その次の人は間違えた数の次の数から始める。぀たり、1, 2, 3 ず発蚀した堎合、3 で間違えたので次は 4 から始めるこずになる。」 このルヌルに埓っおゲヌムを行うのですが、ゲヌムに慣れおいないため、間違えたこずに気付かないこずがあり、公平な刀断ができたせん。そこであなたは倪郎君たちがこのゲヌムを楜しめるように、決められた発蚀回数が終わった時点で残っおいた人を出力するプログラムを䜜成するこずにしたした。 プレむダヌ数、ゲヌム䞭に発蚀された回数、それぞれの発蚀を入力ずし、入力が終わった時点で残っおいるプレむダヌの番号を小さい順に出力するプログラムを䜜成しおください。ただし、プレむダヌには 1 から番号が割り振られおおり、発蚀順番も 1 番目のプレむダヌから順に行い、䞀通り発蚀が終わるず、再床 1 番目のプレむダヌから発蚀するこずずしたす。順番の回っおきたプレむダヌが既に脱萜しおいる堎合は、その次のプレむダヌが発蚀したす。たた、このプログラムは、プレむダヌが䞀人になった時点で、その埌の発蚀を無芖しなければなりたせん。 Input 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 m n s 1 s 2 : s n 1 行目にプレむダヌ数 m (2 ≀ m ≀ 1000) ず発蚀回数 n (1 ≀ n ≀ 10000) が䞎えられたす。 続く n 行に i 番目の発蚀 s 1 が䞎えられたす。 s i は敎数、Fizz、Buzz、たたは FizzBuzz を瀺す文字列8文字以䞋です。 デヌタセットの数は 50 を超えたせん。 Output 入力デヌタセットごずに、指定された発蚀回数たで入力されたずきに残っおいるプレむダヌの番号を小さい順に出力したす。 Sample Input 5 7 1 2 Fizz 4 Buzz 6 7 3 5 1 2 3 4 5 0 0 Output for the Sample Input 2 3 4 5 1
36,654
Score : 200 points Problem Statement Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice. Given is a string S . Find the minimum number of hugs needed to make S palindromic. Constraints S is a string consisting of lowercase English letters. The length of S is between 1 and 100 (inclusive). Input Input is given from Standard Input in the following format: S Output Print the minimum number of hugs needed to make S palindromic. Sample Input 1 redcoder Sample Output 1 1 For example, we can change the fourth character to o and get a palindrome redooder . Sample Input 2 vvvvvv Sample Output 2 0 We might need no hugs at all. Sample Input 3 abcdabc Sample Output 3 2
36,655
長幎の研究の末、むクタ君は未来予知胜力を手に入れた 圌がこの研究に費やした時間や金銭は莫倧なものであったが、぀いに報われる時がやっおきたのだ。手始めに金銭を取り戻すため、むクタ君は株匏投資を始めるこずにした。 むクタ君は珟圚株匏は党く保有しおおらず、 x 円を所持しおいる。圌が投資察象に定めた株匏は n 皮類で、それらに぀いお今日から d 日分の株䟡を予知するこずに成功した。その結果、驚くべきこずに今日から d 日間は日䞭の株䟡倉動が党くないこずが刀明した。぀たり、今日を1日目ずしたずきの i  1 ≀ i ≀ d 日目の株匏 j  1 ≀ j ≀ n の株䟡 p i,j 円がわかっおいる。むクタ君はそれぞれの日に自由に株匏を売買できる。すなわち、任意の時点で以䞋の操䜜賌入・売华を任意の順番で任意の回数行える。ただし、各操䜜の前埌での所持金ず株匏の保有単䜍数は非負敎数でなければならない。 賌入 : i 日目に、株匏の皮類 j  1 ≀ j ≀ n を䞀぀遞び、所持金 p i,j 円を支払い1単䜍の株匏 j を埗る。 売华 : i 日目に、株匏の皮類 j  1 ≀ j ≀ n を䞀぀遞び、1単䜍の株匏 j を支払い p i,j 円を埗る。 圌が研究に没頭する間に蚌刞取匕システムは倧きな発達を遂げ、取匕手数料はかからなくなった。 むクタ君は倧孊で情報科孊を修めおいたが、未来予知研究に明け暮れるすえに倧孊で孊んだこずをすべお忘れおしたっおいた。そんな圌の代わりに最終日の所持金を最倧化するプログラムを曞いおあげおほしい。 Input 入力は以䞋の圢匏で䞎えられる。 n d x p 1,1 ... p 1,n ... p d,1 ... p d,n n : 株匏の皮類数 d : 日数 x : 1日目の所持金 p i,j : i 日目の銘柄 j の株䟡今日を1日目ずする Constraints 入力䞭の各倉数は以䞋の制玄を満たす敎数である。 1 ≀ n ≀ 10 1 ≀ d ≀ 10 1 ≀ x, p i,j ≀ 10 5 最終日の所持金が 10 5 以䞋ずなるこずが保蚌されおいる。 Output 最適に投資した堎合の最終日の所持金を1行に出力せよ。 Sample Input 1 2 2 5 3 2 5 4 Output for the Sample Input 1 9 䟋えば、それぞれの株匏を1単䜍ず぀賌入したす。 Sample Input 2 1 2 5 6 10000 Output for the Sample Input 2 5 1単䜍より小さい取匕はできたせん。小口投資家の悲哀です。 Sample Input 3 2 3 5 4 5 6 3 8 5 Output for the Sample Input 3 11 1日目は1皮類目の株匏に、2日目は2皮類目の株匏に投資したす。 Sample Input 4 3 3 10 10 9 6 8 7 3 7 5 1 Output for the Sample Input 4 10 景気が悪い時もありたす。
36,656
Score : 500 points Problem Statement Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N , and wrote 0 at each edge. Then, Aoki gave him M queries. The i -th of them is as follows: Increment the number written at each edge along the path connecting vertices a_i and b_i , by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi. Constraints 2 ≀ N ≀ 10^5 1 ≀ M ≀ 10^5 1 ≀ a_i,b_i ≀ N a_i ≠ b_i Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_M b_M Output Print YES if there exists a tree that has the property mentioned by Takahashi; print NO otherwise. Sample Input 1 4 4 1 2 2 4 1 3 3 4 Sample Output 1 YES For example, Takahashi's graph has the property mentioned by him if it has the following edges: 1-2 , 1-3 and 1-4 . In this case, the number written at every edge will become 2 . Sample Input 2 5 5 1 2 3 5 5 1 3 4 2 3 Sample Output 2 NO
36,657
Problem A: Ennichi 瞁日に来たうさぎが, ある出店のゲヌムの景品がキャロットケヌキであるのを芋぀けた. このゲヌムのルヌルは以䞋の通りである. 瞊h マス× 暪w マスの栌子状のフィヌルドがあり, 各マスに぀き高々1 個のブロックが眮かれる. 各ブロックにはアルファベット倧文字(‘A’ - ‘Z’) のいずれかで衚される色が぀いおいる. 同色のブロックが瞊たたは暪に䞀盎線䞊にn 個以䞊連続しお䞊ぶず, それらのブロックは消滅する. 参加者は暪に隣り合う2 ぀のマスを遞んで, それらの状態を互いに入れ替える操䜜ができる. ブロックの入れ替え, 消滅, 萜䞋によっおブロックの有るマスの1 ぀䞋のマスにブロックが無くなるず, このブロックは萜䞋する. このずきふたたび同色のブロックがn 個以䞊䞊ぶず消滅する. ただし, ブロックの消滅は, 萜䞋するブロックが存圚する間は起こらず, すべおのブロックの萜䞋が終了したタむミングで同時に起こる. 1 回の操䜜でフィヌルド䞊のすべおのブロックを消滅させるず, このゲヌムは成功ずなり景品のケヌキを埗るこずができる. うさぎは1 回分の参加費で確実にケヌキを手に入れたく, それができない堎合は参加したくない. ゲヌム開始時のフィヌルドの状態から, うさぎがこのゲヌムに参加すべきであるか答えよ. Input 入力の䞀行目にはh, w, n がスペヌスで区切られお䞎えられる. 2 ≀ h , w , n ≀ 30 続く h 行にはフィヌルドの状態が䞊から順に䞎えられる. アルファベット倧文字はブロックを, ‘.’ は空きマスを衚す. 䞎えられるフィヌルドの状態には, 瞊あるいは暪に n 個以䞊連続する同色のブロックはなく, 萜䞋する状態にあるブロックもない. 1 個以䞊のブロックが存圚する. Output うさぎがこのゲヌムに参加すべきであるなら”YES”を, そうでないなら”NO”を䞀行に出力せよ. Sample Input 1 4 6 3 ...... ...Y.. ...Y.. RRYRYY Sample Output 2 YES Sample Input 1 4 6 3 ...... ...Y.. ...Y.. RRYRY. Sample Output 2 NO
36,658
Problem L: Tree Fragments Problem あいちゃんは、$N$個の頂点ず$N-1$本の蟺からなる朚$T$を持っおいる。各頂点には$1$から$N$たでの番号ず、正の敎数の重みが぀いおいる。 次の$Q$回のク゚リに順に答えよ。 $1 \le a_i,b_i \le N$($a_i \ne b_i$)が䞎えられるので、$T$の$a_i$-$b_i$パス䞊の頂点ずそれに接続する蟺を取り陀いおできる、いく぀かの連結成分の䞭で、重みが最倧ずなる連結成分の重みを出力する。そのような連結成分が1぀もない堎合、0ず出力する。 ただし、連結成分の重みはその連結成分に含たれる頂点の重みの和で定矩される。 Input 入力は以䞋の圢匏で䞎えられる。 $N$ $w_1$ $w_2$ ... $w_N$ $u_1$ $v_1$ $u_2$ $v_2$ ... $u_{N-1}$ $v_{N-1}$ $Q$ $a_1$ $b_1$ $a_2$ $b_2$ ... $a_Q$ $b_Q$ 入力はすべお敎数で䞎えられる。 1行目に$T$の頂点数$N$が䞎えられる。 2行目に頂点$i$($1 \le i \le N$)の重み$w_i$が空癜区切りで䞎えられる。 3行目以降の$N$-1行に蟺$_i$($1 \le i \le N-1$)の端点$u_i,v_i$が空癜区切りで䞎えられる。 $N$+2行目にク゚リの数$Q$が䞎えられる。 $N$+3行目以降の$Q$行に、ク゚リ$_i$($1 \le i \le Q$)を衚す$a_i,b_i$が空癜区切りで䞎えられる。 Constraints 入力は以䞋の条件を満たす。 $2 \le N \le 10^5$ $1 \le Q \le 10^5$ $1 \le w_i \le 10^8$($1 \le i \le N$) $1 \le u_i,v_i \le N$($1 \le i \le N-1$) $u_i \ne v_i$ $i \ne j$なら$(u_i,v_i) \ne (u_j,v_j)$か぀$(u_i,v_i) \ne (v_j, u_j)$ $1 \le a_i,b_i \le N$($1 \le i \le Q$) $a_i \ne b_i$ Ouput ク゚リ毎に、0たたは重みが最倧ずなる連結成分の重みを1行に出力する。 Sample Input 1 10 1 2 3 4 5 6 7 8 9 10 1 2 2 3 3 4 3 5 2 6 6 7 2 8 8 9 8 10 3 3 8 7 1 7 10 Sample Output 1 13 27 12 Sample Input 2 5 1 2 3 4 5 1 2 2 3 3 4 4 5 3 1 2 1 5 2 4 Sample Output 2 12 0 5 Sample Input 3 15 3 8 4 2 6 5 1 2 10 3 4 2 6 1 1 1 2 2 3 3 4 3 5 2 6 6 7 6 8 1 9 9 10 10 11 10 12 9 13 13 14 13 15 5 1 1 2 7 6 10 1 15 3 4 Sample Output 3 28 30 12 28 46
36,660
出珟頻床操䜜 有限数列の倉換操䜜に出珟頻床操䜜ずいうものがありたす。数列 $S = \{s_1, s_2,... s_n\}$ の倉換結果は同じ長さの数列ずなりたす。その結果を $C = \{c_1,c_2, ..., c_n\}$ ずするず、 $c_i$ は数列 $S$ における $s_i$ の個数を衚したす。 䟋えば $S = \{3,4,1,5,9,2,6,5,3\}$ ならば $C = {2,1,1,2,1,1,1,2,2}$ ずなりたす。さらにこの数列 $C$ に出珟頻床操䜜を行うず $P = \{4,5,5,4,5,5,5,4,4\}$ を埗たす。この数列は出珟頻床操䜜で倉わるこずがありたせん。このような数列 $P$ を数列 $S$ の䞍動点ず呌びたす。どのような数列に察しおも出珟頻床操䜜を繰り返せば、その䞍動点を求めるこずが出来るずいうこずが知られおいたす。 䞋の䟋は出珟頻床操䜜の手順を瀺したものです。1 行目を数列 $S$ 、2 行目を数列 $C$、最終行を数列 $P$ ずしたす。数列 $S$ の最初の芁玠($s_1 = 2$) ず同じ数は 3 個あるので数列 $C$ の最初の芁玠 $c_1$ は 3、次の芁玠 ($s_2 = 7$) ず同じ数は 2 個あるので $c_2 = 2$、ずいった具合に個数を数え $c_i$ を求めおいきたす。 数列の長さ $n$ ず数列 $S$ を入力し、䞍動点の数列 $P$ および、$P$ を埗るために実行した出珟頻床操䜜の最小の回数を出力するプログラムを䜜成しおください。 Input 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 $n$ $s_1$ $s_2$ ... $s_n$ 1 行目に数列の長さを衚す敎数 $n$ ($n \leq 12$) が䞎えられたす。行目に数列 $S$ の芁玠を衚す敎数 $s_i$ ($1 \leq s_i \leq 100$) が空癜区切りで䞎えられたす。 入力は䞀぀の行で終わりたす。デヌタセットの数は 200 を超えたせん。 Output 各デヌタセットに぀いお、行目に出珟頻床操䜜の最小の実行回数(敎数)、行目に察応する䞍動点の数列 $P$ の芁玠 $p_1$, $p_2$, ..., $p_n$ を空癜区切りで出力しおください。 Sample Input 10 4 5 1 1 4 5 12 3 5 4 0 Output for the Sample Input 3 6 6 4 4 6 6 4 4 6 6
36,661
Score : 100 points Problem Statement Consider placing N flags on a line. Flags are numbered through 1 to N . Flag i can be placed on the coordinate X_i or Y_i . For any two different flags, the distance between them should be at least D . Decide whether it is possible to place all N flags. If it is possible, print such a configulation. Constraints 1 \leq N \leq 1000 0 \leq D \leq 10^9 0 \leq X_i < Y_i \leq 10^9 All values in Input are integer. Input Input is given from Standard Input in the following format: N D X_1 Y_1 X_2 Y_2 \vdots X_N Y_N Output Print No if it is impossible to place N flags. If it is possible, print Yes first. After that, print N lines. i -th line of them should contain the coodinate of flag i . Sample Input 1 3 2 1 4 2 5 0 6 Sample Output 1 Yes 4 2 0 Sample Input 2 3 3 1 4 2 5 0 6 Sample Output 2 No
36,662
ヘビの JOI 君 (Snake JOI) 問題 ヘビの JOI 君はある倧きな屋敷に迷い蟌んでしたった屋敷の䜏人に芋぀かる前に屋敷を脱出しなければならない この屋敷には郚屋が N 個あり1, 2, ..., N の番号が付けられおいるたた廊䞋が M 本ありi 本目の廊䞋 (1 ≩ i ≩ M) は郚屋 A i ず郚屋 B i を結んでいるJOI 君はこれらの廊䞋をどちらの向きにも通るこずができ廊䞋 i を通るのには D i 分かかる郚屋ず郚屋の間を廊䞋を通る以倖の手段で移動する方法はない この屋敷の郚屋の枩床はそれぞれ䞀定に調節されおおりJOI 君にずっお寒すぎるか快適であるか暑すぎるかであるJOI 君は急な枩床倉化に察応できないため最埌に寒すぎる郚屋を出おから X 分未満のうちに暑すぎる郚屋に入るこずはできない同様に最埌に暑すぎる郚屋を出おから X 分未満のうちに寒すぎる郚屋に入るこずもできない JOI 君は移動䞭に郚屋に入るずすぐに郚屋から出なければならないたた廊䞋の途䞭で匕き返したり廊䞋 i を D i 分より長い時間かけお通るこずもできないただし䞀床蚪れた郚屋にもう䞀床入るこずや䞀床䜿った廊䞋をもう䞀床䜿うこずは蚱される JOI 君は珟圚郚屋 1 にいるこの郚屋は JOI 君にずっお寒すぎるJOI 君は屋敷の出口のある郚屋 N に入るず屋敷から脱出できる JOI 君が屋敷から脱出するのにかかる最短の時間を求めよ 入力 入力は 1 + N + M 行からなる 1 行目には3 個の敎数 N, M, X (2 ≩ N ≩ 10000, 1 ≩ M ≩ 20000, 1 ≩ X ≩ 200) が空癜を区切りずしお曞かれおいるこれは屋敷に N 個の郚屋ず M 本の廊䞋がありJOI 君が枩床倉化に察応するのに X 分かかるこずを衚す 続く N 行のうちの i 行目 (1 ≩ i ≩ N) には郚屋 i の枩床を衚す敎数 T i (0 ≩ T i ≩ 2) が曞かれおいるJOI 君にずっお郚屋 i はT i = 0 のずき寒すぎT i = 1 のずき快適でありT i = 2 のずき暑すぎるT 1 = 0 であるこずが保蚌されおいる 続く M 行のうちの j 行目 (1 ≩ j ≩ M) には3 個の敎数 A j , B j , D j (1 ≩ A j < B j ≩ N, 1 ≩ D j ≩ 200) が空癜を区切りずしお曞かれおいるこれは廊䞋 j が郚屋 A j ず郚屋 B j を結んでおり通るのに D j 分かかるこずを衚す同じ郚屋の組を結ぶ廊䞋が耇数ある可胜性があるこずに泚意せよ 䞎えられる入力デヌタではJOI 君が屋敷から脱出できるこずは保蚌されおいる 出力 JOI 君が屋敷から脱出するのに最短で䜕分かかるかを衚す敎数を 1 行で出力せよ 入出力䟋 入力䟋 1 8 10 4 0 1 1 2 1 1 2 0 1 2 1 1 3 1 2 3 3 2 4 5 3 4 1 4 5 1 5 6 1 5 8 1 1 7 2 7 8 2 出力䟋 1 9 入力䟋 2 15 25 4 0 1 1 0 2 1 0 1 1 2 0 0 1 0 1 8 11 1 7 10 1 12 14 1 3 8 1 1 5 1 3 9 1 3 8 1 1 5 1 6 15 1 11 12 1 2 14 1 7 10 1 11 12 1 5 13 1 2 8 1 1 4 1 2 11 1 5 6 1 1 13 1 6 12 1 5 10 1 9 13 1 4 10 1 3 12 1 7 13 1 出力䟋 2 6 入力䟋 1 では郚屋を 1 → 2 → 3 → 4 → 5 → 6 → 5 → 8 の順に移動するのが最短ずなる 入力䟋 2 ではいく぀かの郚屋の組 (たずえば郚屋 1 ず郚屋 5) を結ぶ廊䞋が耇数ある 情報オリンピック日本委員䌚䜜 『第 16 回日本情報オリンピック JOI 2016/2017 予遞競技課題』
36,663
Problem Statement One day (call it day 0), you find a permutation $P$ of $N$ integers written on the blackboard in a single row. Fortunately you have another permutation $Q$ of $N$ integers, so you decide to play with these permutations. Every morning of the day 1,2,3,... , you rewrite every number on the blackboard in such a way that erases the number $x$ and write the number $Q_x$ at the same position. Please find the minimum non-negative integer $d$ such that in the evening of the day $d$ the sequence on the blackboard is sorted in increasing order. Input The input consists of a single test case in the format below. $N$ $P_1$ $\ldots$ $P_N$ $Q_1$ $\ldots$ $Q_N$ The first line contains an integer $N$ ($1 \leq N \leq 200$). The second line contains $N$ integers $P_1,\ldots,P_N$ ($1 \leq P_i \leq N$) which represent the permutation $P$. The third line contains $N$ integers $Q_1,\ldots,Q_N$ ($1 \leq Q_i \leq N$) which represent the permutation $Q$. Output Print the minimum non-negative integer $d$ such that in the evening of the day $d$ the sequence on the blackboard is sorted in increasing order. If such $d$ does not exist, print -1 instead. It is guaranteed that the answer does not exceed $10^{18}$. Examples Input Output 6 2 3 1 4 5 6 3 1 2 5 4 6 4 6 1 2 3 4 5 6 3 1 2 5 4 6 0 6 2 3 1 4 5 6 3 4 5 6 1 2 -1
36,664
Shuffle Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h , and prints the final state (a string). Input The input consists of multiple datasets. Each dataset is given in the following format: A string which represents a deck The number of shuffle m h 1 h 2 . . h m The input ends with a single character '-' for the string. Constraints The length of the string ≀ 200 1 ≀ m ≀ 100 1 ≀ h i < The length of the string The number of datasets ≀ 10 Output For each dataset, print a string which represents the final state in a line. Sample Input aabc 3 1 2 1 vwxyz 2 3 4 - Sample Output aabc xyzvw
36,665
Score : 500 points Problem Statement You are given a sequence with N integers: A = \{ A_1, A_2, \cdots, A_N \} . For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied: If A_i and A_j (i < j) are painted with the same color, A_i < A_j . Find the minimum number of colors required to satisfy the condition. Constraints 1 \leq N \leq 10^5 0 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print the minimum number of colors required to satisfy the condition. Sample Input 1 5 2 1 4 5 3 Sample Output 1 2 We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1 , 4 , and 5 blue. Sample Input 2 4 0 0 0 0 Sample Output 2 4 We have to paint all the integers with distinct colors.
36,666
Score : 300 points Problem Statement Snuke and Raccoon have a heap of N cards. The i -th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y , respectively. They would like to minimize |x-y| . Find the minimum possible value of |x-y| . Constraints 2 \leq N \leq 2 \times 10^5 -10^{9} \leq a_i \leq 10^{9} a_i is an integer. Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N} Output Print the answer. Sample Input 1 6 1 2 3 4 5 6 Sample Output 1 1 If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10 , y=11 , and thus |x-y|=1 . This is the minimum possible value. Sample Input 2 2 10 -10 Sample Output 2 20 Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10 , y=-10 , and thus |x-y|=20 .
36,667
Score : 300 points Problem Statement You are given a string S of length N and another string T of length M . These strings consist of lowercase English letters. A string X is called a good string when the following conditions are all met: Let L be the length of X . L is divisible by both N and M . Concatenating the 1 -st, (\frac{L}{N}+1) -th, (2 \times \frac{L}{N}+1) -th, ... , ((N-1)\times\frac{L}{N}+1) -th characters of X , without changing the order, results in S . Concatenating the 1 -st, (\frac{L}{M}+1) -th, (2 \times \frac{L}{M}+1) -th, ... , ((M-1)\times\frac{L}{M}+1) -th characters of X , without changing the order, results in T . Determine if there exists a good string. If it exists, find the length of the shortest such string. Constraints 1 \leq N,M \leq 10^5 S and T consist of lowercase English letters. |S|=N |T|=M Input Input is given from Standard Input in the following format: N M S T Output If a good string does not exist, print -1 ; if it exists, print the length of the shortest such string. Sample Input 1 3 2 acp ae Sample Output 1 6 For example, the string accept is a good string. There is no good string shorter than this, so the answer is 6 . Sample Input 2 6 3 abcdef abc Sample Output 2 -1 Sample Input 3 15 9 dnsusrayukuaiia dujrunuma Sample Output 3 45
36,668
C - ゜ヌシャル 問題文 うさぎが N 匹おりボヌトを䜿っお川を枡ろうずしおいるボヌトは K 個あり誰がどのボヌトに乗るかを適圓に決めお乗るこずにした ずころでうさぎずいうのは互いの仲の良し悪しに敏感であり狭い空間に仲の悪いうさぎず䞀緒に閉じ蟌められるず気分を悪くしおしたう この N 匹のうさぎに぀いおも䜕組かのうさぎは仲が悪いずいうこずが分かっおおり今の割り圓おでは䜕匹かは気分を悪くしおしたう可胜性がある もっず良い割り圓おを考えるのがよいずころではあるがひずたず今の割り圓おで䜕匹のうさぎが気分を悪くするかを求めお欲しい 入力圢匏 入力は以䞋の圢匏で䞎えられる N K m 1 bunny 1,1 ... bunny 1,m 1 m 2 bunny 2,1 ... bunny 2,m 2 ... m K bunny K,1 ... bunny K,m K R p 1 q 1 ... p R q R N はボヌトに乗るうさぎの数である K はボヌトの個数である m i はボヌト i に乗るうさぎの数である bunny i,1 , ..., bunny i,m i はボヌト i に乗るうさぎの番号 (1 以䞊 N 以䞋) を衚す R は仲の悪いうさぎの組の個数を衚す p j , q j はうさぎ p j ずうさぎ q j の仲が悪いこずを衚す 出力圢匏 気分を悪くするうさぎの数を出力せよ 制玄 1 ≀ N ≀ 50 1 ≀ K ≀ N m 1 + ... + m K = N {bunny 1,1 , ..., bunny 1,m 1 , bunny 2,1 , ..., bunny K,m K } = {1, 2, ..., N} 0 ≀ R ≀ N(N-1)/2 1 ≀ p j < q j ≀ N 組 (p j , q j ) は党お異なる 入力倀はすべお敎数である 入出力䟋 入力䟋 1 6 2 2 1 5 4 2 3 4 6 2 1 2 2 5 出力䟋 1 0 気分を悪くしおいるうさぎはいない 入力䟋 2 6 2 2 1 5 4 2 3 4 6 3 2 3 3 4 1 2 出力䟋 2 3 割り圓おは䟋 1 ず同じであるが仲の悪さを衚す組が異なっおいるこの䟋ではうさぎ 2,3,4 が気分を悪くしおしたう 入力䟋 3 10 3 3 4 1 9 3 10 5 2 4 3 8 7 6 9 3 4 1 2 1 9 6 8 1 6 1 8 6 7 6 10 7 8 出力䟋 3 5 Writer: 楠本充 Tester: 小浜翔倪郎
36,669
Problem B: Headstrong Student You are a teacher at a cram school for elementary school pupils. One day, you showed your students how to calculate division of fraction in a class of mathematics. Your lesson was kind and fluent, and it seemed everything was going so well - except for one thing. After some experiences, a student Max got so curious about how precise he could compute the quotient. He tried many divisions asking you for a help, and finally found a case where the answer became an infinite fraction. He was fascinated with such a case, so he continued computing the answer. But it was clear for you the answer was an infinite fraction - no matter how many digits he computed, he wouldn’t reach the end. Since you have many other things to tell in today’s class, you can’t leave this as it is. So you decided to use a computer to calculate the answer in turn of him. Actually you succeeded to persuade him that he was going into a loop, so it was enough for him to know how long he could compute before entering a loop. Your task now is to write a program which computes where the recurring part starts and the length of the recurring part, for given dividend/divisor pairs. All computation should be done in decimal numbers. If the specified dividend/divisor pair gives a finite fraction, your program should treat the length of the recurring part as 0. Input The input consists of multiple datasets. Each line of the input describes a dataset. A dataset consists of two positive integers x and y , which specifies the dividend and the divisor, respectively. You may assume that 1 ≀ x < y ≀ 1,000,000. The last dataset is followed by a line containing two zeros. This line is not a part of datasets and should not be processed. Output For each dataset, your program should output a line containing two integers separated by exactly one blank character. The former describes the number of digits after the decimal point before the recurring part starts. And the latter describes the length of the recurring part. Sample Input 1 3 1 6 3 5 2 200 25 99 0 0 Output for the Sample Input 0 1 1 1 1 0 2 0 0 2
36,670
Problem C: TransferTrain うなぎは電車に乗るのが奜きである. いたうなぎは駅 A から駅 B ぞ電車を䜿っお行こうずしおいる. うなぎは急いでいるので, 最短時間の経路を遞ぶこずにした. ただしうなぎは乗り換えが苊手なので, 最短時間の経路が耇数ある堎合は最も乗り換え回数の少ない経路を遞ぶこずにした. $N$ 本の路線がある. $i$ 本目の路線は $a_i$ 個の駅を通っおいる. $i$ 本目の路線の通る駅名は通る順に $s_{i,0}, ... , s_{i,a_i -1}$ であり, 駅間の所芁時間は $t_{i,0}, ..., t_{i,a_i - 2}$ である. 電車は路線䞊を䞊䞋方向に走っおおり, 入力で䞎えられた逆順に乗るこずもできる. 耇数の路線の同じ駅名は同じ駅を衚しおおり乗り換えをするこずが出来る. 乗り換えには駅や路線によらず $T$ 分かかる. 䞀本の路線が同じ駅を耇数回通るこずもあるもし同じ路線同じ駅の路線内で異なる䜍眮の駅に移動したい堎合は乗り換えをする必芁がある. たずえば, C - D - E - F - D - G ずいう路線を䜿っお C から G たで行く堎合, 始点から終点たで䞀本の電車で行くこずもD 駅で乗り換えお C - D, D - G ず乗るこずもできる. うなぎが駅 A から駅 B ぞ行くのにかかる時間ず乗り換え回数を求めよ. 電車はずおも頻繁に来るので埅ち時間は無芖しおよい. Constraints $N$ will be between 1 and 50,000, inclusive. $T$ will be an integer between 1 and 1,000, inclusive. At least one train stops at A. At least one train stops at B. A and B will be distinct. $a_i$ will be bigger than or equal to 2. $a_1 + ... + a_N$ will be between 2 and 100,000, inclusive. $s_{i,j}$ will contain between 1 and 10 characters, inclusive. Each character in $s_{i,j}$ will be a letter ('A'-'Z', 'a'-'z'). $t_{i,j}$ will be an integer between 1 and 1,000, inclusive. Input 入力は以䞋の圢匏で䞎えられる: $N$ $T$ $A$ $B$ $a_1$ $s_{1,1}$ ... $s_{1,a_1}$ $t_{1,1}$ ... $t_{1,a_1 -1}$ ... $a_N$ $s_{N,1}$ ... $s_{N,a_N}$ $t_{N,1}$ ... $t_{N,a_N-1}$ Output うなぎが駅 A から駅 B ぞ行くのにかかる時間ず乗り換え回数を空癜で区切っお1 行に出力せよ. Sample Input 1 2 10 Warsaw Petersburg 3 Kiev Moscow Petersburg 150 120 3 Moscow Minsk Warsaw 100 150 Sample Output 1 380 1 Sample Input 2 2 10 Warsaw Petersburg 3 Kiev Moscow Petersburg 150 120 2 Minsk Warsaw 150 Sample Output 2 -1
36,671
ニュヌタりン 䌚接県では人口増加のためにニュヌタりンを䜜るこずにしたした。そのために、新たに長方圢の土地を開拓し、この土地を䜙すずころなく、すべお同じ倧きさの正方圢からなる区画に区切るこずを決めたした。この土地の敎備には、区画数に比䟋した費甚がかかりたすが、県ずしおはこの費甚を最小にしたいず考えおいたす。 新たに開拓した土地の東西方向ず南北方向の長さず、区画圓たりの敎備費甚が䞎えられたずき、すべおの区画を敎備したずきにかかる、最小の敎備費甚を求めるプログラムを䜜成せよ。 Input 入力は以䞋の圢匏で䞎えられる。 W H C 入力は行であり、新たに開拓した土地の東西方向の長さ W (1 ≀ W ≀ 1000)ず南北方向の長さ H (1 ≀ H ≀ 1000)、区画圓たりの敎備費甚 C (1 ≀ C ≀ 1000)が敎数で䞎えられる。 Output 土地を敎備するために必芁な最小の費甚を行に出力する。 Sample Input 1 10 20 5 Sample Output 1 10 個の正方圢で土地を䜙すずころなく区切るこずができ、区画圓たりの敎備費甚がなので、ず 出力する。 Sample Input 2 27 6 1 Sample Output 2 18 個の正方圢で土地を䜙すずころなく区切るこずができ、区画圓たりの敎備費甚がなので、ず出力する。
36,672
Railway Connection Tokyo has a very complex railway system. For example, there exists a partial map of lines and stations as shown in Figure D-1. Figure D-1: A sample railway network Suppose you are going to station D from station A. Obviously, the path with the shortest distance is A→B→D. However, the path with the shortest distance does not necessarily mean the minimum cost. Assume the lines A-B, B-C, and C-D are operated by one railway company, and the line B-D is operated by another company. In this case, the path A→B→C→D may cost less than A→B→D. One of the reasons is that the fare is not proportional to the distance. Usually, the longer the distance is, the fare per unit distance is lower. If one uses lines of more than one railway company, the fares charged by these companies are simply added together, and consequently the total cost may become higher although the distance is shorter than the path using lines of only one company. In this problem, a railway network including multiple railway companies is given. The fare table (the rule to calculate the fare from the distance) of each company is also given. Your task is, given the starting point and the goal point, to write a program that computes the path with the least total fare. Input The input consists of multiple datasets, each in the following format. n m c s g x 1 y 1 d 1 c 1 ... x m y m d m c m p 1 ... p c q 1,1 ... q 1, p 1 -1 r 1,1 ... r 1, p 1 ... q c ,1 ... q c,p c -1 r c ,1 ... r c,p c Every input item in a dataset is a non-negative integer. Input items in the same input line are separated by a space. The first input line gives the size of the railway network and the intended trip. n is the number of stations (2 ≀ n ≀ 100). m is the number of lines connecting two stations (0 ≀ m ≀ 10000). c is the number of railway companies (1 ≀ c ≀ 20). s is the station index of the starting point (1 ≀ s ≀ n ). g is the station index of the goal point (1 ≀ g ≀ n , g ≠ s ). The following m input lines give the details of (railway) lines. The i -th line connects two stations x i and y i (1 ≀ x i ≀ n , 1 ≀ y i ≀ n , x i ≠ y i ). Each line can be traveled in both directions. There may be two or more lines connecting the same pair of stations. d i is the distance of the i -th line (1 ≀ d i ≀ 200). c i is the company index of the railway company operating the line (1 ≀ c i ≀ c ). The fare table (the relation between the distance and the fare) of each railway company can be expressed as a line chart. For the railway company j , the number of sections of the line chart is given by p j (1 ≀ p j ≀ 50). q j,k (1 ≀ k ≀ p j -1) gives the distance separating two sections of the chart (1 ≀ q j,k ≀ 10000). r j,k (1 ≀ k ≀ p j ) gives the fare increment per unit distance for the corresponding section of the chart (1 ≀ r j,k ≀ 100). More precisely, with the fare for the distance z denoted by f j ( z ), the fare for distance z satisfying q j , k -1 +1 ≀ z ≀ q j , k is computed by the recurrence relation f j ( z ) = f j ( z -1)+ r j,k . Assume that q j ,0 and f j (0) are zero, and q j , p j is infinity. For example, assume p j = 3, q j ,1 = 3, q j ,2 = 6, r j ,1 = 10, r j ,2 = 5, and r j ,3 = 3. The fare table in this case is as follows. distance 1 2 3 4 5 6 7 8 9 fare 10 20 30 35 40 45 48 51 54 q j,k increase monotonically with respect to k . r j,k decrease monotonically with respect to k . The last dataset is followed by an input line containing five zeros (separated by a space). Output For each dataset in the input, the total fare for the best route (the route with the minimum total fare) should be output as a line. If the goal cannot be reached from the start, output "-1". An output line should not contain extra characters such as spaces. Once a route from the start to the goal is determined, the total fare of the route is computed as follows. If two or more lines of the same railway company are used contiguously, the total distance of these lines is used to compute the fare of this section. The total fare of the route is the sum of fares of such "sections consisting of contiguous lines of the same company". Even if one uses two lines of the same company, if a line of another company is used between these two lines, the fares of sections including these two lines are computed independently. No company offers transit discount. Sample Input 4 4 2 1 4 1 2 2 1 2 3 2 1 3 4 5 1 2 4 4 2 3 1 3 6 10 5 3 10 2 0 1 1 2 1 1 4 5 2 4 1 4 3 10 1 3 2 2 1 3 2 1 2 3 2 5 2 2 1 10 1 3 3 20 30 3 2 1 5 10 3 2 1 5 5 2 1 5 1 2 10 2 1 3 20 2 2 4 20 1 3 4 10 1 4 5 20 1 2 2 20 4 1 20 3 1 0 0 0 0 0 Output for the Sample Input 54 -1 63 130
36,673
G: 塗るだけ / Paint 問題文 情倪くんず立子さんは 平面の䞖界にある庭付きの家に䜏んでいる二人は点ずみなせ 庭は $N$ 頂点の単玔倚角圢 (隣り合わないどの $2$ 蟺も亀差も接觊もしない倚角圢) の圢をしおいる ある日二人は䞀本の䌞び瞮みするロヌラヌを手に入れた ロヌラヌは線分ずみなせロヌラヌが通過した領域に色を塗るこずができる 二人はロヌラヌを䜿っお庭党䜓に色を塗りたいず思っおいる 䜜業の前に二人は以䞋のような準備を䞊から順に行う 庭の内郚の任意の $1$ 箇所に杭を打぀ 庭の倖郚のある $1$ 点に集たる 十分に長い玐を甚意し片方の端を情倪くんもう䞀方の端を立子さんの䜓に結ぶ 情倪くんがロヌラヌの片方の端を立子さんがもう䞀方の端を持぀ 準備ができたら以䞋のルヌルに埓っお塗り始める ただしロヌラヌは杭の䞊空を通過させるこずができるが玐はできない 庭のどの郚分から塗り始めおもよい 庭の倖郚たたは呚䞊を移動できるが内郚に入っおはいけない 塗り終わるたでロヌラヌから手を離しおはいけない さらに塗り終わったずきに以䞋の条件を満たしおいなければならない 二人が再びある $1$ 点に集たっおいる 庭の内郚の任意の点の䞊をロヌラヌが通過しおいる 二人の䜓の玐を解き䞡端を結んで茪を䜜るこの茪を倖から匕っ匵ったずきに杭に匕っかかっお抜けない さお二人はできるだけ離れたくないので塗っおいる最䞭にずる二人の距離の最倧倀を最小化したい 二人に代わっおそのような倀を求めおほしい 入力 入力は以䞋の圢匏で䞎えられる$N$ は倚角圢を構成する頂点の数 $(x_i,y_i)$ はある頂点から始めお時蚈回りたたは反時蚈回りに芋たずきの $i$ 番目の点の座暙である $N$ $x_1 \ y_1$ $\vdots$ $x_N \ y_N$ 制玄 $3 \leq N \leq 50$ $|x_i|, |y_i| \leq 100$ 党お敎数である 頂点は時蚈回りたたは反時蚈回りに䞎えられる 庭の圢は単玔倚角圢である 呚䞊の連続する $3$ 点は䞀盎線䞊に存圚しない 出力 答えを $1$ 行で出力せよ$10^{-5}$ 未満の絶察誀差は蚱容される サンプル 各サンプルでの庭の圢ず塗り終わるたでのロヌラヌの動きを図瀺するず以䞋のようになる敎数は時刻を衚す図瀺する郜合䞊ロヌラヌの動きは飛び飛びに瀺したが,実際には連続的に動いおいる ロヌラヌが倪くなっおいる郚分で距離の最倧倀を達成しおいる サンプル入力1 4 0 0 0 1 1 1 1 0 サンプル出力1 1 サンプル入力2 3 0 0 0 1 1 0 サンプル出力2 0.7071067811865476 サンプル入力3 8 0 0 5 0 5 3 0 3 0 2 4 2 4 1 0 1 サンプル出力3 1.4142135623730951
36,674
孊食 今日は倧孊のオヌプンキャンパスです。毎幎この日の昌䌑みには、倧勢の高校生たちが孊食に列を぀くりたす。そこで倧孊の事務局は、行列の長さが最倧でどのくらいの距離になるかを予枬するこずにしたした。事前調査の結果で、以䞋のこずが分かっおいたす。 行列にはそれぞれ 1 から N たでの番号が振られた N 人が䞊びたす。 C 個の高校生のペア ( a i , b i ) それぞれに぀いお、以䞋の皮類の制玄がありたす ぀目の制玄は順序に関するもので以䞋のいずれかです a i は b i よりも先、たたは同じ䜍眮に䞊ばなくおはならない a i は b i よりも埌、たたは同じ䜍眮に䞊ばなくおはならない a i は b i より先でも、同じ䜍眮でも、埌でもよい ぀目の制玄は距離に関するもので以䞋のいずれかです a i ず b i は d i メヌトル以䞊離れなければならない a i ず b i は d i メヌトル以内に䞊ばなければならない たた、先頭から同じ距離の堎所に耇数の人が䞊ぶこずができ、行列の先頭には垞に番号 1 の人が䞊ぶこずが分かっおいたす。 䞎えられた C 個の制玄をすべお満たす行列に぀いお、先頭から最埌尟たでの距離が最倧ずなるような䞊び方をした堎合の距離を求めるプログラムを䜜成しおください。ただし、どこたでも離れるこずができる堎合は inf ず、制玄を満たす䞊び方が䞍可胜な堎合は -1 ず出力しおください。 入力 入力は以䞋の圢匏で䞎えられる。 N C constraint 1 constraint 2 : constraint C 1 行目に行列に䞊ぶ高校生の人数 N (2 ≀ N ≀ 100) ず制玄の数 C (0 ≀ C ≀ 200) が䞎えられる。続く C 行に各制玄 constraint i が次の圢匏で䞎えられる。 a i o i b i s i d i 制玄には空癜は含たれない。 a i , o i , b i , s i , d i の意味を以䞋に瀺す。 a i ず b i (1 ≀ a i , b i ≀ N か぀ a i ≠ b i ) は高校生の番号、 d i は距離 (0 ≀ d ≀ 10000) を衚す敎数である。 o i は順序の制玄を指定する <= 、 >= 、 * のいずれかの文字列であり、 <= の堎合「 a i は b i よりも先、たたは同じ䜍眮に䞊ばなくおはならない」、 >= の堎合「 a i は b i よりも埌、たたは同じ䜍眮に䞊ばなくおはならない」、 * の堎合「 a i は b i より先でも、同じ䜍眮でも、埌でもよい」こずを意味する。ただし o i が * ずなる制玄は個以䞊䞎えられるこずはない。 s i は距離の制玄を指定する + たたは - の文字であり、 + の堎合「 a i ず b i は d i メヌトル以䞊離れなければならない」、 - の堎合「 a i ず b i は d i メヌトル以内に䞊ばなければならない」こずを意味する。 ただし、あるペアに察しお耇数の制玄が䞎えられるこずはないものずする。 出力 先頭から最埌尟たでの距離を行に出力する。 入出力䟋 入力䟋 3 2 1<=2-1 2<=3-2 出力䟋 3 入力䟋 3 3 1<=2-1 2<=3-2 1<=3+4 出力䟋 -1 入力䟋 3 2 1<=2-2 2*3+1 出力䟋 inf
36,675
陣圢 プログラマヌ逊成校であるアカベ高校では、チヌム戊の競技プログラマヌの圹割を以䞋のタむプに分けおいたす。  コヌダヌ 蚀語を熟知しおおり、コヌディングを行う。  アルゎリズマヌ 論理的思考が埗意であり、アルゎリズムを考える。  ナビゲヌタヌ 読解力に長けおおり、問題の分析・デバッグをする。 この高校では以䞋のいずれかの陣圢で人䞀組のチヌムを構成しおいたす。  バランスがずれおいる安定型  スピヌドを芋蟌めるがリスクの高い速攻型  正確に問題を解く慎重型 競技プログラミング郚のコヌチであるあなたは、これらの郚員をうたく組み合わせ、できるだけ倚くのチヌムを結成できるよう、毎幎気を配っおいたす。そこで、コヌダヌの人数、アルゎリズマヌの人数、ナビゲヌタヌの人数が入力ずしお䞎えられたずき、最倧䜕チヌム䜜れるかを出力するプログラムを䜜成しおください。 入力 入力は1぀のデヌタセットからなる。入力デヌタは以䞋の圢匏で䞎えられる。 Q c 1 a 1 n 1 c 2 a 2 n 2 : c Q a Q n Q 1行目の Q (0 ≀ Q ≀ 100)はチヌム数を求めたい幎数である。続く Q 行に各幎の圹割別の人数が䞎えられる。各行にはコヌダヌの人数 c i (0 ≀ c i ≀ 1000)、アルゎリズマヌの人数 a i (0 ≀ a i ≀ 1000)、ナビゲヌタヌの人数 n i (0 ≀ n i ≀ 1000)が䞎えられる。 出力 幎ごずに、䜜成できる最倧のチヌム数を1行に出力する。 入力䟋 4 3 0 0 1 1 1 9 4 1 0 1 2 出力䟋 1 1 4 0
36,676
Problem F: Chocolate with Heart Marks 倪郎君はチョコレヌトが倧奜きで, 孊校から垰るずハヌトマヌクが描かれたお気に入りの板チョコを食べたす, 最近の楜しみは, すべおのハヌトマヌクのブロックを最埌たで残すように食べるこずです. 倪郎君は, すべおのハヌトマヌクのブロックが぀ながったたた, できるだけ倚くのハヌトマヌクのないブロックを食べようずしたす. しかし倪郎君はただ幌く, 䞊蚘のように食べようずしおも無駄なブロックが残っおしたいたす. そこで倪郎君は, すべおのハヌトマヌクのブロックを぀ながったたた残すずきに食べられる最倧のブロック数を求めるプログラムの䜜成をあなたに䟝頌したした. 倪郎君は, すべおのハヌトマヌクのブロックが぀ながっおいる限り、どんな食べ方をしおもかたいたせん. ブロックのいずれか䞀蟺が他のブロックに接しおいないず分かれおいるこずになりたす. Input 入力は耇数のデヌタセットからなりたす. 各デヌタセットは以䞋の圢匏で䞎えられたす: H W H × W 個の数字 H , W はそれぞれ板チョコの瞊のサむズ, 暪のサむズを瀺す敎数です. H × W 個の数字はブロックの情報を衚し, ハヌトマヌクのないブロックを衚す ' 0 ', ハヌトマヌクのブロックを衚す ' 1 ' から構成されたす. 入力の終了は, H = W = 0 であるデヌタセットによっお瀺されたす. このケヌスに察しお出力をしおはいけたせん. 1 ≀ H , W ≀ 12 であり、ハヌトマヌクのブロックの数は 6 個以䞋ず仮定しおかたいたせん. Output それぞれのデヌタセットに察しお, 倪郎君が食べられる最倧のブロック数を出力しおください. Sample Input 4 4 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 1 1 2 3 1 0 0 0 0 1 0 0 Output for the Sample Input 7 0 2
36,677
D: 次元旅行 問題 次元が $1$ 次元から $N$ 次元たで存圚する。 AORむカちゃんは次元間を移動できる。 具䜓的には、AORむカちゃんが $i$ 次元にいるずき、 $j$ 次元( $i > j$ )には自由に移動する事ができるが、 $k$ 次元( $i < k$ )に移動するには魔法を䜿う必芁がある。 AORむカちゃんは $M$ 皮類の魔法が䜿え、 $1, 2, \dots, M$ ず番号が振られおいる。 $i$ 番目の魔法では $a_i$ 次元から $b_i$ 次元に移動できる。 これは $a_i$ 次元にいるずきしか䜿えない。 $i$ 次元に行くず次元特有の「次元の呪い」を受ける。 $i$ 次元の「次元の呪い」により、AORむカちゃんは $d_i$ ダメヌゞを負う。 $i$ 次元の「次元の呪い」を受けた堎合、その埌ずっず、 $j$ 次元( $i > j$ )の「次元の呪い」は受けない。 AORむカちゃんが $s$ 次元から $t$ 次元に移動するずき、 負うダメヌゞの合蚈の最小倀を求めよ。 ただし、AORむカちゃんは既に $s$ 次元の「次元の呪い」は受けおおり、そのダメヌゞは考えないものずする。 たた、AORむカちゃんは $t$ 次元に行けるこずが保蚌されおいる。 制玄 $2 \leq N \leq 10^5$ $1 \leq M \leq min(10^5, N \times (N - 1) / 2)$ $1 \leq s, t \leq N$ $s \neq t$ $1 \leq d_i \leq 10^3$ $1 \leq a_i < b_i \leq N$ $i \neq j$ のずき $( a_i \neq a_j$ たたは $b_i \neq b_j )$ をみたす 入力は党お敎数で䞎えられる。 入力圢匏 入力は以䞋の圢匏で䞎えられる。 $N \ M \ s \ t$ $d_1 \dots d_N$ $a_1 \ b_1$ $a_2 \ b_2$ $\vdots$ $a_M \ b_M$ 出力 AORむカちゃんが受けるダメヌゞの合蚈の最小倀を出力せよ。たた、末尟に改行も出力せよ。 サンプル サンプル入力 1 3 1 2 3 1 2 3 1 3 サンプル出力 1 3 サンプル入力 2 3 2 1 2 1 3 2 1 2 1 3 サンプル出力 2 2 サンプル入力 3 7 5 2 3 277 390 2 784 401 641 917 2 5 5 6 1 5 2 4 5 7 サンプル出力 3 401
36,679
問題文 2぀の敎数 $A$$B$ がある。 十進数での筆算によっお $A - B$ を求める凊理を以䞋に瀺す。 1. $A$$B$ を十進数で衚珟する。添字は䞋䜍から順に $0,1,2,...,n-1$ ずし、 $A = A_{n-1} A_{n-2} ... A_{0}$$B = B_{n-1} B_{n-2} ... B_{0}$ ずする。 $n$ は十進数で衚珟した時の$A$の桁数ずする。 $B$ の桁数が $n$ より小さいずき、䞊䜍桁に $0$ を補う。 2. $borrow_{0} = 0$ ずする。 3. 以䞋の凊理を $i = 0$ から $n-1$ たで繰り返す。 3.1. $A_{i} - borrow_{i} \geq B_{i}$ ならば、 $C_{i} = A_{i} - borrow_{i} - B_{i}$  $borrow_{i+1} = 0$ずする。 3.2. $A_{i} - borrow_{i} \lt B_{i}$ ならば、 $C_{i} = A_{i} - borrow_{i} + 10 - B_{i}$  $borrow_{i+1} = 1$ずする。 $A - B$ の蚈算結果は $C_{n-1} C_{n-2} ... C_{0}$ ずなる。ただし、最䞊䜍に連続する $0$ は取り陀く。 繰り䞋がりを忘れるず3.2の凊理での $borrow_{i+1} = 1$ が $borrow_{i+1} = 0$ ずなる。 最倧 $K$ 回繰り䞋がりを忘れたずきの蚈算結果の最倧倀を求めよ。 入力 入力は以䞋の圢匏に埓う。䞎えられる数は党お敎数である。 $A$ $B$ $K$ 制玄 $1 \leq B \lt A \leq 10^9$ $1 \leq K \leq 9$ 出力 蚈算結果の最倧倀を1行に出力せよ。 Sample Input 1 99 98 1 Output for the Sample Input 1 1 Sample Input 2 100 2 3 Output for the Sample Input 2 198 Sample Input 3 538 84 1 Output for the Sample Input 3 554 Sample Input 4 2012 1987 1 Output for the Sample Input 4 1025
36,680
Problem A: A White Wall Background ずある郜垂に䜏む氏の家の敷地は、真っ癜な壁に囲たれおいる。壁に物足りなさを感じた氏は、近所の子䟛たちを呌んで、壁を自由に塗っおもらうこずにした。子䟛達にはそれぞれ壁の奜きな区間を遞んで色を塗っおもらう。 さお、壁はどのように塗られただろうか。 Problem 0〜 N -1の区画で構成される以䞋のような円型の癜い壁がある。 M 人の子䟛たちがこの壁の開始䜍眮 a ず開始䜍眮からの長さ L を指定し、反時蚈回りに a から (a+L) mod N たで色を塗る(ただし、 a mod N ずは、 a を N で割ったずきの䜙りを衚す)。ここで、他の人が色を塗った区間ず重ねお塗るこずもでき、その堎合は、色が塗られた1぀の区間ずみなす。色が塗られた区間を倧きい順に出力せよ。たた、その倧きさの区間がいく぀あるかも同時に出力せよ。 Input 入力は以䞋の圢匏で䞎えられる。 N M a 0 L 0 a 1 L 1 ... a M−1 L M−1 1行目にそれぞれ壁の長さず壁に色を塗る人の数を衚す2぀の敎数 N , M が空癜区切りで䞎えられる。続く M 行には、各人が色を塗る区間の開始䜍眮 a i ず長さ L i が䞎えられる。 Constrains 入力は以䞋の条件を満たす 2 ≀ N ≀ 100 1 ≀ M ≀ 50 0 ≀ a i < N 1 ≀ L i ≀ N Output 色が塗られた区間の長さずその長さの総数を色が塗られた区間が倧きい順に出力する。 Sample Input 1 5 3 0 1 2 1 3 1 Sample Output 1 2 1 1 1 Sample Input 2 4 2 0 2 1 2 Sample Output 2 3 1 Sample Input 3 10 3 2 1 4 1 9 2 Sample Output 3 2 1 1 2
36,681
Problem A: AOJ50M Problem AliceずBobが50m走で勝負しおいたす。 しかし、この䞖界においおはAOJのレヌトが高い方が偉いので、AOJのレヌトが高い方が勝ちたす。 どちらか䞀方でもAOJのレヌトが無い堎合は比べようが無いので、仕方なく50m走のタむムで勝負したす。この堎合はタむムが短い方を勝ちずしたす。 AOJのレヌトが同じ堎合は匕き分け、50m走のタむムで勝負しなければならない堎合はタむムが同じなら匕き分けです。 Input 入力は以䞋の圢匏で䞎えられる。 $T_1$ $T_2$ $R_1$ $R_2$ 各芁玠が空癜区切りで䞎えられる。 $T_1,T_2$ はそれぞれAlice、Bobの50m走のタむムを、$R_1,R_2$ はそれぞれAlice、BobのAOJのレヌトを衚す。 ただし、$R_1=-1$ のずきはAliceのレヌトがないこずを、$R_2=-1$ のずきはBobのレヌトがないこずを瀺す。 Constraints 入力は以䞋の条件を満たす。 $1 \leq T_1,T_2 \lt 100 $ $-1 \leq R_1,R_2 \lt 2850 $ 入力は党お敎数である Output Aliceが勝぀ならなら"Alice"を、Bobが勝぀ならなら"Bob"を、匕き分けであれば"Draw"を$1$行に出力せよ。 Sample Input 1 9 8 1000 999 Sample Output 1 Alice Aliceの方がAOJのレヌトが高いため、Aliceの勝ちです。 Sample Input 2 9 8 1000 1000 Sample Output 2 Draw AliceずBobのAOJのレヌトが同じため、匕き分けです。この堎合50m走の結果は関係がないこずに泚意しおください。 Sample Input 3 9 8 2849 -1 Sample Output 3 Bob Aliceのレヌトは高いですが、Bobのレヌトが無いため50m走のタむムが短いBobの勝ちです。
36,682
Score: 100 points Problem Statement E869120's and square1001's 16 -th birthday is coming soon. Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces. E869120 and square1001 were just about to eat A and B of those pieces, respectively, when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake". Can both of them obey the instruction in the note and take desired numbers of pieces of cake? Constraints A and B are integers between 1 and 16 (inclusive). A+B is at most 16 . Input Input is given from Standard Input in the following format: A B Output If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay! ; otherwise, print :( . Sample Input 1 5 4 Sample Output 1 Yay! Both of them can take desired number of pieces as follows: Sample Input 2 8 8 Sample Output 2 Yay! Both of them can take desired number of pieces as follows: Sample Input 3 11 4 Sample Output 3 :( In this case, there is no way for them to take desired number of pieces, unfortunately.
36,683
Score : 200 points Problem Statement You are given a string S . Each character of S is uppercase or lowercase English letter. Determine if S satisfies all of the following conditions: The initial character of S is an uppercase A . There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive). All letters except the A and C mentioned above are lowercase. Constraints 4 ≀ |S| ≀ 10 ( |S| is the length of the string S .) Each character of S is uppercase or lowercase English letter. Input Input is given from Standard Input in the following format: S Output If S satisfies all of the conditions in the problem statement, print AC ; otherwise, print WA . Sample Input 1 AtCoder Sample Output 1 AC The first letter is A , the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied. Sample Input 2 ACoder Sample Output 2 WA The second letter should not be C . Sample Input 3 AcycliC Sample Output 3 WA The last letter should not be C , either. Sample Input 4 AtCoCo Sample Output 4 WA There should not be two or more occurrences of C . Sample Input 5 Atcoder Sample Output 5 WA The number of C should not be zero, either.
36,684
Score : 300 points Problem Statement There are N towns in a coordinate plane. Town i is located at coordinates ( x_i , y_i ). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2} . There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots , towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths. Constraints 2 \leq N \leq 8 -1000 \leq x_i \leq 1000 -1000 \leq y_i \leq 1000 \left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j ) (Added 21:12 JST) All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the average length of the paths. Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6} . Sample Input 1 3 0 0 1 0 0 1 Sample Output 1 2.2761423749 There are six paths to visit the towns: 1 → 2 → 3 , 1 → 3 → 2 , 2 → 1 → 3 , 2 → 3 → 1 , 3 → 1 → 2 , and 3 → 2 → 1 . The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2} . By calculating the lengths of the other paths in this way, we see that the average length of all routes is: \frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142... Sample Input 2 2 -879 981 -866 890 Sample Output 2 91.9238815543 There are two paths to visit the towns: 1 → 2 and 2 → 1 . These paths have the same length. Sample Input 3 8 -406 10 512 859 494 362 -955 -475 128 553 -986 -885 763 77 449 310 Sample Output 3 7641.9817824387
36,685
Score : 100 points Problem Statement Dolphin loves programming contests. Today, he will take part in a contest in AtCoder. In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as " 21 o'clock". The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time. Constraints 0 \leq A,B \leq 23 A and B are integers. Input The input is given from Standard Input in the following format: A B Output Print the hour of the starting time of the contest in 24-hour time. Sample Input 1 9 12 Sample Output 1 21 In this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time. Sample Input 2 19 0 Sample Output 2 19 The contest has just started. Sample Input 3 23 2 Sample Output 3 1 The contest will begin at 1 o'clock the next day.
36,686
Score : 300 points Problem Statement You are given integers N and K . Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K . The order of a,b,c does matter, and some of them can be the same. Constraints 1 \leq N,K \leq 2\times 10^5 N and K are integers. Input Input is given from Standard Input in the following format: N K Output Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K . Sample Input 1 3 2 Sample Output 1 9 (1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition. Sample Input 2 5 3 Sample Output 2 1 Sample Input 3 31415 9265 Sample Output 3 27 Sample Input 4 35897 932 Sample Output 4 114191
36,687
Score : 400 points Problem Statement For an integer N , we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\} . Then, for each i=1,2,...,N , let M_i be the remainder when i is divided by P_i . Find the maximum possible value of M_1 + M_2 + \cdots + M_N . Constraints N is an integer satisfying 1 \leq N \leq 10^9 . Input Input is given from Standard Input in the following format: N Output Print the maximum possible value of M_1 + M_2 + \cdots + M_N . Sample Input 1 2 Sample Output 1 1 When the permutation \{P_1, P_2\} = \{2, 1\} is chosen, M_1 + M_2 = 1 + 0 = 1 . Sample Input 2 13 Sample Output 2 78 Sample Input 3 1 Sample Output 3 0
36,688
Problem F: Directional Resemblance Vectors have their directions and two vectors make an angle between them. Given a set of three-dimensional vectors, your task is to find the pair among them that makes the smallest angle. Input The input is a sequence of datasets. A dataset specifies a set of three-dimensional vectors, some of which are directly given in the dataset and the others are generated by the procedure described below. Each dataset is formatted as follows. m n S W x 1 y 1 z 1 x 2 y 2 z 2 : x m y m z m The first line contains four integers m , n , S , and W . The integer m is the number of vectors whose three components are directly specified in the dataset. Starting from the second line, m lines have the three components of m vectors. The i -th line of which indicates the vector v i = ( x i , y i , z i ). All the vector components are positive integers less than or equal to 100. The integer n is the number of vectors generated by the following procedure. int g = S; for(int i=m+1; i<=m+n; i++) { x[i] = (g/7) %100 + 1; y[i] = (g/700) %100 + 1; z[i] = (g/70000)%100 + 1; if( g%2 == 0 ) { g = (g/2); } else { g = (g/2) ^ W; } } For i = m + 1, . . . , m + n , the i -th vector v i of the set has three components x[i] , y[i] , and z[i] generated by this procedure. Here, values of S and W are the parameters S and W given in the first line of the dataset. You may assume 1 ≀ S ≀ 10 9 and 1 ≀ W ≀ 10 9 . The total number of vectors satisfies 2 ≀ m + n ≀ 12 × 10 4 . Note that exactly the same vector may be specified twice or more in a single dataset. A line containing four zeros indicates the end of the input. The total of m+n for all the datasets in the input never exceeds 16 × 10 5 . Output For each dataset, output the pair of vectors among the specified set with the smallest non-zero angle in between. It is assured that there are at least two vectors having different directions. Vectors should be indicated by their three components. The output for a pair of vectors v a and v b should be formatted in a line as follows. x a y a z a x b y b z b Two vectors ( x a , y a , z a ) and ( x b , y b , z b ) are ordered in the dictionary order, that is, v a < v b if x a < x b , or if x a = x b and y a < y b , or if x a = x b , y a = y b and z a < z b . When a vector pair is output, the smaller vector in this order should be output first. If more than one pair makes the equal smallest angle, the pair that is the smallest among them in the dictionary order between vector pairs should be output. The pair ( v i , v j ) is smaller than the pair ( v k , v l ) if v i < v k , or if v i = v k and v j < v l . Sample Input 4 0 2013 1124 1 1 1 2 2 2 2 1 1 1 2 1 2 100 131832453 129800231 42 40 46 42 40 46 0 100000 7004674 484521438 0 0 0 0 Output for the Sample Input 1 1 1 1 2 1 42 40 46 83 79 91 92 92 79 99 99 85
36,689
Score : 200 points Problem Statement The word internationalization is sometimes abbreviated to i18n . This comes from the fact that there are 18 letters between the first i and the last n . You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way. Constraints 3 ≀ |s| ≀ 100 ( |s| denotes the length of s .) s consists of lowercase English letters. Input Input is given from Standard Input in the following format: s Output Print the abbreviation of s . Sample Input 1 internationalization Sample Output 1 i18n Sample Input 2 smiles Sample Output 2 s4s Sample Input 3 xyz Sample Output 3 x1z
36,690
Multiplication of Big Integers II Given two integers $A$ and $B$, compute the product, $A \times B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the product in a line. Constraints $-1 \times 10^{200000} \leq A, B \leq 10^{200000}$ Sample Input 1 5 8 Sample Output 1 40 Sample Input 2 100 25 Sample Output 2 2500 Sample Input 3 -1 0 Sample Output 3 0 Sample Input 4 12 -3 Sample Output 4 -36
36,691
M: プレれント (Presents) 癜矜さんは、ずある悪魔にサプラむズプレれントずしお次のような集合を甚意した。 $N$ 以䞋の異なる $K$ 個の自然数からなる どの 2 ぀の倀の組を集合から遞んでも、片方の数がもう片方の数で割り切れる 実はこのような集合には悪魔の力を奪う性質があり、このたただず力を倱っおしたう。 悪魔を助けるために、このような集合がいく぀あるか蚈算せよ。 入力 2 ぀の敎数 $N, K$ が空癜区切りで䞎えられる。 出力 条件を満たす集合の個数を出力せよ。 制玄 $N$ は $1$ 以䞊 $100 \ 000$ 以䞋の敎数 $K$ は $1$ 以䞊 $N$ 以䞋の敎数 入力䟋1 6 3 出力䟋1 3 集合 $(1,2,4), (1,2,6), (1,3,6)$ が条件を満たす。 入力䟋2 100000 7 出力䟋2 58848855 $N = 100 \ 000, K = 7$ のずき、条件を満たす集合は $58 \ 848 \ 855$ 通りある。
36,692
C: 足し算掛け算 / AddMul 問題文 情倪くんは a から z たでの文字ず 足し算の蚘号 + しか知りたせん 情倪くんには姉の立子さんがいたす 立子さんはそれに加えお掛け算 * ず括匧 (  )  そしお 1 以䞊 9 以䞋の敎数 (数字) も知っおいたす しかし括匧を倚重に䜿甚するこず括匧の䞭で掛け算を行うこずは知りたせん 䟋えば次のような数匏があったずしたす a+a+a a+4*(b+c) a+3*(b+2*(c+d)) a-b a/b 11*a このうち情倪くんは 1. のみ立子さんは 1. ず 2. を曞くこずができたす 3. から 6. は二人ずも曞くこずができたせん ある日情倪くんは文字列ずしおの長さが $n$ の倚項匏 $S$ を曞きたした ショヌトコヌダヌの立子さんは掛け算ず括匧ず 1 以䞊 9 以䞋の敎数を䜿っお$S$ を文字列ずしおより短い恒等な倚項匏 $T$ に曞きなおしおやりたいず思っおいたす しかしそう簡単ではないようです さお立子さんのかわりに文字列ずしお最も短い $T$ を䜜り その長さを出力するプログラムを曞いおください 入力 $N$ $S$ 制玄 $1 \leq N \leq 499$ $N$ は奇数である $S$ は a から z たでのアルファベット小文字ず + のみからなる $S$ の最初の文字はアルファベットでありその埌 + ずアルファベット $1$ 文字が亀互に䞊ぶ $S$ に同じアルファベットは $9$ 個以䞋しか含たれない 出力 答えを $1$ 行で出力しおください サンプル サンプル入力1 5 a+a+a サンプル出力1 3 a*3 の $3$ 文字が最短です サンプル入力2 9 a+a+b+a+b サンプル出力2 7 a*3+2*b たたは a*3+b+b の $7$ 文字が最短です サンプル入力3 11 a+a+b+a+b+b サンプル出力3 7 (a+b)*3 で $7$ 文字 サンプル入力4 3 a+a サンプル出力4 3 a+a たたは a*2 で $3$ 文字
36,693
Score : 200 points Problem Statement You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i -th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j -th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i -th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i -th refrigerator and the y_i -th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required. Constraints All values in input are integers. 1 \le A \le 10^5 1 \le B \le 10^5 1 \le M \le 10^5 1 \le a_i , b_i , c_i \le 10^5 1 \le x_i \le A 1 \le y_i \le B c_i \le a_{x_i} + b_{y_i} Input Input is given from Standard Input in the following format: A B M a_1 a_2 ... a_A b_1 b_2 ... b_B x_1 y_1 c_1 \vdots x_M y_M c_M Output Print the answer. Sample Input 1 2 3 1 3 3 3 3 3 1 2 1 Sample Output 1 5 With the ticket, you can get the 1 -st refrigerator and the 2 -nd microwave for 3+3-1=5 yen. Sample Input 2 1 1 2 10 10 1 1 5 1 1 10 Sample Output 2 10 Note that you cannot use more than one ticket at a time. Sample Input 3 2 2 1 3 5 3 5 2 2 2 Sample Output 3 6 You can get the 1 -st refrigerator and the 1 -st microwave for 6 yen, which is the minimum amount to pay in this case. Note that using a ticket is optional.
36,694
Vampire Mr. C is a vampire. If he is exposed to the sunlight directly, he turns into ash. Nevertheless, last night, he attended to the meeting of Immortal and Corpse Programmers Circle, and he has to go home in the near dawn. Fortunately, there are many tall buildings around Mr. C's home, and while the sunlight is blocked by the buildings, he can move around safely. The top end of the sun has just reached the horizon now. In how many seconds does Mr. C have to go into his safe coffin? To simplify the problem, we represent the eastern dawn sky as a 2-dimensional x - y plane, where the x axis is horizontal and the y axis is vertical, and approximate building silhouettes by rectangles and the sun by a circle on this plane. The x axis represents the horizon. We denote the time by t , and the current time is t =0. The radius of the sun is r and its center is at (0, - r ) when the time t =0. The sun moves on the x - y plane in a uniform linear motion at a constant velocity of (0, 1) per second. The sunlight is blocked if and only if the entire region of the sun (including its edge) is included in the union of the silhouettes (including their edges) and the region below the horizon (y ≀ 0). Write a program that computes the time of the last moment when the sunlight is blocked. The following figure shows the layout of silhouettes and the position of the sun at the last moment when the sunlight is blocked, that corresponds to the first dataset of Sample Input below. As this figure indicates, there are possibilities that the last moment when the sunlight is blocked can be the time t =0. The sunlight is blocked even when two silhouettes share parts of their edges. The following figure shows the layout of silhouettes and the position of the sun at the last moment when the sunlight is blocked, corresponding to the second dataset of Sample Input. In this dataset the radius of the sun is 2 and there are two silhouettes: the one with height 4 is in -2 ≀ x ≀ 0, and the other with height 3 is in 0 ≀ x ≀ 2. Input The input consists of multiple datasets. The first line of a dataset contains two integers r and n separated by a space. r is the radius of the sun and n is the number of silhouettes of the buildings. (1 ≀ r ≀ 20, 0 ≀ n ≀ 20) Each of following n lines contains three integers x li , x ri , h i (1 ≀ i ≀ n ) separated by a space. These three integers represent a silhouette rectangle of a building. The silhouette rectangle is parallel to the horizon, and its left and right edges are at x = x li and x = x ri , its top edge is at y = h i , and its bottom edge is on the horizon. (-20 ≀ x li < x ri ≀ 20, 0 < h i ≀ 20) The end of the input is indicated by a line containing two zeros separated by a space. Note that these silhouettes may overlap one another. Output For each dataset, output a line containing the number indicating the time t of the last moment when the sunlight is blocked. The value should not have an error greater than 0.001. No extra characters should appear in the output. Sample Input 2 3 -2 -1 3 0 1 3 2 3 3 2 2 -2 0 4 0 2 3 2 6 -3 3 1 -2 3 2 -1 3 3 0 3 4 1 3 5 2 3 6 2 6 -3 3 1 -3 2 2 -3 1 3 -3 0 4 -3 -1 5 -3 -2 6 0 0 Output for the Sample Input 0.0000 3.0000 2.2679 2.2679
36,695
Edit Distance (Levenshtein Distance) Find the edit distance between given two words s1 and s2 . The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations: insertion : Insert a character at a particular position. deletion : Delete a character at a particular position. substitution : Change the character at a particular position to a different character Input s1 s2 Two words s1 and s2 are given in the first line and the second line respectively. The words will consist of lower case characters. Output Print the edit distance in a line. Constraints 1 ≀ length of s1 ≀ 1000 1 ≀ length of s2 ≀ 1000 Sample Input 1 acac acm Sample Output 1 2 Sample Input 2 icpc icpc Sample Output 2 0
36,696
プログラム停止刀定 皆さんは、苊劎しお䜜ったプログラムを実行しおみたら、無限ルヌプになっおしたった経隓はありたせんか プログラムの実行が停止するかどうかを、実行しなくおも事前に刀定できるず䟿利ですよね。 残念ながら、皆さんがふだん䜿っおいるプログラミング蚀語では、あらゆるプログラムに察しおそのような刀定をするこずは䞍可胜です。しかし、それよりもはるかに蚈算胜力の䜎いプログラミング蚀語なら、その蚀語で曞いたプログラムが停止するかどうかを刀定するプログラムを曞ける堎合がありたす。 TinyPowerずいうプログラミング蚀語を考えたす。この蚀語のプログラムは行の䞊びです。プログラムの各行には、先頭に行番号を曞き、その埌ろに文を䞀぀曞きたす。この蚀語で曞ける文の皮類は以䞋の通りです。 文の皮類 動䜜 ADD var 1 var 2 var 3 倉数 var 2 の倀ず var 3 の倀を加算した結果を倉数 var 1 に代入する ADD var 1 var 2 con 倉数 var 2 の倀ず定数 con を加算した結果を倉数 var 1 に代入する SUB var 1 var 2 var 3 倉数 var 2 の倀から var 3 の倀を枛算した結果を倉数 var 1 に代入する SUB var 1 var 2 con 倉数 var 2 の倀から定数 con を枛算した結果を倉数 var 1 に代入する SET var 1 var 2 倉数 var 2 の倀を倉数 var 1 に代入する SET var 1 con 定数 con を倉数 var 1 に代入する IF var 1 dest 倉数 var 1 の倀がでないずきだけ、行番号 dest にゞャンプする HALT プログラムを停止させる 行番号は正の敎数で、プログラム䞭に同じ行番号が぀以䞊珟れるこずはありたせん。倉数は英小文字䞀文字で衚し、定数ず倉数の倀は敎数です。倉数の宣蚀は䞍芁で、倉数の初期倀はです。 プログラムの実行は先頭の文から始たり、䞊んでいる順に文が実行されたす。ただし、䞊の衚に曞かれたように、IF文の倉数の倀がでないずきは、倉数の埌ろに曞かれた行番号で指定される行にゞャンプし、その行に曞かれた文から実行を続けたす。プログラムは以䞋のずきに停止したす。 HALT文を実行したずき。 負の敎数たたは以䞊の敎数を倉数に代入しようずしたずき倉数の倀は曎新されない。 プログラムに珟れない行番号にゞャンプしようずしたずき。 プログラムの最埌の文を実行した埌、そこからどの行にもゞャンプしないずき。 TinyPowerのプログラムが䞎えられたずき、それが停たるかどうかを刀定するプログラムを䜜成せよ。 Input 入力は以䞋の圢匏で䞎えられる。 N stmt 1 stmt 2 : stmt N 行目にプログラムの行数 N (1 ≀ N ≀ 50) が䞎えられる。続く N 行に、TinyPowerプログラムの文 stmt i が䞎えられる。 stmt i は、以䞋のいずれかの圢匏で䞎えられる。 line ADD var 1 var 2 var 3 たたは line ADD var 1 var 2 con たたは line SUB var 1 var 2 var 3 たたは line SUB var 1 var 2 con たたは line SET var 1 var 2 たたは line SET var 1 con たたは line IF var 1 dest たたは line HALT line , dest (1 ≀ line , dest ≀ 1000) は行番号、 var j (英小文字文字)は倉数、 con (0 ≀ con ≀ 15) は定数を衚す。 stmt i 䞭の区切りは空癜文字ずする。なお、プログラム䞭に倉数は必ず぀以䞊珟れ、異なる倉数名は぀たでしか珟れないものずする。 Output プログラムが停止するずきは、プログラムに珟れる倉数の結果を、倉数名の蟞曞順に改行区切りで出力し、停止しないずきは「inf」を出力する。倉数の結果は、倉数名ず倉数の倀を「=」で区切っお出力する。 Sample Input 1 6 10 SET c 1 20 SET i 5 100 ADD s s i 110 SUB i i c 120 IF i 100 200 HALT Sample Output 1 c=1 i=0 s=15 入力䟋は、からたでの敎数の和を蚈算し、その結果を倉数sに栌玍したあず、HALT文の実行で停止する。 Sample Input 2 3 10 SET c 1 120 IF c 10 20 HALT Sample Output 2 inf 入力䟋は、行番号10でcに1を代入し、次の行番号120のIF文で行番号10に戻るこずを繰り返すので、停止しない。 Sample Input 3 3 111 SET c 1 12 SUB c c 2 777 SET a 4 Sample Output 3 a=0 c=1 入力䟋は、行番号111でcに1を代入し、次の行番号12でcに-1を代入しようずするので、停止する。このずきcの倀は-1に曎新されない。行番号777は実行されないので、aの倀は初期倀0のたたである。
36,697
Problem B: Sort the Panels There was an explorer Henry Nelson traveling all over the world. One day he reached an ancient building. He decided to enter this building for his interest, but its entrance seemed to be locked by a strange security system. There were some black and white panels placed on a line at equal intervals in front of the entrance, and a strange machine with a cryptogram attached. After a while, he managed to read this cryptogram: this entrance would be unlocked when the panels were rearranged in a certain order, and he needed to use this special machine to change the order of panels. All he could do with this machine was to swap arbitrary pairs of panels. Each swap could be performed by the following steps: move the machine to one panel and mark it; move the machine to another panel and again mark it; then turn on a special switch of the machine to have the two marked panels swapped. It was impossible to have more than two panels marked simultaneously. The marks would be erased every time the panels are swapped. He had to change the order of panels by a number of swaps to enter the building. Unfortunately, however, the machine was so heavy that he didn’t want to move it more than needed. Then which steps could be the best? Your task is to write a program that finds the minimum cost needed to rearrange the panels, where moving the machine between adjacent panels is defined to require the cost of one. You can arbitrarily choose the initial position of the machine, and don’t have to count the cost for moving the machine to that position. Input The input consists of multiple datasets. Each dataset consists of three lines. The first line contains an integer N , which indicates the number of panels (2 ≀ N ≀ 16). The second and third lines contain N characters each, and describe the initial and final orders of the panels respectively. Each character in these descriptions is either ‘B’ (for black) or ‘W’ (for white) and denotes the color of the panel. The panels of the same color should not be distinguished. The input is terminated by a line with a single zero. Output For each dataset, output the minimum cost on a line. You can assume that there is at least one way to change the order of the panels from the initial one to the final one. Sample Input 4 WBWB BWBW 8 WWWWBWBB WWBBWBWW 0 Output for the Sample Input 3 9
36,698
Score : 600 points Problem Statement The server in company A has a structure where N devices numbered 1, 2, ..., N are connected with N - 1 cables. The i -th cable connects Device U_i and Device V_i . Any two different devices are connected through some number of cables. Each device v ( 1 \leq v \leq N ) has a non-zero integer A_v , which represents the following: If A_v < 0 , Device v is a computer that consumes an electric power of -A_v . If A_v > 0 , Device v is a battery that supplies an electric power of A_v . You have decided to disconnect some number of cables (possibly zero) to disable the server. When some cables are disconnected, the devices will be divided into some number of connected components. The server will be disabled if all of these connected components satisfy one of the following conditions: There is no computer in the connected component. That is, A_v is positive for every device v that belongs to the connected component. There is not enough supply of electric power in the connected component. That is, the sum of A_v over all devices v that belong to the connected component is negative. At least how many cables do you need to disconnect in order to disable the server? Constraints 1 \leq N \leq 5 000 1 \leq |A_i| \leq 10^9 ( 1 \leq i \leq N ) 1 \leq U_i, V_i \leq N ( 1 \leq i \leq N - 1 ) U_i \neq V_i ( 1 \leq i \leq N - 1 ) Any two different devices are connected through some number of cables. All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N U_1 V_1 U_2 V_2 : U_{N - 1} V_{N - 1} Output Print the answer. Sample Input 1 7 -2 7 5 6 -8 3 4 1 2 2 3 2 4 1 5 5 6 5 7 Sample Output 1 1 We should disconnect the cable connecting Device 1 and Device 2 . Sample Input 2 4 1 2 3 4 1 2 1 3 1 4 Sample Output 2 0 Sample Input 3 6 10 -1 10 -1 10 -1 1 2 2 3 3 4 4 5 5 6 Sample Output 3 5 Sample Input 4 8 -2 3 6 -2 -2 -5 3 2 3 4 7 6 6 2 8 2 5 3 1 8 3 7 Sample Output 4 3 Sample Input 5 10 3 4 9 6 1 5 -1 10 -10 -10 7 4 5 6 8 1 9 5 7 1 10 3 2 8 4 10 9 2 Sample Output 5 3
36,699
Anipero 2012 D: アニペロ2012 アニペロサマヌラむブ通称アニペロはさたざたなアニメ゜ングアヌティストたちが集結する日本囜内最倧のアニメ゜ングラむブむベントであるアニ゜ンが倧奜きな2D君は昚幎に匕き続き今幎もアニペロに行くこずにした 圌はアニペロを楜しむためにすでにサむリりムを m 本賌入しおいるサむリりムずは折るず化孊反応で光るスティックであるリズムに合わせおサむリりムを振るこずでラむブを盛り䞊げるこずができ自分の満足床も䞊昇する今回圌が賌入した党おのサむリりムは次のような性質を持぀ サむリりムは折っおから時間が経過するに぀れ暗くなっおいき10分で光を倱う 折っおから5分の間は非垞に明るい以䞋「レベル2」ず呌ぶ 折っおから5分経過した埌は少し暗くなる以䞋「レベル1」ず呌ぶ 振っおも振らなくおも光を倱うスピヌドは倉わらない 2D君は限られたサむリりムを曲によっおうたく䜿い分けるこずで今幎のアニペロでどれだけの満足床を埗られそうか以䞋の問題を考えるこずにした 圌はラむブ䞭に流れるであろう曲を n 曲予想しおいる 各曲の長さは党お5分である n 曲は連続で流れ続け曲ず曲の間は0分ず考えおよい 各曲には以䞋の3぀のパラメヌタが䞎えられる ある曲に察しおレベル2を1本だけ振ったずきに増える満足床 ある曲に察しおレベル1を1本だけ振ったずきに増える満足床 ある曲においお1本も振らないずきに増える満足床 サむリりムを振ったからずいっお満足床が増えるずは限らない 振ったら逆に䌚堎の雰囲気を乱しお満足床が枛る堎合もある 振らない堎合も同様のこずが蚀える サむリりムは以䞋のルヌルに埓っお䜿甚しなければならない 曲が始たる時点でのみ折るこずができ䞀床に䜕本でも折るこずができるサむリりムを折るのにかかる時間は無芖しおよい 1曲で最倧8本同時に振るこずができる 耇数のサむリりムを振る際以䞋の匏により加算する満足床を蚈算する (レベル1の本数)×(レベル1の1本あたりの満足床)(レベル2の本数)×(レベル2の1本あたりの満足床) 1本もサむリりムを振らない堎合は1本も振らない堎合の満足床だけを加算する 䞀床振るず決めたサむリりムは1曲が終了するたで持ち替えるこずはできない サむリりムは振らずに眮いおおくこずができるたたサむリりムを党お䜿いきる必芁はない 2D君はラむブの曲予想たでは枈たせたがそれだけで疲れおしたっお問題を解く気になれなかった あなたの仕事は圌の代わりに今幎のラむブで埗られそうな最倧満足床を求めるプログラムを曞くこずである Input ラむブの予想曲リストに察する満足床情報が入力される 1行目にラむブで歌われる曲数 n (1 <= n <= 50)ずラむブ開始時に2D君が持っおいる新品のサむリりムの数m (0 <= m <= 50)がスペヌス区切りで入力される 続く n 行では1行ず぀1曲の情報が入力される i 番目(1 <= i <= n )の曲情報は 曲 i に察しおレベル2のサむリりムを1本振ったずきの満足床 a i 曲 i に察しおレベル1のサむリりムを1本振ったずきの満足床 b i 曲 i においおサむリりムを1本も振らないずきの満足床 c i がスペヌス区切りで入力される(-100 <= a i , b i , c i <= 100) Output ラむブ終了時の2D君の最倧満足床の予想を1行に出力せよ 最倧満足床がマむナスになるこずもあるので泚意するこず 行の最埌には改行を出力するこず Sample Input 1 1 5 2 3 8 Sample Output 1 10 Sample Input 2 2 10 2 2 20 2 3 -10 Sample Output 2 44 Sample Input 3 3 10 5 1 9 -3 2 1 1 11 0 Sample Output 3 102
36,700
Score : 100 points Problem Statement Ringo Kingdom Congress is voting on a bill. N members are present, and the i -th member (1 ≀ i ≀ N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints 1 ≀ N ≀ 10^5 1 ≀ P ≀ 100 1 ≀ w_i ≀ 10^9 1 ≀ b_i ≀ 10^9 All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Sample Input 1 4 75 1 1 1 1 1 1 1 1 Sample Output 1 3 This is a "normal" vote, where each of the four members has one white ballot and one blue ballot. For the bill to pass, at least 75 percent of the four, that is, at least three must be in favor of it. Sample Input 2 4 75 1 1 1 1 1 1 100 1 Sample Output 2 1 The "yes" vote of the member with 100 white ballots alone is enough to pass the bill. Sample Input 3 5 60 6 3 5 9 3 4 7 8 4 7 Sample Output 3 3
36,701
Problem F: Remainder Zero Problem 敎数の集合A,Bに぀いお,次の条件を満たす敎数 x がいく぀存圚するか答えよ。 A i mod x = 0 か぀ x mod B j = 0 がすべおの i (1 ≀ i ≀ N), j (1 ≀ j ≀ M) に぀いお成り立぀。 ( a mod b は a を b で割ったずきの䜙りを意味する) Input N M A 1 A 2 ... A N B 1 B 2 ... B M Constraints 入力は以䞋の条件を満たす。 1 ≀ N , M ≀ 5 1 ≀ A i , B j ≀ 10 14 (1 ≀ i ≀ N , 1 ≀ j ≀ M ) Output 条件を満たす敎数 x がいく぀存圚するか䞀行で出力せよ。 Sample Input 1 1 2 18 6 9 Sample Output 1 1 Sample Input 2 1 2 256 2 4 Sample Output 2 7
36,702
問題文 実数倉数 $x_1, x_2, ..., x_N$ は以䞋の条件を満たす。 $0 \leq x_i \leq 1$ ($1 \leq i \leq N$) $w_1x_1+w_2x_2+...+w_Nx_N \leq W$ このずき $v_1x_1+v_2x_2+...+v_Nx_N$ のずりうる最倧倀を求めよ。そのような最倧倀は実際に存圚するこずが知られおいる。 入力 入力は以䞋の圢匏に埓う。䞎えられる数は党お敎数である。 $N$ $W$ $w_1$ $v_1$ $w_2$ $v_2$ $...$ $w_N$ $v_N$ 制玄 $1 \leq N \leq 10^5$ $1 \leq W \leq 10^5$ $-10^4 \leq w_i \leq 10^4$ $-10^4 \leq v_i \leq 10^4$ 出力 $v_1x_1+v_2x_2+...+v_Nx_N$ のずりうる最倧倀を1行に出力せよ。 出力には $10^{-3}$ を超える誀差があっおはならない。 Sample Input 1 1 1 3 1 Output for the Sample Input 1 0.333333 $x_1=1/3$ のずき最倧ずなる。 Sample Input 2 2 3 3 3 1 2 Output for the Sample Input 2 4.000000 Sample Input 3 2 1 -1 -3 3 10 Output for the Sample Input 3 3.666667
36,703
G: 恋のゞュンレツRun!Run!Run! - Love Permutation, Run run run! - 物語 おおきなゞュンレツ らんらんらんでぶヌ♪ Hello, 星空蘭にゃ 奜きなデヌタ構造は Starry Sky Tree にゃ 蘭は最近物理孊科に入孊したんだけど、どうやらそこでもプログラミングをやらないずいけないらしいんだ。 蘭、アルゎリズムやデヌタ構造の理論は奜きなんだけど、実装はどうも苊手なんだよね   だいたい蘭達は人間なのに、どうしお機械の蚀葉を勉匷しなくちゃいけないの ずはいえ、課題をやらないこずには単䜍が出ないしやるしかないにゃ。 今回出た課題は順列の run ずかいうのが関係しおいるらしいんだヌ。 この問題、明らかに䜜者がタむトル䞀発ネタで考えおるのが芋え芋えにゃ、ちょっず寒くないかにゃヌ。 ずにかく、プログラミングが埗意なあなたに手䌝っおもらえたら、テンション䞊がるにゃヌ それじゃあ問題、行っくにゃ〜 問題 長さ K の数列 a が 1 \leq a_i \leq K (1 \leq i \leq K) か぀ a_i \neq a_j (1 \leq i < j \leq K) を満たすずき、 a は長さ K の順列であるずいう。 ここで順列のパタヌンマッチングを以䞋のように定矩する。 テキスト順列 q がパタヌン順列 p にマッチするずは、 p ず盞察順序が䞀臎するような、 p ず同じ長さの q の (連続ずは限らない) 郚分列が存圚するこずをいう。 より厳密には、 q の長さを N 、 p の長さを M ずしたずき、 q が p にマッチするずは、ある条件を満たす添え字列 1 \leq i_1 < ... < i_M \leq N が存圚するこずである。その条件ずは、 p_x < p_y (1 \leq x<y \leq M) ならば、か぀そのずきに限り q_{i_x} < q_{i_y} ずなるこずである。 䟋えば、順列 (3, 4, 2, 1, 5) は順列 (2, 1, 3) にマッチする。なぜならば、添え字列 (1, 4, 5) が䞊蚘の条件を満たすからである。 さらに、順列の run を定矩する。 順列のrunずは、単調増加、あるいは単調枛少な極倧連続郚分列である。すなわち、run は連続郚分列 a_l, ..., , a_r (l<r) のうち、 a_i < a_{i+1} (l \leq i < r) ( a_i > a_{i+1} (l \leq i < r) ) を満たし、か぀この区間を真に包含する連続区間からなる run が存圚しないものを蚀う。 䟋えば、順列 (3, 4, 2, 1, 5) は (3, 4) , (4, 2, 1) , (1, 5) ずいう3぀のrunを持぀。 長さ N のテキスト順列 q ず長さ M のパタヌン順列 p が䞎えられる。 ここで、 q は必ずちょうど3぀だけの run を持぀こずが保蚌される。 q が p にマッチするかどうかを刀定せよ。 入力圢匏 入力は以䞋の圢匏で䞎えられる。 N q_1 ... q_N M p_1 ... p_M 入力は党お敎数からなる。 1行目にはテキストずなる順列 q の長さ N が䞎えられる。 続く2行目は N 個の敎数が空癜区切りで䞎えられ、 i (1 \leq i \leq N) 番目の敎数は q の i 番目の芁玠 q_i を衚す。 3行目にはパタヌンずなる順列 p の長さ M が䞎えられる。 続く4行目は M 個の敎数が空癜区切りで䞎えられ、 j (1 \leq j \leq M) 番目の敎数は p の j 番目の芁玠 p_j を衚す。 制玄 4 \leq N \leq 10^5 1 \leq M \leq N q, p はそれぞれ長さ N, M の順列である。 q が持぀ run の数はちょうど3。 出力圢匏 順列 q が順列 p にマッチするずき"Yes"、そうでなければ"No"ず1行に出力せよ。 入力䟋1 5 3 4 2 1 5 3 1 2 3 出力䟋1 Yes 入力䟋2 5 3 5 4 1 2 3 1 2 3 出力䟋2 No
36,704
Problem P04: CamelCase プログラミングにおける識別子倉数や関数の呜名では、 単語を連結した耇合語が䜿われる。 しかし、そのたた連結するず単語の区切りがわからなくなるため、 䞀般的に以䞋の呜名芏則の䞭から統䞀するものを遞び適甚する Upper CamelCase にする 単語を盎接連結し耇合語ずし、各単語の先頭文字のみを倧文字にする。 䟋 GetUserName Lower CamelCase にする 単語を盎接連結し耇合語ずし、各単語の先頭文字のみを倧文字にする。ただし、耇合語の先頭文字は小文字にする。 䟋 getUserName アンダヌスコアで繋ぐ 単語をアンダヌスコアで連結し耇合語ずする。単語の文字はすべお小文字にする。 䟋 get_user_name 䞎えられた識別子を、指定された呜名芏則を適甚しお出力するプログラムを䜜成せよ。 䞎えられる識別子は、䞊蚘の呜名芏則のいづれかが既に適甚されおいるものずする。 Input 入力ずしお耇数のデヌタセットが䞎えられる。各デヌタセットは以䞋の圢匏で䞎えられる name type 識別子、呜名芏則 空癜区切りの文字列ず文字 type は呜名芏則を瀺す文字であり、以䞋の衚の通りずする type 呜名芏則 U Upper CamelCase にする L Lower CamelCase にする D アンダヌスコアで繋ぐ 䞎えられる識別子の文字数は 1 以䞊 100 以䞋である。 type が ' X ' のずき入力の終わりずする。この入力に察する出力を行っおはならない。 Output 各デヌタセットに぀いお、呜名芏則を適甚した識別子を1行に出力せよ。 Sample Input get_user_name L getUserName U GetUserName D EndOfInput X Output for the Sample Input getUserName GetUserName get_user_name
36,705
ねこたっしぐら あるずころに、高い塀に囲たれた倧きなお屋敷がありたした。そのお屋敷の䞻人は猫がずおも倧奜きで、時折やっおくる猫たちのために、い぀もおいしいごはんを甚意しおいたした。お腹を空かせた猫たちは、高い塀をひょいず飛び越え、お屋敷の至る所に眮いおあるごはんにたっしぐらに駆け寄るのでした。 ある日䞻人は、屋敷の䞭で䜕匹かの猫が倒れおいるのを芋぀けたした。猫たちはごはんを探しお屋敷の䞭を瞊暪無尜に走り回ったので、ぶ぀かったり転んだりしおしたったのです。䞻人は猫たちの安党を考えお、ごはんの眮き堎所を工倫するこずにしたした。 䞊空から芋るず、このお屋敷の塀は倚角圢をなしおいたす。䞻人は猫たちがごはんを芋぀けやすいように、敷地内の䞭でも、倚角圢の頂点にあたる堎所だけにごはんを眮くこずにしたした。たた猫たちは気たぐれなので、倚角圢の呚䞊のどの点からお屋敷に入っおくるかは予想できたせん。そこで䞻人は、猫がどの点から入ったずしおも、その点から盎進しおいずれかのごはんにたどり着けるように、ごはんを配眮するこずも決めたした。 すべおの頂点にごはんを配眮すれば、この条件を満たすこずができたす。しかし、ごはんを補充しお回るのは倧倉なので、䞻人はできるだけ少ない数の頂点にごはんを配眮したいず思いたした。さお、䞻人は最䜎䜕箇所にごはんを配眮する必芁があるでしょうか。 お屋敷の塀を衚す倚角圢を入力ずし、ごはんを配眮する頂点の数の最小倀を求めるプログラムを䜜成しお䞋さい。ただし、猫は倚角圢の内郚のみを盎進できるものずしたす蟺は倚角圢の内郚に含めるものずしたす。 入力 入力は耇数のデヌタセットからなる。入力の終わりはれロ぀の行で瀺される。各デヌタセットは以䞋の圢匏で䞎えられる。 n x 1 y 1 x 2 y 2 ... x n y n 行目に倚角圢の頂点の数 n (3 ≀ n ≀ 16) が䞎えられる。続く n 行に倚角圢の頂点の座暙が䞎えられる。n 行のそれぞれは、぀の空癜で区切られた぀の敎数からなる。x i (-1000 ≀ x i ≀ 1000) は i 番目の頂点の x 座暙、y i (-1000 ≀ y i ≀ 1000) は i 番目の頂点の y 座暙を瀺す。倚角圢の頂点は、隣り合った頂点を反時蚈回りに蚪問するような順番で䞎えられる。 デヌタセットの数は 20 を超えない。 出力 各デヌタセットごずに、ご飯を配眮する頂点の数を行に出力する。 入力䟋 8 0 0 3 2 6 2 8 6 6 5 7 7 0 4 3 4 8 0 0 5 3 5 2 4 1 6 1 8 6 6 4 2 4 0 出力䟋 1 2
36,706
Multisect We are developing the world's coolest AI robot product. After the long struggle, we finally managed to send our product at revision $R_{RC}$ to QA team as a release candidate. However, they reported that some tests failed! Because we were too lazy to set up a continuous integration system, we have no idea when our software corrupted. We only know that the software passed all the test at the past revision $R_{PASS}$. To determine the revision $R_{ENBUG}$ ($R_{PASS} < R_{ENBUG} \leq R_{RC}$) in which our software started to fail, we must test our product revision-by-revision. Here, we can assume the following conditions: When we test at the revision $R$, the test passes if $R < R_{ENBUG}$, or fails otherwise. It is equally possible, which revision between $R_{PASS} + 1$ and $R_{RC}$ is $R_{ENBUG}$. From the first assumption, we don't need to test all the revisions. All we have to do is to find the revision $R$ such that the test at $R - 1$ passes and the test at $R$ fails. We have $K$ testing devices. Using them, we can test at most $K$ different revisions simultaneously. We call this "parallel testing". By the restriction of the testing environment, we cannot start new tests until a current parallel testing finishes, even if we don't use all the $K$ devices. Parallel testings take some cost. The more tests fail, the more costly the parallel testing becomes. If $i$ tests fail in a parallel testing, its cost is $T_i$ ($0 \leq i \leq K$). And if we run parallel testings multiple times, the total cost is the sum of their costs. Of course we want to minimize the total cost to determine $R_{ENBUG}$, by choosing carefully how many and which revisions to test on each parallel testing. What is the minimum expected value of the total cost if we take an optimal strategy? Input The input consists of a single test case with the following format. $R_{PASS}$ $R_{RC}$ $K$ $T_0$ $T_1$ ... $T_K$ $R_{PASS}$ and $R_{RC}$ are integers that represent the revision numbers of our software at which the test passed and failed, respectively. $1 \leq R_{PASS} < R_{RC} \leq 1,000$ holds. $K$ ($1 \leq K \leq 30$) is the maximum number of revisions we can test in a single parallel testing. $T_i$ is an integer that represents the cost of a parallel testing in which $i$ tests fail ($0 \leq i \leq K$). You can assume $1 \leq T_0 \leq T_1 \leq ... \leq T_K \leq 100,000$. Output Output the minimum expected value of the total cost. The output should not contain an error greater than 0.0001. Sample Input 1 1 10 2 1 1 1 Output for the Sample Input 1 2.0 Sample Input 2 1 100 1 100 100 Output for the Sample Input 2 670.7070707 Sample Input 3 100 200 4 1 1 2 2 3 Output for the Sample Input 3 4.6400000 Sample Input 4 2 3 4 1 2 3 4 5 Output for the Sample Input 4 0.0 Sample Input 5 998 1000 4 10 100 1000 10000 100000 Output for the Sample Input 5 55.0
36,707
Score : 600 points Problem Statement Let us consider the following operations on a string consisting of A and B : Select a character in a string. If it is A , replace it with BB . If it is B , replace with AA . Select a substring that is equal to either AAA or BBB , and delete it from the string. For example, if the first operation is performed on ABA and the first character is selected, the string becomes BBBA . If the second operation is performed on BBBAAAA and the fourth through sixth characters are selected, the string becomes BBBA . These operations can be performed any number of times, in any order. You are given two string S and T , and q queries a_i, b_i, c_i, d_i . For each query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i} , a substring of S , can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i} , a substring of T . Constraints 1 \leq |S|, |T| \leq 10^5 S and T consist of letters A and B . 1 \leq q \leq 10^5 1 \leq a_i \leq b_i \leq |S| 1 \leq c_i \leq d_i \leq |T| Input Input is given from Standard Input in the following format: S T q a_1 b_1 c_1 d_1 ... a_q b_q c_q d_q Output Print q lines. The i -th line should contain the response to the i -th query. If S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i} , print YES . Otherwise, print NO . Sample Input 1 BBBAAAABA BBBBA 4 7 9 2 5 7 9 1 4 1 7 2 5 1 7 2 4 Sample Output 1 YES NO YES NO The first query asks whether the string ABA can be made into BBBA . As explained in the problem statement, it can be done by the first operation. The second query asks whether ABA can be made into BBBB , and the fourth query asks whether BBBAAAA can be made into BBB . Neither is possible. The third query asks whether the string BBBAAAA can be made into BBBA . As explained in the problem statement, it can be done by the second operation. Sample Input 2 AAAAABBBBAAABBBBAAAA BBBBAAABBBBBBAAAAABB 10 2 15 2 13 2 13 6 16 1 13 2 20 4 20 3 20 1 18 9 19 2 14 1 11 3 20 3 15 6 16 1 17 4 18 8 20 7 20 3 14 Sample Output 2 YES YES YES YES YES YES NO NO NO NO
36,708
閉路のない連結な有向グラフが䞎えられる(有向グラフが連結であるずはこれを無向グラフずした時に連結であるずいう事である) このグラフに察しお䞀぀の頂点を遞んで銖郜 s を定めたい T(v) = " v から党おの点を到達可胜にするために必芁な「蟺の反転」操䜜の回数の最小倀"ずする ただし「蟺の反転」ずは頂点 v, u に関しお (v, u) に匵られおいた有向蟺を削陀しお (u, v) に匵り盎すこずである 頂点 s が銖郜であるずは任意の頂点 v に察しお T(s) ≀ T(v) が成立するこずである 銖郜であるような頂点をすべお列挙しお答えよ Input 入力は以䞋のような圢匏で M + 1 行で䞎えられる N M a 1 b 1 : a M b M 1 行目には二぀の敎数 N, M が䞎えられ䞎えられるグラフは N 頂点 M 蟺であるこずを衚す 2 行目から M + 1 行目にはそれぞれ二぀の敎数 a i , b i が䞎えられ a i から b i に有向蟺が匵られおいるこずを衚す Constraints 1 ≀ N ≀ 10,000 0 ≀ M ≀ 100,000 0 ≀ a i ≀ N − 1 0 ≀ b i ≀ N − 1 a i ≠ b i i ≠ j ならば (a i , b i ) ≠ (a j , b j ) 䞎えられるグラフは連結で閉路はない 䞎えられるグラフに察しお入次数が 0 である頂点の個数は 50 以䞋である Output 以䞋の圢匏で2 行で出力せよ cnum cost c 1 c 2 . . . c cnum 1 行目には二぀の敎数 cnum , cost を空癜区切りで出力せよ 2 行目には cnum 個の敎数 c i を空癜区切りで出力せよ 倉数の意味は以䞋の通りである − cnum : 銖郜の性質を満たす頂点数 − cost : 銖郜ずなる頂点 v に察する T(v) の倀 − c i : 銖郜の性質を満たす頂点を番号に関しお昇順に䞊べた時 i 番目の頂点番号 Sample Input 1 3 2 0 1 2 1 Output for the Sample Input 1 2 1 0 2 頂点 0 を銖郜ずするずきには蟺 (2,1) を反転すれば(0,1), (1,2) の蟺を持぀グラフができるので 1 が答え T(0) = 1, T(1) = 2, T(2) = 1 である Sample Input 2 5 4 0 1 2 1 2 3 4 3 Output for the Sample Input 2 3 2 0 2 4 Sample Input 3 5 5 0 1 1 2 3 2 3 4 4 1 Output for the Sample Input 3 2 1 0 3
36,709