task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Problem D: Trapezoids If you are a computer user, you should have seen pictures drawn with ASCII characters. Such a picture may not look as good as GIF or Postscript pictures, but is much easier to handle. ASCII pictures can easily be drawn using text editors, and can convey graphical information using only text-based media. Program s extracting information from such pictures may be useful. We are interested in simple pictures of trapezoids, consisting only of asterisk('*') characters and blank spaces. A trapezoid (trapezium in the Queen's English) is a four-side polygon where at least one pair of its sides is parallel. Furthermore, the picture in this problem satisfies the following conditions. All the asterisks in the picture belong to sides of some trapezoid. Two sides of a trapezoid are horizontal and the other two are vertical or incline 45 degrees. Every side is more than 2 characters long. Two distinct trapezoids do not share any asterisk characters. Sides of two trapezoids do not touch. That is, asterisks of one trapezoid do not appear in eight neighbors of asterisks of a different trapezoid. For example, the following arrangements never appear. **** | **** | ****** * * | * * *** | * * **** | ******* * | **** **** | *** | **** * * | | * * **** | | **** Some trapezoids may appear inside others. For example, the following is a valid picture. ********* * * * *** * * * * * * ***** * * * ********* Your task is to recognize trapezoids in the picture and to calculate the area of each trapezoid. The area of a trapezoid is the number of characters on or inside its four sides, including the areas of the trapezoids inside it, if any. Input The input contains several descriptions of pictures. Each of then starts with a line containing an integer h (1 ≀ h ≀ 1000), where h is the height (number of lines) of the picture. Each line of the picture consists only of asterisk and space characters, and contains less than 80 characters. The lines of the picture do not necessarily have the same length and may contain redundant space characters at the end. After the last picture, and integer zero terminates the input. Output For each picture, your program should produce output lines each containing two integers m and n is this order, which means there are n trapezoids of area m in the picture. output lines for one picture should be in ascending order on m and count all the trapezoids in the picture. Output lines for two pictures should be separated by a line containing ten hyphen ('-') characters. This separator line should not appear before the output for the first picture nor after the output for the last. Sample Input 7 ******** * * * *** * * * * * * *** * * * ******** 9 *** * * ***** ***** * * *** ***** * * * * *** 11 **** ******************* * * ********* * * ****** * * **** * ********* * * *** * * * * * * * *** * * * * **** ******* * * *** *** * * * * * ***** * * * * * * * * * * * *** * * *** * * *** *** * * ********* * * * * * ********************* * * * ***************************** 0 (Spacing between lines in pictures is made narrower for better appearance. Note that a blank line exists as the first line of the second picture.) Output for the Sample Input 9 1 56 1 ---------- 12 2 15 1 ---------- 9 3 12 2 15 2 63 1 105 1 264 1
35,800
Score : 1000 points Problem Statement There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N . Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c , and visit town c_i on the i -th day. That is, on the i -th day, he will travel from his current location to town c_i . If he is already at town c_i , he will stay at that town. His location just before the beginning of the tour is town 1 , the capital. The tour ends at town c_M , without getting back to the capital. The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b , there will be a newly paved one-way road from town a to town b . Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition? Constraints 2≩N≩300 1≩M≩300 Input The input is given from Standard Input in the following format: N M Output Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7) . Sample Input 1 3 3 Sample Output 1 2 As shown below, the condition is satisfied only when c = (2,3,1) or c = (3,2,1) . Sequences such as c = (2,3,2) , c = (2,1,3) , c = (1,2,2) do not satisfy the condition. Sample Input 2 150 300 Sample Output 2 734286322 Sample Input 3 300 150 Sample Output 3 0
35,801
ぞやわり N+1 郚屋が1列に䞊んだ新築の建物がある各郚屋はすべお1人甚の䜏居であり珟圚どの郚屋も空宀だが来月から新たに N 人がここに䜏む予定であるしたがっお圌らが暮らし始めるず1宀は空き郚屋になる あなたは倧家ずしお圌らの嗜奜に合わせた郚屋割りを倚く提案したいず考えおいるここで郚屋割りずはそれぞれの人がどの郚屋に䜏むのかを䞎える衚である䟋えば N = 3 のずき「1人目は4号宀2人目は1号宀3人目は2号宀」がありうる䞀぀の郚屋割りである もちろんありうるすべおの郚屋割りを提案すれば話は早いがそれでは提案の意味がないため倧家の手間ず䜏人の嗜奜を考慮しおいく぀か制玄を蚭ける たず提案された郚屋割りの䞀぀に圌らが䜏み始めおから「別の提案された郚屋割りの方に倉曎したい」ず蚀われるかもしれないこの建物は新築であり圌らはただ誰も入居しおいない新しい郚屋が奜みであるこずがわかっおいるので単玔に誰か1人が空き郚屋ぞ匕っ越しをするだけで提案された別の郚屋割りに倉曎できるずきに限りこれが起こりうるしかし倧家ずしおそういう面倒ごずは避けたいためこのような倉曎が蚱されないよう提案する郚屋割りをうたく調敎したい ぀たり提案する郚屋割りの集合は次を満たさなければならない 「任意の二぀の異なる提案された郚屋割り A, B に察しお郚屋割り A の空き郚屋に誰か1人を移しおも郚屋割り B にならない」 次にこれから䜏む N 人にはそれぞれちょうど1人奜たしい人がいるこずがわかっおいるしたがっお提案するすべおの郚屋割りはすべおの人に察しお奜たしい人が隣に䜏むような郚屋割りにする これらの条件を満たす郚屋割りの集合で最倧の集合の倧きさはいくらだろうか 1, 000, 000, 007 で割った䜙りを求めおほしい Input 入力は耇数のデヌタセットからなる 各デヌタセットは次の圢匏で衚される N a 1 a 2 ... a N デヌタセットの 1 行目には来月建物に䜏む人数を衚す敎数 N が䞎えられるこれは 2 ≀ N ≀ 100, 000 を満たす 2行目には i 番目の人にずっお隣の郚屋に䜏んでくれるず奜たしい人の番号 a i の情報が䞎えられるこれに぀いおは 1 ≀ a i ≀ N か぀ a i ≠ i を満たす たたデヌタセットの数は 50 を超えない 入力の終わりは1個のれロだけからなる行で衚される Output 各デヌタセットに察しお問題文にあるような同時に提案できる郚屋割りの数の最倧倀を 1, 000, 000, 007 で割った䜙りを1行で出力せよ Sample Input 2 2 1 3 3 1 2 10 2 1 1 1 1 1 1 1 1 1 8 2 1 4 3 3 7 6 6 25 2 3 2 5 4 5 8 7 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 10 2 1 4 3 6 5 8 7 10 9 0 Output for Sample Input 2 0 0 144 633544712 11520
35,802
Score : 100 points Problem Statement How many multiples of d are there among the integers between L and R (inclusive)? Constraints All values in input are integers. 1 \leq L \leq R \leq 100 1 \leq d \leq 100 Input Input is given from Standard Input in the following format: L R d Output Print the number of multiples of d among the integers between L and R (inclusive). Sample Input 1 5 10 2 Sample Output 1 3 Among the integers between 5 and 10 , there are three multiples of 2 : 6 , 8 , and 10 . Sample Input 2 6 20 7 Sample Output 2 2 Among the integers between 6 and 20 , there are two multiples of 7 : 7 and 14 . Sample Input 3 1 100 1 Sample Output 3 100
35,803
Problem A: ねこかわいがり ある孊園のキャンパス内には、倚くのねこが䜏んでいる。な぀めは、それらのねこをかわいがるこずを日課ずしおいる。 しかし、ねこ達は気たぐれで、キャンパスの倖に散歩に出かけおいるかもしれない。 キャンパスの敷地は各蟺が x 軞たたは y 軞に平行な長方圢であり、門の郚分を陀いおフェンスで囲たれおいるが、ねこは門から自由に出入りできるし、たた、フェンスを乗り越えお移動するこずもある。 ある日、な぀めはキャンパス内にいるねこたちをなるべく平等にかわいがるために、キャンパス内に䜕匹のねこがいるのかを知りたいず考えた。 あなたの仕事は、座暙平面䞊のキャンパスの䜍眮ずねこ達の座暙が䞎えられたずきに、キャンパス内にいるねこの数を求めるこずである。 ただし、フェンスの䞊を歩いおいるねこや、ちょうど門を通過䞭のねこもキャンパス内にいるずみなす。 Input 入力の1行目には、4぀の敎数 X , Y , W , H が、スペヌス文字で区切られお䞎えられる。これらはそれぞれ、キャンパスの南西端の x 座暙、同地点の y 座暙、キャンパスの東西方向の幅、およびキャンパスの南北方向の長さを衚す。これらの倀は、-10000 <= X , Y <= 10000 および 0 < W , H <= 10000 を満たす。 入力の2行目にはねこの数 N (0 < N <= 100) が䞎えられる。 続く N 行には、それぞれのねこに぀いお1行に1匹ず぀、ねこの䜍眮の x , y 座暙を衚す敎数の組 (-50000 <= x , y <= 50000) が䞎えられる。 x 軞の正の方向は東、 y 軞の正の方向は北であり、䞎えられる数倀はすべお敎数である。 Output キャンパス内にいるねこの数を出力せよ。 Notes on Submission 䞊蚘圢匏で耇数のデヌタセットが䞎えられたす。入力デヌタの 1 行目にデヌタセットの数が䞎えられたす。各デヌタセットに察する出力を䞊蚘圢匏で順番に出力するプログラムを䜜成しお䞋さい。 Sample Input 2 1 3 20 10 4 21 13 1 15 10 10 25 10 1 3 20 10 4 21 13 1 15 10 10 25 10 Output for the Sample Input 2 2
35,804
西暊20XX 幎孊校察抗魔法競技倧䌚が開かれおいた倧䌚もいよいよ最終競技を残すのみずなったあなたはその競技の遞手の1 人である あなたが出堎する競技は空間内に配眮された青いオブゞェをすべお砎壊するたでの時間を競うずいうものである遞手は競技甚の銃の持蟌が蚱可されおいる空間内には耇数の青いオブゞェず同じ数の赀いオブゞェそしお耇数の障害物が配眮されおいる青いオブゞェず赀いオブゞェは1 察1 に察応しおおり赀いオブゞェが配眮されおいる座暙から青いオブゞェに匟を撃぀こずで青いオブゞェを砎壊しなければならない空間内に配眮されおいる障害物は球状であり少しず぀組成が異なっおいるが通垞の匟であれば障害物に觊れるず匟はその堎に止たっおしたう 競技に䜿われる匟はMagic Bullet ずいう特殊な匟であるこの匟は魔力をため蟌むこずができ匟が障害物に接觊した際に自動的に魔力を消費し匟が貫通する魔法が発動する障害物の組成の違いから貫通するために必芁な魔法やその発動のために消費する魔力の量は異なっおいるこのためある障害物に察する魔法が発動した埌であっおも別の障害物を貫通するためには新たに別の魔法を発動する必芁があるたた匟が耇数の障害物に同時に接觊した堎合は同時に魔法が発動する匟に蟌められた魔力の量は魔法の発動のたびに枛少する 障害物の䜍眮や倧きさ貫通する魔法の発動に必芁な魔力の量はすでに公開されおいるのに察し赀いオブゞェ青いオブゞェの䜍眮は公開されおいないしかし過去の同䞀競技の情報からある皋床オブゞェの䜍眮を予想するこずができた魔力を匟にこめるこずは非垞に䜓力を消耗しおしたうためあなたは魔力をできるだけ節玄したいず考えたそこで赀いオブゞェずそれに察応する青いオブゞェの䜍眮を仮定しおそのずきに匟にこめるべき必芁な魔力の最小量぀たり青いオブゞェに到達しおいる時点で匟に残っおいる魔力が0 になる魔力の量を求めよう Input 入力はすべお敎数であるそれぞれの数は1 ぀の空癜により区切られる N Q x 1 y 1 z 1 r 1 l 1 : x N y N z N r N l N sx 1 sy 1 sz 1 dx 1 dy 1 dz 1 : sx Q sy Q sz Q dx Q dy Q dz Q N は障害物の個数であり Q は仮定した青いオブゞェず赀いオブゞェの座暙の組の個数である x i , y i , z i はそれぞれ i 個目の障害物の䞭心の䜍眮を衚す x 座暙 y 座暙 z 座暙である r i は i 個目の障害物の半埄である l i は i 個目の障害物を貫通するための魔法で消費する魔力の量である sx j , sy j , sz j はそれぞれ j 番目の仮定における赀いオブゞェの䜍眮を衚す x 座暙 y 座暙 z 座暙である dx j , dy j , dz j はそれぞれ j 番目の仮定における青いオブゞェの䜍眮を衚す x 座暙 y 座暙 z 座暙である Constraints 0 ≀ N ≀ 50 1 ≀ Q ≀ 50 -500 ≀ x i , y i , z i ≀ 500 1 ≀ r i ≀ 1,000 1 ≀ l i ≀ 10 16 -500 ≀ sx j , sy j , sz j ≀ 500 -500 ≀ dx j , dy j , dz j ≀ 500 障害物が他の障害物にめり蟌んでいるこずはない オブゞェの座暙は障害物の内郚衚面にはない それぞれの仮定においお赀いオブゞェず青いオブゞェの座暙は䞀臎しない Output それぞれ1 組の赀いオブゞェずそれに察応する青いオブゞェの䜍眮の仮定においお空間䞭に障害物ず赀いオブゞェず青いオブゞェ1 察ずのみがあるものずしお匟にこめるべき魔力の量を1 行に出力せよ匟は赀いオブゞェの䜍眮から青いオブゞェの䜍眮たで䞀盎線に飛ぶものずし匟の倧きさは非垞に小さいので点ずしお扱う Sample Input 1 5 1 0 10 0 5 2 0 20 0 5 12 0 30 0 5 22 0 40 0 5 32 0 50 0 5 42 0 0 0 0 60 0 Output for the Sample Input 1 110 Sample Input 2 1 1 10 5 0 5 9 0 0 0 9 12 0 Output for the Sample Input 2 9 Sample Input 3 5 5 -38 -71 -293 75 1 -158 -38 -405 66 1 -236 -303 157 266 1 316 26 411 190 1 207 -312 -27 196 1 -50 292 -375 -401 389 -389 460 278 409 -329 -303 411 215 -220 -200 309 -474 300 261 -494 -87 -300 123 -463 386 378 486 -443 -64 299 Output for the Sample Input 3 0 2 1 3 0
35,805
Problem F: Atomic Car Race In the year 2020, a race of atomically energized cars will be held. Unlike today’s car races, fueling is not a concern of racing teams. Cars can run throughout the course without any refueling. Instead, the critical factor is tire (tyre). Teams should carefully plan where to change tires of their cars. The race is a road race having n checkpoints in the course. Their distances from the start are a 1 , a 2 , ... , and a n (in kilometers). The n -th checkpoint is the goal. At the i -th checkpoint ( i < n ), tires of a car can be changed. Of course, a team can choose whether to change or not to change tires at each checkpoint. It takes b seconds to change tires (including overhead for braking and accelerating). There is no time loss at a checkpoint if a team chooses not to change tires. A car cannot run fast for a while after a tire change, because the temperature of tires is lower than the designed optimum. After running long without any tire changes, on the other hand, a car cannot run fast because worn tires cannot grip the road surface well. The time to run an interval of one kilometer from x to x + 1 is given by the following expression (in seconds). Here x is a nonnegative integer denoting the distance (in kilometers) from the latest checkpoint where tires are changed (or the start). r , v , e and f are given constants. 1/( v - e × ( x - r )) (if x ≥ r ) 1/( v - f × ( r - x )) (if x < r ) Your mission is to write a program to determine the best strategy of tire changes which minimizes the total time to the goal. Input The input consists of multiple datasets each corresponding to a race situation. The format of a dataset is as follows. n a 1 a 2 . . . a n b r v e f The meaning of each of the input items is given in the problem statement. If an input line contains two or more input items, they are separated by a space. n is a positive integer not exceeding 100. Each of a 1 , a 2 , ... , and a n is a positive integer satisfying 0 < a 1 < a 2 < . . . < a n ≀ 10000. b is a positive decimal fraction not exceeding 100.0. r is a nonnegative integer satisfying 0 ≀ r ≀ a n - 1. Each of v , e and f is a positive decimal fraction. You can assume that v - e × ( a n - 1 - r ) ≥ 0.01 and v - f × r ≥ 0.01. The end of the input is indicated by a line with a single zero. Output For each dataset in the input, one line containing a decimal fraction should be output. The decimal fraction should give the elapsed time at the goal (in seconds) when the best strategy is taken. An output line should not contain extra characters such as spaces. The answer should not have an error greater than 0.001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. Sample Input 2 2 3 1.0 1 1.0 0.1 0.3 5 5 10 15 20 25 0.15 1 1.0 0.04 0.5 10 1783 3640 3991 4623 5465 5481 6369 6533 6865 8425 4.172 72 59.4705 0.0052834 0.0611224 0 Output for the Sample Input 3.5397 31.9249 168.6682
35,806
Score : 300 points Problem Statement You are given N positive integers a_1, a_2, ..., a_N . For a non-negative integer m , let f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N) . Here, X\ mod\ Y denotes the remainder of the division of X by Y . Find the maximum value of f . Constraints All values in input are integers. 2 \leq N \leq 3000 2 \leq a_i \leq 10^5 Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print the maximum value of f . Sample Input 1 3 3 4 6 Sample Output 1 10 f(11) = (11\ mod\ 3) + (11\ mod\ 4) + (11\ mod\ 6) = 10 is the maximum value of f . Sample Input 2 5 7 46 11 20 11 Sample Output 2 90 Sample Input 3 7 994 518 941 851 647 2 581 Sample Output 3 4527
35,807
問題 3 ある工堎では各営業所から補品生産の泚文を受けおいる 前日の泚文をたずめお各補品の生産合蚈を求めたい 入力ファむルの行目には泚文デヌタの数 n が曞いおあり 続く n 行には補品名ず泚文数が空癜で区切られお曞いおある 補品名は5文字以内の英倧文字で曞かれおいる 泚文デヌタには同じ補品が含たれおいるこずもあり順序はバラバラである この泚文デヌタの䞭に珟れる同じ補品の泚文数を合蚈し 出力ファむルに補品名ず合蚈を空癜を区切り文字ずしお出力しなさい ただし補品名に次の順序を付けおその順で出力するこず 順序文字の長さの小さい順に同じ長さのずきは前から比べお 最初に異なる文字のアルファベット順ずする 入力デヌタにおける補品数泚文数ずその合蚈のどれも10 6 以䞋である 出力ファむルにおいおは 出力の最埌の行にも改行コヌドを入れるこず 入出力䟋 入力䟋1 5 A 20 B 20 A 20 AB 10 Z 10 出力䟋1 A 40 B 20 Z 10 AB 10 入力䟋2 5 AAA 20 ABA 20 AAA 20 AAB 20 AAA 20 出力䟋2 AAA 60 AAB 20 ABA 20 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
35,808
玠数の性質 4 で割るず 3 あたる玠数 n (11、19、23 など) には、面癜い性質がありたす。1 以䞊 n 未満の自然数 (1, 2,... , n - 1) を 2 乗したものを n で割ったあたりを蚈算した結果を䞊べるず、同じ数になるものがあるため、互いに異なった数の個数は、( n - 1)/2 になりたす。 この様にしお埗られた数の集合には、特別な性質がありたす。埗られた数の集合から、互いに異なる 2 ぀ a ず b を遞んでその差を蚈算したす。差が負になったずきは、その差に n を足したす。さらに結果が ( n - 1)/2 より倧きいずきは、その差を n から匕きたす。 䟋えば、 n = 11 のずき 1 ず 9 の差は、 1 − 9 = −8 → −8 + n = −8 + 11 = 3 になりたす。9 ず 1 の差も 9 −1 = 8 → n − 8 = 11 − 8 = 3 で、同じ倀 3 になりたす。この差は、円呚䞊に 0, 1, ・・・, n - 1 を曞いお、二぀の数字の間の短い方の円匧を考えるずわかりやすくなりたす。(䞋図参照) こうしお埗られた数の「差」は、1, 2, . . ., ( n - 1)/2 のいずれかであり、同じ回数出珟したす。 【䟋】 n = 11 の時は、以䞋のようになりたす。 1 から n -1 たでの数を 2 乗したものを n で割った䜙りを蚈算したす。 1 2 = 1 → 1 2 2 = 4 → 4 3 2 = 9 → 9 4 2 = 16 → 5 5 2 = 25 → 3 6 2 = 36 → 3 7 2 = 49 → 5 8 2 = 64 → 9 9 2 = 81 → 4 10 2 = 100 → 1 a , b の「差」の蚈算 1 で埗られた 1, 3, 4, 5, 9 に぀いお異なる数同士の差を蚈算したす。 蚈算結果が負の堎合、 n = 11 を加算したす。 さらに、蚈算結果が ( n -1)/2 = 5 より倧きい堎合 n = 11 から枛算したす。 出珟回数を求める 蚈算結果 1, 2, 3, 4, 5 の出珟回数をそれぞれ数え䞊げたす。 これらの蚈算結果から 1, 2, 3, 4, 5 の出珟回数が 4 回であるこずがわかりたす。この性質は 4 で割るず 3 あたる玠数特有の性質であり 4 で割るず 1 あたる玠数ではこのようなこずはおきたせん。このこずを確認するため、10000 以䞋の奇数 n を入力ずし、䟋題にあるような蚈算 ( n で割ったあたりの 2 乗の差の頻床を求める)を実行し、その出珟回数を出力するプログラムを䜜成しおください。 Input 耇数のデヌタセットが䞎えられたす。各デヌタセットずしお぀の敎数 n ( n ≀ 10000) が行に䞎えられたす。入力は 0 を぀含む行でおわりたす。 Output 各デヌタセットに぀いお、出珟頻床を以䞋の圢匏で出力しおください。 剰䜙の平方の差が 1 である( a, b )の出珟個数(敎数) 剰䜙の平方の差が 2 である( a, b )の出珟個数(敎数) : : 剰䜙の平方の差が ( n -1)/2 である( a, b )の出珟個数(敎数) Sample Input 11 15 0 Output for the Sample Input 4 4 4 4 4 2 2 4 2 4 4 2
35,809
Set 数列 a_1,a_2,..,a_N が䞎えられたす。 この数列に倀は䜕皮類ありたすか。 入力 N a_1 a_2...a_N 出力 数列の倀の皮類数を出力せよ。 制玄 1 \leq N \leq 10^5 1 \leq a_i \leq 10^9 入力䟋 6 8 6 9 1 2 1 出力䟋 5
35,810
連鎖 問題 次のようなゲヌムがある あるキャラクタヌが瞊 1 列に N 個䞊んでいるこれらのキャラクタヌの色は赀青黄のいずれかであり初期状態で同じ色のキャラクタヌが4぀以䞊連続しお䞊んでいるこずはないプレヌダヌはある䜍眮のキャラクタヌを遞び他の色に倉曎するこずができるこの操䜜により同じ色のキャラクタヌが4぀以䞊連続しお䞊ぶずそれらのキャラクタヌは消滅するキャラクタヌが消滅するこずにより新たに同じ色のキャラクタヌが4぀以䞊連続しお䞊ぶずそれらのキャラクタヌも消滅し同じ色のキャラクタヌが4぀以䞊連続しお䞊んでいる箇所がなくなるたでこの連鎖は続くこのゲヌムの目的は消滅しないで残っおいるキャラクタヌ数をなるべく少なくするこずである 䟋えば䞋図の巊端の状態で䞊から6番目のキャラクタヌの色を黄色から青に倉曎するず青のキャラクタヌが5぀連続するので消滅し最終的に3぀のキャラクタヌが消滅せずに残る 初期状態における N 個のキャラクタヌの色の䞊びが䞎えられたずき 1箇所だけキャラクタヌの色を倉曎した堎合の消滅しないで残っおいるキャラクタヌ数の最小倀 M を求めるプログラムを䜜成せよ 入力 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる 1行目はキャラクタヌ数 N (1 ≀ N ≀ 10000) だけからなる続く N 行には 1, 2, 3 のいずれか1぀の敎数が曞かれおおり i + 1 行目 (1 ≀ i ≀ N) は初期状態における䞊から i 番目のキャラクタヌの色を衚す1 は赀を2 は青を3は黄を衚す N が 0 のずき入力の終了を瀺すデヌタセットの数は 5 を超えない 出力 デヌタセットごずに, 消滅しないで残っおいるキャラクタヌ数の最小倀 M を行に出力せよ 入出力䟋 入力䟋 12 3 2 1 1 2 3 2 2 2 1 1 3 12 3 2 1 1 2 3 2 1 3 2 1 3 0 出力䟋 3 12 䞊蚘問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
35,811
Debt Hell Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≀ n ≀ 100) is given in a line. Output Print the amout of the debt in a line. Sample Input 5 Output for the Sample Input 130000
35,812
Score : 200 points Problem Statement Iroha has a sequence of N strings S_1, S_2, ..., S_N . The length of each string is L . She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3 ... s_n is lexicographically smaller than another string t=t_1t_2t_3 ... t_m if and only if one of the following holds: There exists an index i(1≩i≩min(n,m)) , such that s_j = t_j for all indices j(1≩j<i) , and s_i<t_i . s_i = t_i for all integers i(1≩i≩min(n,m)) , and n<m . Constraints 1 ≩ N, L ≩ 100 For each i , the length of S_i equals L . For each i , S_i consists of lowercase letters. Input The input is given from Standard Input in the following format: N L S_1 S_2 : S_N Output Print the lexicographically smallest string that Iroha can produce. Sample Input 1 3 3 dxx axx cxx Sample Output 1 axxcxxdxx The following order should be used: axx , cxx , dxx .
35,813
Score : 800 points Problem Statement Given are integers N and X . For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353 . Let us repeat the following operation on the integer k . Operation: if the integer is currently odd, subtract 1 from it and divide it by 2 ; otherwise, divide it by 2 and add 2^{N-1} to it. How many operations need to be performed until k returns to its original value? (The answer is considered to be 0 if k never returns to its original value.) Constraints 1 \leq N \leq 2\times 10^5 0 \leq X < 2^N X is given in binary and has exactly N digits. (In case X has less than N digits, it is given with leading zeroes.) All values in input are integers. Input Input is given from Standard Input in the following format: N X Output Print the sum of the answers to the questions for the integers between 0 and X (inclusive), modulo 998244353 . Sample Input 1 3 111 Sample Output 1 40 For example, for k=3 , the operation changes k as follows: 1,0,4,6,7,3 . Therefore the answer for k=3 is 6 . Sample Input 2 6 110101 Sample Output 2 616 Sample Input 3 30 001110011011011101010111011100 Sample Output 3 549320998
35,815
Problem D: Land Mark “Hey, what’s up? It’s already 30 minutes past eleven!” “I’m so sorry, but actually I got lost. I have no idea where I am now at all and I got tired wandering around. Please help!” - Today you came to the metropolis to play with your friend. But she didn’t show up at the appointed time. What happened to her? After some uncomfortable minutes, finally you managed to get her on line, and have been just notified that she’s been lost in the city. You immediately told her not to move, and asked her what are around her to figure out where she is. She told the names of some famous land marks, in the order where she caught in her sight while she made a full turn counterclockwise without moving around. Fortunately, today you have a map of the city. You located all the land marks she answered on the map, but want to know in which district of the city she’s wandering. Write a program to calculate the area where she can be found, as soon as you can! Input Each input case is given in the format below: N x 1 y 1 ... x N y N l 1 . . . l N An integer N in the first line specifies the number of land marks she named ( N ≀ 10). The following N lines specify the x- and y-coordinates of the land marks in the city. Here you modeled the city as an unbounded two- dimensional plane. All coordinate values are integers between 0 and 100, inclusive. The last line of a test case specifies the order in which she found these land marks in a counterclockwise turn. A single line containing zero indicates the end of input. This is not a part of the input and should not be processed. Output Your program should output one line for each test case. The line should contain the case number followed by a single number which represents the area where she can be found. The value should be printed with the fifth digit after the decimal point, and should not contain an absolute error greater than 10 -5 . If there is no possible area found under the given condition, output “No area” in a line, instead of a number. If you cannot bound the area, output “Infinity”. Sample Input 8 1 0 2 0 3 1 3 2 2 3 1 3 0 2 0 1 1 2 3 4 5 6 7 8 8 1 0 2 0 3 1 3 2 2 3 1 3 0 2 0 1 4 3 2 1 8 7 6 5 4 0 0 1 0 1 1 0 1 1 2 3 4 0 Output for the Sample Input Case 1: 10.00000 Case 2: No area Case 3: Infinity
35,816
D: Statement Coverage / 呜什網矅 「うわっなんおひどいコヌドだ」 叀い゜ヌスコヌドを開きながら先茩が叫んでいる たた面倒な仕事が抌し付けられそうだ   ゜ヌスコヌドにはめたいがしそうなほどたくさんの if 文が䞊んでいる if 条件文 1; 呜什 1 if 条件文 2; 呜什 2 if 条件文 3; 呜什 3 ... どうやら制埡の構造はそれほど耇雑ではないらしい 1 ぀の条件文には倉数ず NOT 挔算子 "~" そしお AND "&" / OR "|" の 2 項挔算子が珟れる 倉数は真たたは停を衚し倉数名は1文字以䞊のアルファベットで衚される 挔算の順序は NOT 挔算子が優先だが括匧で先に蚈算するよう順序を倉えおもよい 倉数は 1 ぀もしくは 2 ぀2 項挔算は高々 1 回それ以倖は䜕床でも珟れお良い ずりあえずコンパむルは通った コヌドを修正する前にテストを曞く必芁がある 今回頌たれたのはこのコヌドのテストケヌスを曞く䜜業だ テストケヌスの数は党おの呜什が 1 床以䞊実行されれば十分である テストケヌスの数を芋積もっお 1 ぀で枈むようなら匕き受けるこずにしよう Input 䞎えられる入力は以䞋のように衚される N M cond 1 ; cond 2 ; ... cond N ; N ( 1 ≩ N ≩ 500 ) 行の条件文が珟れ条件文䞭には M ( 1 ≩ M ≩ 500 ) 皮類の倉数が存圚する 条件文 cond i は最倧 1000 文字である たた倉数名は10文字を超えない Output 䜜業を匕き受けるなら accept拒吊するなら reject を 1 行出力せよ Sample Input 1 3 4 ~~(~A|B); ~(~C&~D); ~(~A|~~D); Sample Output 1 accept Sample Input 2 2 1 var; ~var; Sample Output 2 reject
35,817
Score : 300 points Problem Statement Given is a string S consisting of lowercase English letters. Find the maximum positive integer K that satisfies the following condition: There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} ( 1 \leq i \leq K-1 ). Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this order. Constraints 1 \leq |S| \leq 2 \times 10^5 S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output Print the maximum positive integer K that satisfies the condition. Sample Input 1 aabbaa Sample Output 1 4 We can, for example, divide S into four strings aa , b , ba , and a . Sample Input 2 aaaccacabaababc Sample Output 2 12
35,818
Problem A: Ginkgo Numbers We will define Ginkgo numbers and multiplication on Ginkgo numbers. A Ginkgo number is a pair < m , n > where m and n are integers. For example, <1, 1>, <-2, 1> and <-3,-1> are Ginkgo numbers. The multiplication on Ginkgo numbers is defined by < m , n > · < x , y > = < mx − ny , my + nx >. For example, <1, 1> · <-2, 1> = <-3,-1>. A Ginkgo number < m , n > is called a divisor of a Ginkgo number < p , q > if there exists a Ginkgo number < x , y > such that < m , n > · < x , y > = < p , q >. For any Ginkgo number < m , n >, Ginkgo numbers <1, 0>, <0, 1>, <-1, 0>, <0,-1>, < m , n >, <- n , m >, <- m ,- n > and < n ,- m > are divisors of < m , n >. If m 2 + n 2 > 1, these Ginkgo numbers are distinct. In other words, any Ginkgo number such that m 2 + n 2 > 1 has at least eight divisors. A Ginkgo number < m , n > is called a prime if m 2 + n 2 > 1 and it has exactly eight divisors. Your mission is to check whether a given Ginkgo number is a prime or not. The following two facts might be useful to check whether a Ginkgo number is a divisor of another Ginkgo number. Suppose m 2 + n 2 > 0. Then, < m , n > is a divisor of < p , q > if and only if the integer m 2 + n 2 is a common divisor of mp + nq and mq − np . If < m , n > · < x , y > = < p , q >, then ( m 2 + n 2 )( x 2 + y 2 ) = p 2 + q 2 . Input The first line of the input contains a single integer, which is the number of datasets. The rest of the input is a sequence of datasets. Each dataset is a line containing two integers m and n , separated by a space. They designate the Ginkgo number < m , n >. You can assume 1 < m 2 + n 2 < 20000. Output For each dataset, output a character ' P ' in a line if the Ginkgo number is a prime. Output a character ' C ' in a line otherwise. Sample Input 8 10 0 0 2 -3 0 4 2 0 -13 -4 1 -2 -1 3 -1 Output for the Sample Input C C P C C P P C
35,819
Problem I: Cousin's Aunt Sarah is a girl who likes reading books. One day, she wondered about the relationship of a family in a mystery novel. The story said, B is A’s father’s brother’s son, and C is B’s aunt. Then she asked herself, “So how many degrees of kinship are there between A and C?” There are two possible relationships between B and C, that is, C is either B’s father’s sister or B’s mother’s sister in the story. If C is B’s father’s sister, C is in the third degree of kinship to A (A’s father’s sister). On the other hand, if C is B’s mother’s sister, C is in the fifth degree of kinship to A (A’s father’s brother’s wife’s sister). You are a friend of Sarah’s and good at programming. You can help her by writing a general program to calculate the maximum and minimum degrees of kinship between A and C under given relationship. The relationship of A and C is represented by a sequence of the following basic relations: father, mother, son, daughter, husband, wife, brother, sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, and niece. Here are some descriptions about these relations: X ’s brother is equivalent to X ’s father’s or mother’s son not identical to X . X ’s grandfather is equivalent to X ’s father’s or mother’s father. X ’s grandson is equivalent to X ’s son’s or daughter’s son. X ’s uncle is equivalent to X ’s father’s or mother’s brother. X ’s nephew is equivalent to X ’s brother’s or sister’s son. Similar rules apply to sister, grandmother, granddaughter, aunt and niece. In this problem, you can assume there are none of the following relations in the family: adoptions, marriages between relatives (i.e. the family tree has no cycles), divorces, remarriages, bigamous marriages and same-sex marriages. The degree of kinship is defined as follows: The distance from X to X ’s father, X ’s mother, X ’s son or X ’s daughter is one. The distance from X to X ’s husband or X ’s wife is zero. The degree of kinship between X and Y is equal to the shortest distance from X to Y deduced from the above rules. Input The input contains multiple datasets. The first line consists of a positive integer that indicates the number of datasets. Each dataset is given by one line in the following format: C is A(’s relation )* Here, relation is one of the following: father, mother, son, daughter, husband, wife, brother, sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, niece. An asterisk denotes zero or more occurance of portion surrounded by the parentheses. The number of relations in each dataset is at most ten. Output For each dataset, print a line containing the maximum and minimum degrees of kinship separated by exact one space. No extra characters are allowed of the output. Sample Input 7 C is A’s father’s brother’s son’s aunt C is A’s mother’s brother’s son’s aunt C is A’s son’s mother’s mother’s son C is A’s aunt’s niece’s aunt’s niece C is A’s father’s son’s brother C is A’s son’s son’s mother C is A Output for the Sample Input 5 3 5 1 2 2 6 0 2 0 1 1 0 0
35,820
Score : 1200 points Problem Statement There are N jewels, numbered 1 to N . The color of these jewels are represented by integers between 1 and K (inclusive), and the color of Jewel i is C_i . Also, these jewels have specified values, and the value of Jewel i is V_i . Snuke would like to choose some of these jewels to exhibit. Here, the set of the chosen jewels must satisfy the following condition: For each chosen jewel, there is at least one more jewel of the same color that is chosen. For each integer x such that 1 \leq x \leq N , determine if it is possible to choose exactly x jewels, and if it is possible, find the maximum possible sum of the values of chosen jewels in that case. Constraints 1 \leq N \leq 2 \times 10^5 1 \leq K \leq \lfloor N/2 \rfloor 1 \leq C_i \leq K 1 \leq V_i \leq 10^9 For each of the colors, there are at least two jewels of that color. All values in input are integers. Input Input is given from Standard Input in the following format: N K C_1 V_1 C_2 V_2 : C_N V_N Output Print N lines. In the i -th line, if it is possible to choose exactly i jewels, print the maximum possible sum of the values of chosen jewels in that case, and print -1 otherwise. Sample Input 1 5 2 1 1 1 2 1 3 2 4 2 5 Sample Output 1 -1 9 6 14 15 We cannot choose exactly one jewel. When choosing exactly two jewels, the total value is maximized when Jewel 4 and 5 are chosen. When choosing exactly three jewels, the total value is maximized when Jewel 1, 2 and 3 are chosen. When choosing exactly four jewels, the total value is maximized when Jewel 2, 3, 4 and 5 are chosen. When choosing exactly five jewels, the total value is maximized when Jewel 1, 2, 3, 4 and 5 are chosen. Sample Input 2 5 2 1 1 1 2 2 3 2 4 2 5 Sample Output 2 -1 9 12 12 15 Sample Input 3 8 4 3 2 2 3 4 5 1 7 3 11 4 13 1 17 2 19 Sample Output 3 -1 24 -1 46 -1 64 -1 77 Sample Input 4 15 5 3 87 1 25 1 27 3 58 2 85 5 19 5 39 1 58 3 12 4 13 5 54 4 100 2 33 5 13 2 55 Sample Output 4 -1 145 173 285 318 398 431 491 524 576 609 634 653 666 678
35,821
Elevator Time Limit: 8 sec / Memory Limit: 64 MB E: ゚レベヌタ あなたの友人はキリンのマヌクの匕越業者でアルバむトをしおいる 圌の仕事は建物から荷物を運び出すこずである 今回圌はある n 階建おのビルからいく぀かの荷物を運び出すこずになった 幞いこのビルにぱレベヌタが1぀備え付けられおいるため ゚レベヌタで荷物を運び出すこずにした 運び出すべき荷物は各階に耇数個あり荷物毎に重さが異なる ゚レベヌタには重量制限が蚭定されおおり重さ W を超える荷物を茉せるこずはできない ゚レベヌタは十分に広く重量制限を満たすならばどれだけ倚くの荷物でも茉せるこずができる ゚レベヌタは停止した階で荷物の搬入ず搬出を行うこずができる ベテランアルバむタヌである圌は゚レベヌタに乗らずに階段で移動する ゚レベヌタに荷物を積み蟌んだ埌階段で次の゚レベヌタの停止フロアに先回りし荷物の搬入ず搬出を行うのだ ベテランアルバむタヌの圌は荷物の搬入ず搬出を非垞に高速に行うこずができるので各フロアでの゚レベヌタの停止時間は無芖するこずができる よっお党おの荷物を1階に移動させるのに必芁な時間は゚レベヌタの移動距離から容易に算出できる 圌は荷物をできるだけ早く1階に移動させたい 圌はベテランアルバむタヌではあるがどのような手順で各階での荷物の出し入れを行えばよいのか分からない そこで圌は友人であるあなたに助けを求めおきた あなたの仕事は圌が党おの荷物を1階に移動させるために必芁な゚レベヌタの最小の移動距離を求めるこずである Input 入力は以䞋の圢匏で䞎えられる n m W 1階の荷物の情報 ... i 階の荷物の情報 ... n 階の荷物の情報 i 階の荷物の情報は以䞋の圢匏で䞎えられる(1 <= i <= n ) k i w 1 w 2 , ..., w j , ..., w k i 入力の圢匏の各倉数の意味は次の通りである n はフロア数(1 <= n <= 10000) m ぱレベヌタの初期䜍眮(1 <= m <= n) W ぱレベヌタの重量制限(1 <= W <= 10000) k i は荷物の数(0 <= k i <= 15, 1 <= k 1 + k 2 + ... + k n <= 15) w j は荷物 j の重さ(1 <= w j <= W ) Output 最小の移動距離を1行で出力せよ Sample Input 1 3 3 2 1 1 2 1 1 3 1 1 1 Sample Output 1 8 Sample Input 2 3 3 10 0 2 4 5 3 3 3 5 Sample Output 2 6 Sample Input 3 3 3 100 5 3 4 5 6 7 0 0 Sample Output 3 0
35,822
J - 刺身 問題文 き぀ねのしえるは川で釣りをしおいた黒くお现長い魚を手に入れるこずができたのでその堎で切り刻んで刺身にしお食べるこずにした 魚は䜓長が N センチメヌトルある奇劙なこずにこの魚は身䜓の郚分ごずに密床が異なっおいた 魚の身䜓を頭から 1 センチメヌトルごずに区切っお番号を 1, 2, ..., N ず付けるずき身䜓の i 番目の郚分の重みは w_i であった 魚の i 番目から j 番目たでの郚分を [i..j] ず衚すこずにする 最初しえるは魚の身䜓 [0..N-1] を 1 枚だけ持っおいるず芋なせるしえるはこれを切っおいき最終的に N 個に分割された魚の身䜓 [0..0], [1..1], ..., [N-1..N-1] を埗たい しえるは今野倖におりたな板などを持っおいないので次のようなアクロバティックな方法で魚の身䜓を切っおいくこずにした  たず魚の身䜓を 1 枚取るこれを [i..j] ずするこの魚の身䜓は長さが少なくずも 2 センチメヌトル以䞊でなければならないすなわち j-i ≥ 1 でなければならない次にそれを空䞭に投げるそしお日本刀を手に持ち宙に舞う魚を真っ二぀に切るこのずきしえるは匷靭な運動神経によっお任意の䜍眮でこの魚を切るこずができるが必ず 1 センチメヌトル区切りの䜍眮で切るものずするこれにより元の魚の身䜓 [i..j] を任意の切断䜍眮 k (i ≀ k < j) によっお [i..k] ず [k+1..j] の 2 ぀に分割するのである このアクロバティックな方法で魚の身䜓を 2 ぀に切るずき元の身䜓の重さ (= w i +w i+1 +...+w j ) だけコストがかかる しえるは魚のすべおの郚分を 1 センチメヌトル区切りに切るのにかかるコストの合蚈倀を最小にしたい 入力圢匏 入力は以䞋の圢匏で䞎えられる N w 1 w 2 ... w N N は魚の䜓長である w i は魚の i 番目の郚分の重さである 出力圢匏 魚を N 個に切り分けるのにかかるコストの合蚈の最小倀を出力せよ 制玄 2 ≀ N ≀ 4,000 1 ≀ w i ≀ 10 10 入力倀はすべお敎数である この問題の刀定には3 点分のテストケヌスのグルヌプが蚭定されおいる このグルヌプに含たれるテストケヌスは䞊蚘の制玄に加えお䞋蚘の制玄も満たす 1 ≀ N ≀ 100 入出力䟋 入力䟋 1 3 1 2 3 出力䟋 1 9 たず魚党䜓を 2 番目ず 3 番目の郚分の間で切るこれには 1+2+3 = 6 のコストがかかる 次に1 番目ず 2 番目の郚分の間で切るこれには 1+2=3 のコストがかかる合蚈で 6+3=9 のコストがかかりこれが最善手である 入力䟋 2 6 9876543210 9876543210 9876543210 9876543210 9876543210 9876543210 出力䟋 2 158024691360 入力䟋 3 10 127 131 137 139 149 151 157 163 167 173 出力䟋 3 5016 Writer: 楠本充 Tester: 花田裕䞀朗
35,823
Score : 100 points Problem Statement We have 2N pots. The market price of the i -th pot (1 ≀ i ≀ 2N) is p_i yen (the currency of Japan). Now, you and Lunlun the dachshund will alternately take one pot. You will go first, and we will continue until all the pots are taken by you or Lunlun. Since Lunlun does not know the market prices of the pots, she will always choose a pot randomly from the remaining pots with equal probability. You know this behavior of Lunlun, and the market prices of the pots. Let the sum of the market prices of the pots you take be S yen. Your objective is to maximize the expected value of S . Find the expected value of S when the optimal strategy is adopted. Constraints 1 ≀ N ≀ 10^5 1 ≀ p_i ≀ 2 × 10^5 All input values are integers. Input Input is given from Standard Input in the following format: N p_1 : p_{2N} Output Print the expected value of S when the strategy to maximize the expected value of S is adopted. The output is considered correct if its absolute or relative error from the judge's output is at most 10^{-9} . Sample Input 1 1 150000 108 Sample Output 1 150000.0 Naturally, you should choose the 150000 yen pot. Sample Input 2 2 50000 50000 100000 100000 Sample Output 2 183333.3333333333 First, you will take one of the 100000 yen pots. The other 100000 yen pot will become yours if it is not taken in Lunlun's next turn, with probability 2/3 . If it is taken, you will have to settle for a 50000 yen pot. Thus, the expected value of S when the optimal strategy is adopted is 2/3 × (100000 + 100000) + 1/3 × (100000 + 50000) = 183333.3333

35,824
Score : 300 points Problem Statement Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print -1 . Constraints 1 \leq A \leq B \leq 100 A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print -1 . Sample Input 1 2 2 Sample Output 1 25 If the price of a product before tax is 25 yen, the amount of consumption tax levied on it is: When the consumption tax rate is 8 percent: \lfloor 25 \times 0.08 \rfloor = \lfloor 2 \rfloor = 2 yen. When the consumption tax rate is 10 percent: \lfloor 25 \times 0.1 \rfloor = \lfloor 2.5 \rfloor = 2 yen. Thus, the price of 25 yen satisfies the condition. There are other possible prices, such as 26 yen, but print the minimum such price, 25 . Sample Input 2 8 10 Sample Output 2 100 If the price of a product before tax is 100 yen, the amount of consumption tax levied on it is: When the consumption tax rate is 8 percent: \lfloor 100 \times 0.08 \rfloor = 8 yen. When the consumption tax rate is 10 percent: \lfloor 100 \times 0.1 \rfloor = 10 yen. Sample Input 3 19 99 Sample Output 3 -1 There is no price before tax satisfying this condition, so print -1 .
35,825
ICPC Ranking Your mission in this problem is to write a program which, given the submission log of an ICPC (International Collegiate Programming Contest), determines team rankings. The log is a sequence of records of program submission in the order of submission. A record has four fields: elapsed time, team number, problem number, and judgment. The elapsed time is the time elapsed from the beginning of the contest to the submission. The judgment field tells whether the submitted program was correct or incorrect, and when incorrect, what kind of an error was found. The team ranking is determined according to the following rules. Note that the rule set shown here is one used in the real ICPC World Finals and Regionals, with some detail rules omitted for simplification. Teams that solved more problems are ranked higher. Among teams that solve the same number of problems, ones with smaller total consumed time are ranked higher. If two or more teams solved the same number of problems, and their total consumed times are the same, they are ranked the same. The total consumed time is the sum of the consumed time for each problem solved. The consumed time for a solved problem is the elapsed time of the accepted submission plus 20 penalty minutes for every previously rejected submission for that problem. If a team did not solve a problem, the consumed time for the problem is zero, and thus even if there are several incorrect submissions, no penalty is given. You can assume that a team never submits a program for a problem after the correct submission for the same problem. Input The input is a sequence of datasets each in the following format. The last dataset is followed by a line with four zeros. M T P R m 1 t 1 p 1 j 1 m 2 t 2 p 2 j 2 ..... m R t R p R j R The first line of a dataset contains four integers M , T , P , and R . M is the duration of the contest. T is the number of teams. P is the number of problems. R is the number of submission records. The relations 120 ≀ M ≀ 300, 1 ≀ T ≀ 50, 1 ≀ P ≀ 10, and 0 ≀ R ≀ 2000 hold for these values. Each team is assigned a team number between 1 and T , inclusive. Each problem is assigned a problem number between 1 and P , inclusive. Each of the following R lines contains a submission record with four integers m k , t k , p k , and j k (1 ≀ k ≀ R ). m k is the elapsed time. t k is the team number. p k is the problem number. j k is the judgment (0 means correct, and other values mean incorrect). The relations 0 ≀ m k ≀ M −1, 1 ≀ t k ≀ T , 1 ≀ p k ≀ P , and 0 ≀ j k ≀ 10 hold for these values. The elapsed time fields are rounded off to the nearest minute. Submission records are given in the order of submission. Therefore, if i < j , the i -th submission is done before the j -th submission ( m i ≀ m j ). In some cases, you can determine the ranking of two teams with a difference less than a minute, by using this fact. However, such a fact is never used in the team ranking. Teams are ranked only using time information in minutes. Output For each dataset, your program should output team numbers (from 1 to T ), higher ranked teams first. The separator between two team numbers should be a comma. When two teams are ranked the same, the separator between them should be an equal sign. Teams ranked the same should be listed in decreasing order of their team numbers. Sample Input 300 10 8 5 50 5 2 1 70 5 2 0 75 1 1 0 100 3 1 0 150 3 2 0 240 5 5 7 50 1 1 0 60 2 2 0 70 2 3 0 90 1 3 0 120 3 5 0 140 4 1 0 150 2 4 1 180 3 5 4 15 2 2 1 20 2 2 1 25 2 2 0 60 1 1 0 120 5 5 4 15 5 4 1 20 5 4 0 40 1 1 0 40 2 2 0 120 2 3 4 30 1 1 0 40 2 1 0 50 2 2 0 60 1 2 0 120 3 3 2 0 1 1 0 1 2 2 0 300 5 8 0 0 0 0 0 Output for the Sample Input 3,1,5,10=9=8=7=6=4=2 2,1,3,4,5 1,2,3 5=2=1,4=3 2=1 1,2,3 5=4=3=2=1
35,826
Score : 600 points Problem Statement You are given a positive integer N . Find the number of the pairs of integers u and v (0≩u,v≩N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v . Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7 . Constraints 1≩N≩10^{18} Input The input is given from Standard Input in the following format: N Output Print the number of the possible pairs of integers u and v , modulo 10^9+7 . Sample Input 1 3 Sample Output 1 5 The five possible pairs of u and v are: u=0,v=0 (Let a=0,b=0 , then 0 xor 0=0 , 0+0=0 .) u=0,v=2 (Let a=1,b=1 , then 1 xor 1=0 , 1+1=2 . u=1,v=1 (Let a=1,b=0 , then 1 xor 0=1 , 1+0=1 . u=2,v=2 (Let a=2,b=0 , then 2 xor 0=2 , 2+0=2 . u=3,v=3 (Let a=3,b=0 , then 3 xor 0=3 , 3+0=3 . Sample Input 2 1422 Sample Output 2 52277 Sample Input 3 1000000000000000000 Sample Output 3 787014179
35,827
残り物には犏がある K 個の石から、 P 人が順番に぀ず぀石を取るゲヌムがありたす。 P 人目が石を取った時点で、ただ石が残っおいれば、たた人目から順番に぀ず぀石を取っおいきたす。このゲヌムでは、最埌の石を取った人が勝ちずなりたす。 K ず P が䞎えられたずき、䜕人目が勝぀か刀定するプログラムを䜜成しおください。 入力 入力は以䞋の圢匏で䞎えられる。 N K 1 P 1 K 2 P 2 : K N P N 行目にはゲヌムを行う回数 N (1 ≀ N ≀ 100) が䞎えられる。続く N 行に、 i 回目のゲヌムにおける石の個数 K i (2 ≀ K i ≀ 1000) ず、ゲヌムに参加する人数 P i (2 ≀ P i ≀ 1000) が䞎えられる。 出力 それぞれのゲヌムに぀いお、䜕人目が勝぀かを行に出力する。 入出力䟋 入力䟋 3 10 3 2 10 4 2 出力䟋 1 2 2
35,828
Intersection of Circles For given two circles $c1$ and $c2$, print 4 if they do not cross (there are 4 common tangent lines), 3 if they are circumscribed (there are 3 common tangent lines), 2 if they intersect (there are 2 common tangent lines), 1 if a circle is inscribed in another (there are 1 common tangent line), 0 if a circle includes another (there is no common tangent line). Input Coordinates and radii of $c1$ and $c2$ are given in the following format. $c1x \; c1y \; c1r$ $c2x \; c2y \; c2r$ $c1x$, $c1y$ and $c1r$ represent the center coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the center coordinate and radius of the second circle. All input values are given in integers. Output Print "4", "3", "2", "1" or "0" in a line. Constraints $-1,000 \leq c1x, c1y, c2x, c2y \leq 1,000$ $1 \leq c1r, c2r \leq 1,000$ $c1$ and $c2$ are different Sample Input 1 1 1 1 6 2 2 Sample Output 1 4 Sample Input 2 1 2 1 4 2 2 Sample Output 2 3 Sample Input 3 1 2 1 3 2 2 Sample Output 3 2 Sample Input 4 0 0 1 1 0 2 Sample Output 4 1 Sample Input 5 0 0 1 0 0 2 Sample Output 5 0
35,829
プログラミングコンテスト II 癜虎倧孊では毎幎プログラミングコンテストを開催しおいたす。コンテストは党おのチヌムの埗点が 0の状態から開始し、解答状況に応じお埗点が加算されおいきたす。このコンテストでは、埗点の高い順に順䜍付けが行われたす。チヌムの総数を N ずしたずき、チヌムには 1 から N の番号がそれぞれ割り圓おられおいたす。埗点が同じ堎合は番号がより小さい方が䞊䜍になりたす。 癜虎倧孊では、コンテストを盛り䞊げるために芳戊甚のランキングシステムを開発しおいたす。開発チヌムの䞀員であるあなたは、このシステムの䞀郚であるプログラムの䜜成を任されおいたす。 䞎えられた呜什に埓っお、埗点の曎新ず、指定された順䜍のチヌムの番号ず埗点を報告するプログラムを䜜成せよ。 Input 入力は以䞋の圢匏で䞎えられる。 N C command 1 command 2 : command C 行目にチヌム数 N (2 ≀ N ≀ 100000) ず呜什の数 C (1 ≀ C ≀ 100000)が䞎えられる。続く C 行に、行ず぀呜什が䞎えられる。各呜什は以䞋の圢匏で䞎えられる。 0 t p たたは 1 m 最初の数字が0のずき曎新呜什、1のずき報告呜什を衚す。曎新呜什では指定された番号 t (1 ≀ t ≀ N ) のチヌムに、敎数で䞎えられる埗点 p (1 ≀ p ≀ 10 9 ) を加算する。報告呜什では指定された順䜍 m (1 ≀ m ≀ N ) のチヌムの番号ず埗点を報告する。ただし、報告呜什は少なくずも回珟れるものずする。 Output 各報告呜什に察しお、指定された順䜍のチヌムの番号ず埗点を空癜区切りで行に出力する。 Sample Input 1 3 11 0 2 5 0 1 5 0 3 4 1 1 1 2 1 3 0 3 2 1 1 0 2 1 1 2 1 3 Sample Output 1 1 5 2 5 3 4 3 6 3 6 1 5 Sample Input 2 5 2 1 1 1 2 Sample Output 2 1 0 2 0
35,830
Score : 500 points Problem Statement We have N camels numbered 1,2,\ldots,N . Snuke has decided to make them line up in a row. The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise. Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel. Solve this problem for each of the T test cases given. Constraints All values in input are integers. 1 \leq T \leq 10^5 1 \leq N \leq 2 \times 10^{5} 1 \leq K_i \leq N 1 \leq L_i, R_i \leq 10^9 The sum of values of N in each input file is at most 2 \times 10^5 . Input Input is given from Standard Input in the following format: T \mathrm{case}_1 \vdots \mathrm{case}_T Each case is given in the following format: N K_1 L_1 R_1 \vdots K_N L_N R_N Output Print T lines. The i -th line should contain the answer to the i -th test case. Sample Input 1 3 2 1 5 10 2 15 5 3 2 93 78 1 71 59 3 57 96 19 19 23 16 5 90 13 12 85 70 19 67 78 12 16 60 18 48 28 5 4 24 12 97 97 4 57 87 19 91 74 18 100 76 7 86 46 9 100 57 3 76 73 6 84 93 1 6 84 11 75 94 19 15 3 12 11 34 Sample Output 1 25 221 1354 In the first test case, it is optimal to line up the camels in the order 2, 1 . Camel 1 is not the frontmost camel, so its happiness will be 10 . Camel 2 is among the two frontmost camels, so its happiness will be 15 . In the second test case, it is optimal to line up the camels in the order 2, 1, 3 . Camel 1 is among the two frontmost camels, so its happiness will be 93 . Camel 2 is the frontmost camel, so its happiness will be 71 . Camel 3 is among the three frontmost camels, so its happiness will be 57 .
35,831
Score : 1200 points Problem Statement Takahashi is a magician. He can cast a spell on an integer sequence (a_1,a_2,...,a_M) with M terms, to turn it into another sequence (s_1,s_2,...,s_M) , where s_i is the sum of the first i terms in the original sequence. One day, he received N integer sequences, each with M terms, and named those sequences A_1,A_2,...,A_N . He will try to cast the spell on those sequences so that A_1 < A_2 < ... < A_N will hold, where sequences are compared lexicographically. Let the action of casting the spell on a selected sequence be one cast of the spell. Find the minimum number of casts of the spell he needs to perform in order to achieve his objective. Here, for two sequences a = (a_1,a_2,...,a_M), b = (b_1,b_2,...,b_M) with M terms each, a < b holds lexicographically if and only if there exists i (1 ≩ i ≩ M) such that a_j = b_j (1 ≩ j < i) and a_i < b_i . Constraints 1 ≩ N ≩ 10^3 1 ≩ M ≩ 10^3 Let the j -th term in A_i be A_{(i,j)} , then 1 ≩ A_{(i,j)} ≩ 10^9 . Partial Scores In the test set worth 200 points, Takahashi can achieve his objective by at most 10^4 casts of the spell, while keeping the values of all terms at most 10^9 . In the test set worth another 800 points, A_{(i,j)} ≩ 80 . Input The input is given from Standard Input in the following format: N M A_{(1,1)} A_{(1,2)} 
 A_{(1,M)} A_{(2,1)} A_{(2,2)} 
 A_{(2,M)} : A_{(N,1)} A_{(N,2)} 
 A_{(N,M)} Output Print the minimum number of casts of the spell Takahashi needs to perform. If he cannot achieve his objective, print -1 instead. Sample Input 1 3 3 2 3 1 2 1 2 2 6 3 Sample Output 1 1 Takahashi can achieve his objective by casting the spell on A_2 once to turn it into (2 , 3 , 5) . Sample Input 2 3 3 3 2 10 10 5 4 9 1 9 Sample Output 2 -1 In this case, Takahashi cannot achieve his objective by casting the spell any number of times. Sample Input 3 5 5 2 6 5 6 9 2 6 4 9 10 2 6 8 6 7 2 1 7 3 8 2 1 4 8 3 Sample Output 3 11
35,832
Problem H: Digital Racing Circuit You have an ideally small racing car on an x-y plane (0 ≀ x, y ≀ 255, where bigger y denotes upper coordinate). The racing circuit course is figured by two solid walls. Each wall is a closed loop of connected line segments. End point coordinates of every line segment are both integers (See Figure 1). Thus, a wall is represented by a list of end point integer coordinates ( x 1 , y 1 ), ( x 2 , y 2 ), ...,( x n , y n ). The start line and the goal line are identical. Figure 1. A Simple Course For the qualification run, you start the car at any integer coordinate position on the start line, say ( s x , s y ). At any clock t (≥ 0), according to the acceleration parameter at t , ( a x,t , a y,t ), the velocity changes instantly to ( v x,t-1 + a x,t , v y,t-1 + a y,t ), if the velocity at t - 1 is ( v x,t-1 , v y,t-1 ). The velocity will be kept constant until the next clock. It is assumed that the velocity at clock -1, ( v x,-1 , v y,-1 ) is (0, 0). Each of the acceleration components must be either -1, 0, or 1, because your car does not have so fantastic engine and brake. In other words, any successive pair of velocities should not differ more than 1 for either x -component or y -component. Note that your trajectory will be piecewise linear as the walls are. Your car should not touch nor run over the circuit wall, or your car will be crashed, even at the start line. The referee watches your car's trajectory very carefully, checking whether or not the trajectory touches the wall or attempts to cross the wall. The objective of the qualification run is to finish your run within as few clock units as possible, without suffering from any interference by other racing cars. That is, you run alone the circuit around clockwise and reach, namely touch or go across the goal line without having been crashed. Don't be crashed even in the last trajectory segment after you reach the goal line. But we don't care whatever happens after that clock Your final lap time is the clock t when you reach the goal line for the first time after you have once left the start line. But it needs a little adjustment at the goal instant. When you cross the goal line, only the necessary fraction of your car's last trajectory segment is counted. For example, if the length of your final trajectory segment is 3 and only its 1/3 fraction is needed to reach the goal line, you have to add only 0.333 instead of 1 clock unit. Drivers are requested to control their cars as cleverly as possible to run fast but avoiding crash. ALAS! The racing committee decided that it is too DANGEROUS to allow novices to run the circuit. In the last year, it was reported that some novices wrenched their fingers by typing too enthusiastically their programs. So, this year, you are invited as a referee assistant in order to accumulate the experience on this dangerous car race. A number of experienced drivers are now running the circuit for the qualification for semi-finals. They submit their driving records to the referee. The referee has to check the records one by one whether it is not a fake. Now, you are requested to make a program to check the validity of driving records for any given course configuration. Is the start point right on the start line without touching the walls? Is every value in the acceleration parameter list either one of -1, 0, and 1? Does the length of acceleration parameter list match the reported lap time? That is, aren't there any excess acceleration parameters after the goal, or are these enough to reach the goal? Doesn't it involve any crash? Does it mean a clockwise running all around? (Note that it is not inhibited to run backward temporarily unless crossing the start line again.) Is the lap time calculation correct? You should allow a rounding error up to 0.01 clock unit in the lap time. Input The input consists of a course configuration followed by a number of driving records on that course. A course configuration is given by two lists representing the inner wall and the outer wall, respectively. Each line shows the end point coordinates of the line segments that comprise the wall. A course configuration looks as follows: i x ,1 i y ,1 ..... i x ,N i y ,N 99999 o x ,1 o y ,1 ..... o x ,M o y ,M 99999 where data are alternating x -coordinates and y -coordinates that are all non-negative integers (≀ 255) terminated by 99999. The start/goal line is a line segment connecting the coordinates ( i x ,1 , i y ,1 ) and ( o x ,1 , o y ,1 ). For simplicity, i y ,1 is assumed to be equal to o y ,1 ; that is, the start/goal line is horizontal on the x-y plane. Note that N and M may vary among course configurations, but do not exceed 100, because too many curves involve much danger even for experienced drivers. You need not check the validity of the course configuration. A driving record consists of three parts, which is terminated by 99999: two integers s x , s y for the start position ( s x , s y ), the lap time with three digits after the decimal point, and the sequential list of acceleration parameters at all clocks until the goal. It is assumed that the length of the acceleration parameter list does not exceed 500. A driving record looks like the following: s x s y lap-time a x ,0 a y ,0 a x ,1 a y ,1 ... a x , L a y , L 99999 Input is terminated by a null driving record; that is, it is terminated by a 99999 that immediately follows 99999 of the last driving record. Output The test result should be reported by simply printing OK or NG for each driving record, each result in each line. No other letter is allowed in the result. Sample Input 6 28 6 32 25 32 26 27 26 24 6 24 99999 2 28 2 35 30 35 30 20 2 20 99999 3 28 22.667 0 1 1 1 1 0 0 -1 0 -1 1 0 0 0 1 0 -1 0 0 -1 -1 -1 -1 0 -1 0 -1 -1 -1 1 -1 1 -1 1 -1 0 1 0 1 1 1 1 1 0 1 1 99999 5 28 22.667 0 1 -1 1 1 0 1 -1 1 -1 1 0 1 0 1 0 -1 -1 -1 0 -1 -1 -1 0 -1 1 -1 -1 -1 1 -1 0 -1 1 -1 0 1 0 1 0 1 1 1 1 1 1 99999 4 28 6.333 0 1 0 1 1 -1 -1 -1 0 -1 0 -1 0 -1 99999 3 28 20.000 0 -1 1 -1 1 0 1 1 1 1 1 0 -1 0 -1 0 -1 1 -1 1 -1 1 -1 0 -1 -1 -1 -1 -1 -1 -1 0 1 0 1 -1 1 -1 1 -1 99999 99999 Output for the Sample Input OK NG NG NG
35,833
E: 札 / Fuda この問題はリアクティブ問題です。 サヌバヌ偎に甚意されたプログラムず察話的に応答するこずで正答を導くプログラムを䜜成する必芁がありたす。 問題文 湖に浮かぶ $N$ 個の小島からなるビワコずいう村がある。 各小島には $0$ から $N-1$ たで番号が振られおいる。 村には島ず島の間に架かる橋が $M$ 本あり、$0$ から $M-1$ たで番号が振られおいる。 橋は双方向に移動可胜である。 ここで蚀う橋ずは単に島ず島の間の通り道ずいうこずであり、取り陀くず互いに到達䞍可胜な島の組が増える意味ではない。 最近、橋の䞡端に掲瀺板を蚭眮し、その橋を枡った先の島から橋を $1$ 本だけ䜿っお移動できる島 (今いる島を含たない) の番号の曞かれた札を貌るこずで、 スムヌズな移動を実珟する蚈画が持ち䞊がった。 䞀枚の札には䞀぀の移動先しか曞くこずが出来ないため、移動できる島の数だけ札が必芁になる。 この札の䜜成を呜じられたあなたは、札は党郚で䜕枚必芁かを調べるこずにした。 村には、か぀お党おの橋を架けた橋職人がいる。 たた、各島にはその島に䜏んでいる村人がいる。 村は広倧で党おの掲瀺板を芋お回るのは骚が折れるため、本郚から電話で圌らに質問をするこずで必芁な札の枚数を求めるこずにした。 橋職人ぞの質問では、たず、䜕番の橋の情報が知りたいかを橋職人に䌝える。 するず、どの島ずどの島の間に該圓する橋を架けたかを確実に教えおくれる (edgク゚リ)。 䜏人ぞの質問では、たず聞きたい島の番号$i$を䌝える。 するず、島 $i$ にかかる橋の数ずその橋がどこにかかっおいるかを教えおくれる (lst ク゚リ)。 しかし、貧匱な通信網を䜿甚しおいるため、各橋に察しお、80% の確率で情報が抜け萜ちおしたう。 札の発泚たで時間がないので党䜓で倚くおも $3N$ 回しか質問ができない。 以䞊の条件のもずで、必芁な札の数を求めるプログラムを曞きなさい。 入出力仕様 以降では、あなたが提出したプログラムを「解答」、ゞャッゞ偎が甚意したプログラムを「ゞャッゞ」ず呌ぶ。 入出力の詳现な仕様を以䞋に瀺すが、先にサンプルを芋るず速い。 島ず橋の数 ゞャッゞは、たず島の数 $N$ ず橋の数の合蚈 $M$ を $1$ 行に出力する。 N M 続いお、解答は edg, lst ク゚リを最倧 $3N$ 回、 ans をちょうど 1 回ゞャッゞに察しお送るこずができる。 edg ク゚リ 解答の edg ク゚リに察し、ゞャッゞは橋$i$の䞡端の島の番号を答える。解答は次の圢匏で出力せよ。 edg i これに察しお、ゞャッゞは次の圢匏で応答する。 a b $a$, $b$ は橋 $i$ が結ぶ島の番号である。 lst ク゚リ 解答の lst ク゚リに察し、ゞャッゞは小島 $i$ にかかる橋の本数ず、それぞれの橋の行き先の島の番号を答える。解答は次の圢匏で出力せよ。 lst i これに察しお、ゞャッゞは次の圢匏で応答する。 k v1 v2 v3 
 vk $k$ は島 $i$ にかかる橋の数である。 続く $v_1 \cdots v_k$ は頂点$i$から橋を䞀床だけ䜿っお移動可胜な頂点の番号のリストである。 各橋の行き先 $v_j$ に察し、$v_j \ge 0$ の堎合はその情報がしっかり䌝わったこずを衚す。$v_j = -1$ の堎合は情報が抜け萜ちおいるこずを衚す。 $-1$ かどうかは乱数で決められ、80% の確率で $-1$ ずなる。したがっお、同じ $i$ に察しお耇数回このク゚リを実行するず、結果は倉わりうる。たた、順番も䞍定である。 ans ク゚リ 解答の ans ク゚リによっお、答えを出力できる。このク゚リは 1 床しか行うこずが出来ず、結果が正しくない堎合は盎ちに誀答ずなる。 このク゚リの実行埌に、解答は盎ちに正垞終了せよ。 $X$ を答えずしお出力したい堎合の圢匏は以䞋の通りである。 ans X 制玄ず泚意 $1 \le N \le 100$ $0 \le M \le N(N-1)/2$ 橋は異なる 2 ぀の島の間に架かっおいる。 異なる橋が、同じ 2 ぀の島を結ぶこずはない。 ans 以倖のク゚リは高々 $3N$ 回しか投げられない。 ゞャッゞプログラムの出力は党お $1$ 行か぀スペヌス区切りの敎数からなる。 仕様に埓わない出力の結果は䞍定である。 解答はゞャッゞの応答をすぐに暙準入力で受け取らなければならない。 解答はク゚リを出力した盎埌にバッファを空にせよ。最小の解答プログラム䟋を䞋に瀺す。C、C++以倖の蚀語は各自で調べおほしい。 C #include <stdio.h> int main(){ int n,m; scanf("%d %d", & n, &m); printf("ans 100\n"); // 答えをゞャッゞに提出 fflush(stdout); // フラッシュ return 0; } C++ #include <iostream> using namespace std; int main(){ int n,m; cin >> n >> m; cout << "ans 100" << endl; // 改行盎埌にフラッシュ // cout << "ans 100\n" << flush; // 䞊ず同じ } サンプル 解答プログラムずゞャッゞプログラムの入出力䟋を以䞋に瀺す。 問題文の図䞭の村に察する答えを求めおいる。
35,834
Connected Components Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network. Input In the first line, two integer $n$ and $m$ are given. $n$ is the number of users in the SNS and $m$ is the number of relations in the SNS. The users in the SNS are identified by IDs $0, 1, ..., n-1$. In the following $m$ lines, the relations are given. Each relation is given by two integers $s$ and $t$ that represents $s$ and $t$ are friends (and reachable each other). In the next line, the number of queries $q$ is given. In the following $q$ lines, $q$ queries are given respectively. Each query consists of two integers $s$ and $t$ separated by a space character. Output For each query, print "yes" if $t$ is reachable from $s$ through the social network, "no" otherwise. Constraints $2 \leq n \leq 100,000$ $0 \leq m \leq 100,000$ $1 \leq q \leq 10,000$ Sample Input 10 9 0 1 0 2 3 4 5 7 5 6 6 7 6 8 7 8 8 9 3 0 1 5 9 1 3 Sample Output yes yes no
35,835
Score : 300 points Problem Statement There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0) , (W,0) , (W,H) , and (0,H) . You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum. Constraints 1 \leq W,H \leq 10^9 0\leq x\leq W 0\leq y\leq H All values in input are integers. Input Input is given from Standard Input in the following format: W H x y Output Print the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise. The area printed will be judged correct when its absolute or relative error is at most 10^{-9} . Sample Input 1 2 3 1 2 Sample Output 1 3.000000 0 The line x=1 gives the optimal cut, and no other line does. Sample Input 2 2 2 1 1 Sample Output 2 2.000000 1
35,836
The Phantom Mr. Hoge is in trouble. He just bought a new mansion, but it’s haunted by a phantom. He asked a famous conjurer Dr. Huga to get rid of the phantom. Dr. Huga went to see the mansion, and found that the phantom is scared by its own mirror images. Dr. Huga set two flat mirrors in order to get rid of the phantom. As you may know, you can make many mirror images even with only two mirrors. You are to count up the number of the images as his assistant. Given the coordinates of the mirrors and the phantom, show the number of images of the phantom which can be seen through the mirrors. Input The input consists of multiple test cases. Each test cases starts with a line which contains two positive integers, p x and p y (1 ≀ p x , p y ≀ 50), which are the x - and y -coordinate of the phantom. In the next two lines, each line contains four positive integers u x , u y , v x and v y (1 ≀ u x , u y , v x , v y ≀ 50), which are the coordinates of the mirror. Each mirror can be seen as a line segment, and its thickness is negligible. No mirror touches or crosses with another mirror. Also, you can assume that no images will appear within the distance of 10 -5 from the endpoints of the mirrors. The input ends with a line which contains two zeros. Output For each case, your program should output one line to the standard output, which contains the number of images recognized by the phantom. If the number is equal to or greater than 100, print “TOO MANY” instead. Sample Input 4 4 3 3 5 3 3 5 5 6 4 4 3 3 5 3 3 5 5 5 0 0 Output for the Sample Input 4 TOO MANY
35,837
Score : 300 points Problem Statement We have a 2 \times N grid. We will denote the square at the i -th row and j -th column ( 1 \leq i \leq 2 , 1 \leq j \leq N ) as (i, j) . You are initially in the top-left square, (1, 1) . You will travel to the bottom-right square, (2, N) , by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel? Constraints 1 \leq N \leq 100 1 \leq A_{i, j} \leq 100 ( 1 \leq i \leq 2 , 1 \leq j \leq N ) Input Input is given from Standard Input in the following format: N A_{1, 1} A_{1, 2} ... A_{1, N} A_{2, 1} A_{2, 2} ... A_{2, N} Output Print the maximum number of candies that can be collected. Sample Input 1 5 3 2 2 4 1 1 2 2 2 1 Sample Output 1 14 The number of collected candies will be maximized when you: move right three times, then move down once, then move right once. Sample Input 2 4 1 1 1 1 1 1 1 1 Sample Output 2 5 You will always collect the same number of candies, regardless of how you travel. Sample Input 3 7 3 3 4 5 4 5 3 5 3 4 4 2 3 2 Sample Output 3 29 Sample Input 4 1 2 3 Sample Output 4 5
35,838
カヌドの組み合わせ 敎数が曞いおあるカヌドが䜕枚か入っおいる袋を䜿っおゲヌムをしたしょう。各回のゲヌムで参加者はたず、奜きな数 n を䞀぀宣蚀したす。そしお、袋の䞭から適圓な枚数だけカヌドを䞀床に取り出しお、それらのカヌドに曞かれた数の総和が n に等しければ豪華賞品がもらえたす。なお、それぞれのゲヌム終了埌カヌドは袋に戻されたす。 袋の䞭の m 皮類のカヌドの情報および、 g 回のゲヌムで参加者が宣蚀した数を入力ずし、それぞれのゲヌムで豪華商品をもらえるカヌドの組み合わせが䜕通りあるかを出力するプログラムを䜜成しおください。 Input 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 m a 1 b 1 a 2 b 2 : a m b m g n 1 n 2 : n g 行目にカヌドの皮類数 m 1 ≀ m ≀ 7、続く m 行に i 皮類目のカヌドに曞かれた敎数 a i (1 ≀ a i ≀ 100) ずその枚数 b i (1 ≀ b i ≀ 10) が空癜区切りで䞎えられたす。 続く行にゲヌムの回数 g (1 ≀ g ≀ 10)、続く g 行にゲヌム i で宣蚀された敎数 n i (1 ≀ n i ≀ 1,000) が䞎えられたす。 デヌタセットの数は 100 を超えない。 Output 入力デヌタセットごずに、 i 行目にゲヌム i で豪華賞品がもらえるカヌドの組み合わせ数を出力したす。 Sample Input 5 1 10 5 3 10 3 25 2 50 2 4 120 500 100 168 7 1 10 3 10 5 10 10 10 25 10 50 10 100 10 3 452 574 787 0 Output for the Sample Input 16 0 12 7 9789 13658 17466
35,839
Problem H: Count Words Problem $M$ 皮類の文字がある。それらを䜿っお長さ $N$ の文字列を䜜る。䜿われおいる文字の皮類数が $K$ 以䞊であるような文字列は䜕通りあるか。$998244353$ で割ったあたりを求めよ。 ここで長さ $N$ の2぀の文字列が異なるずは以䞋のように定矩される。 2぀の文字列を $S = S_1S_2 \ldots S_N$, $T = T_1T_2 \ldots T_N$ ずした堎合に、$S_i \neq T_i$ ずなるような $i$ $(1 \leq i \leq N)$ が存圚する。 Input 入力は以䞋の圢匏で䞎えられる。 $M$ $N$ $K$ 1行に $M, N, K$ が空癜区切りで䞎えられる。 Constraints 入力は以䞋の条件を満たす。 $1 \leq M \leq 10^{18} $ $1 \leq N \leq 10^{18} $ $1 \leq K \leq 1000 $ 入力はすべお敎数 Output 䜿われおいる文字の皮類数が $K$ 以䞊であるような長さ $N$ の文字列の通り数を $998244353$ で割ったあたりを出力せよ。 Sample Input 1 2 10 1 Sample Output 1 1024 Sample Input 2 1 1 2 Sample Output 2 0 Sample Input 3 5 10 3 Sample Output 3 9755400 Sample Input 4 7 8 3 Sample Output 4 5759460 Sample Input 5 1000000000000000000 1000000000000000000 1000 Sample Output 5 133611974
35,840
お土産賌入蚈画 (Gifts) 問題 オヌストラリアに旅行に来た JOI 君は様々な堎所で芳光を楜しみ぀いに垰囜する日がやっおきた今JOI 君は垰りの飛行機が出発する囜際空枯のある町にいるこの町は東西南北に区画敎理されおおり各区画には道土産店䜏宅囜際空枯がある JOI 君は最も北西の区画から出発しお最も南東の区画の囜際空枯を目指す JOI 君は今いる区画から隣り合った区画に移動するこずができるが䜏宅のある区画には入るこずはできないたた飛行機の時間に間に合わせるために今いる区画の東か南の区画にのみ移動するただし時間にはいくらか䜙裕があるためK 回たで今いる区画の北か西の区画ぞ移動するこずができる JOI 君は土産店のある区画に入るず日本の友人たちのためにお土産を買うJOI 君は土産店に぀いお入念に䞋調べをしおいたのでどの土産店に行ったら䜕個のお土産を買うこずができるかが分かっおいるJOI 君が賌入できるお土産の個数の最倧倀を求めるプログラムを䜜成せよ ただしお土産を買う時間は無芖できるずし同じ土産店に 2 床以䞊蚪れたずきは最初に蚪れたずきだけお土産を買う 入力 入力は 1 + H 行からなる 1 行目には3 ぀の敎数 H, W, K (2 ≩ H ≩ 50, 2 ≩ W ≩ 50, 1 ≩ K ≩ 3) が空癜を区切りずしお曞かれおいる 続く H 行にはそれぞれ W 文字からなる文字列が曞かれおおり区画の情報を衚す北から i 番目西から j 番目の区画を (i, j) ず衚す (1 ≩ i ≩ H, 1 ≩ j ≩ W) i 行目の j 番目の文字は区画 (i, j) が道か囜際空枯である堎合は '.' であり䜏宅である堎合は '#' である 土産店である堎合は '1', '2', ..., '9' のいずれかでありその土産店で買うこずができるお土産の個数を衚す 䞎えられる入力デヌタにおいおはJOI 君がはじめにいる最も北西の区画が道であるこずは保蚌されおいるたたJOI 君が囜際空枯にたどり着けるこずは保蚌されおいる 出力 JOI 君が賌入できるお土産の個数の最倧倀を衚す敎数を 1 行で出力せよ 入出力䟋 入力䟋 1 5 4 2 ...# .#.# .#73 8##. .... 出力䟋 1 11 入出力䟋 1 においおJOI 君は 3 回南ぞ進み区画 (4, 1) の土産店で買い物をした埌さらに南ぞ 1 回東ぞ 3 回進みそこから北ぞ 2 回進むこずで区画 (3, 4) の土産店で買い物をする最埌に南ぞ 2 回進んで囜際空枯ぞたどり着くず合蚈で 11 個のお土産を買うこずができる 入力䟋 2 4 4 3 .8#9 9.#. .#9. .... 出力䟋 2 27 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
35,841
Score : 600 points Problem Statement There are 2N people numbered 1 through 2N . The height of Person i is h_i . How many ways are there to make N pairs of people such that the following conditions are satisfied? Compute the answer modulo 998,244,353 . Each person is contained in exactly one pair. For each pair, the heights of the two people in the pair are different. Two ways are considered different if for some p and q , Person p and Person q are paired in one way and not in the other. Constraints 1 \leq N \leq 50,000 1 \leq h_i \leq 100,000 All values in input are integers. Input Input is given from Standard Input in the following format: N h_1 : h_{2N} Output Print the answer. Sample Input 1 2 1 1 2 3 Sample Output 1 2 There are two ways: Form the pair (Person 1 , Person 3 ) and the pair (Person 2 , Person 4 ). Form the pair (Person 1 , Person 4 ) and the pair (Person 2 , Person 3 ). Sample Input 2 5 30 10 20 40 20 10 10 30 50 60 Sample Output 2 516
35,842
Score: 300 points Problem Statement Mr. Infinity has a string S consisting of digits from 1 to 9 . Each time the date changes, this string changes as follows: Each occurrence of 2 in S is replaced with 22 . Similarly, each 3 becomes 333 , 4 becomes 4444 , 5 becomes 55555 , 6 becomes 666666 , 7 becomes 7777777 , 8 becomes 88888888 and 9 becomes 999999999 . 1 remains as 1 . For example, if S is 1324 , it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next. You are interested in what the string looks like after 5 \times 10^{15} days. What is the K -th character from the left in the string after 5 \times 10^{15} days? Constraints S is a string of length between 1 and 100 (inclusive). K is an integer between 1 and 10^{18} (inclusive). The length of the string after 5 \times 10^{15} days is at least K . Input Input is given from Standard Input in the following format: S K Output Print the K -th character from the left in Mr. Infinity's string after 5 \times 10^{15} days. Sample Input 1 1214 4 Sample Output 1 2 The string S changes as follows: Now: 1214 After one day: 12214444 After two days: 1222214444444444444444 After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444 The first five characters in the string after 5 \times 10^{15} days is 12222 . As K=4 , we should print the fourth character, 2 . Sample Input 2 3 157 Sample Output 2 3 The initial string is 3 . The string after 5 \times 10^{15} days consists only of 3 . Sample Input 3 299792458 9460730472580800 Sample Output 3 2
35,843
Problem D: Lowest Pyramid You are constructing a triangular pyramid with a sheet of craft paper with grid lines. Its base and sides are all of triangular shape. You draw the base triangle and the three sides connected to the base on the paper, cut along the outer six edges, fold the edges of the base, and assemble them up as a pyramid. You are given the coordinates of the base's three vertices, and are to determine the coordinates of the other three. All the vertices must have integral X- and Y-coordinate values between -100 and +100 inclusive. Your goal is to minimize the height of the pyramid satisfying these conditions. Figure 3 shows some examples. Figure 3: Some craft paper drawings and side views of the assembled pyramids Input The input consists of multiple datasets, each in the following format. X 0 Y 0 X 1 Y 1 X 2 Y 2 They are all integral numbers between -100 and +100 inclusive. ( X 0 , Y 0 ), ( X 1 , Y 1 ), ( X 2 , Y 2 ) are the coordinates of three vertices of the triangular base in counterclockwise order. The end of the input is indicated by a line containing six zeros separated by a single space. Output For each dataset, answer a single number in a separate line. If you can choose three vertices ( X a , Y a ), ( X b , Y b ) and ( X c , Y c ) whose coordinates are all integral values between -100 and +100 inclusive, and triangles ( X 0 , Y 0 )-( X 1 , Y 1 )-( X a , Y a ), ( X 1 , Y 1 )-( X 2 , Y 2 )-( X b , Y b ), ( X 2 , Y 2 )-( X 0 , Y 0 )-( X c , Y c ) and ( X 0 , Y 0 )-( X 1 , Y 1 )-( X 2 , Y 2 ) do not overlap each other (in the XY-plane), and can be assembled as a triangular pyramid of positive (non-zero) height, output the minimum height among such pyramids. Otherwise, output -1. You may assume that the height is, if positive (non-zero), not less than 0.00001. The output should not contain an error greater than 0.00001. Sample Input 0 0 1 0 0 1 0 0 5 0 2 5 -100 -100 100 -100 0 100 -72 -72 72 -72 0 72 0 0 0 0 0 0 Output for the Sample Input 2 1.49666 -1 8.52936
35,844
Score : 200 points Problem Statement AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W . If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W] , and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W] , as shown in the following figure: AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved. Constraints All input values are integers. 1≀W≀10^5 1≀a,b≀10^5 Input The input is given from Standard Input in the following format: W a b Output Print the minimum distance the second rectangle needs to be moved. Sample Input 1 3 2 6 Sample Output 1 1 This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1 . Sample Input 2 3 1 3 Sample Output 2 0 The rectangles are already connected, and thus no move is needed. Sample Input 3 5 10 1 Sample Output 3 4
35,845
w を正敎数 p を長さ2 2 w +1 の文字列ずする (w, p) - セルオヌトマトンずは次のようなものである 0 たたは 1 の状態をずるこずのできるセルが無限個䞀次元に䞊んでいる 時刻 0 にすぬけ君は奜きな有限個のマスを遞んで状態を 1 にするこずができる残りのセルは 0 である 時刻 t (> 0) のセル x の状態 f(t, x) は f(t − 1, x − w), . . . , f(t − 1, x + w) によっお以䞋のように定たる: \begin{eqnarray} f(t, x) = p[ \sum^w_{i=-w}2^{w+i} f(t − 1, x + i)] \;\;\;\;\;\;\;\;\;\;(1) \end{eqnarray} すぬけ君は時刻 0 にどのように初期状態を遞んでも 1 の個数が初期状態から倉わらないようなセルオヌトマトンが奜きである敎数 w ず文字列 s が䞎えられたずき蟞曞順で s 以䞊の文字列 p であっお (w, p) − セルオヌトマトンがすぬけ君に奜かれるような最小の p を求めよ Constraints 1 ≀ w ≀ 3 |s| = 2 2 w +1 s に珟れる文字は '0', '1' のみである Input w s Output 条件を満たす最小の p を出力せよそのようなものが存圚しないずきは " no " ず出力せよ Sample Input 1 1 00011000 Sample Output 1 00011101 Sample Input 2 1 11111111 Sample Output 2 no
35,846
Score : 200 points Problem Statement In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter. It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower. Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover. Assume also that the depth of the snow cover is always at least 1 meter. Constraints 1 \leq a < b < 499500(=1+2+3+...+999) All values in input are integers. There is no input that contradicts the assumption. Input Input is given from Standard Input in the following format: a b Output If the depth of the snow cover is x meters, print x as an integer. Sample Input 1 8 13 Sample Output 1 2 The heights of the two towers are 10 meters and 15 meters, respectively. Thus, we can see that the depth of the snow cover is 2 meters. Sample Input 2 54 65 Sample Output 2 1
35,847
Problem B: Moonlight Farm あなたは倧人気webゲヌム「ムヌンラむト牧堎」に熱䞭しおいるこのゲヌムの目的は畑で䜜物を育おそれらを売华しお収入を埗おその収入によっお牧堎を倧きくしおいくこずである あなたは速く畑を倧きくしたいず考えたそこで手始めにゲヌム䞭で育おるこずのできる䜜物を時間あたりの収入効率にもずづいお䞊べるこずにした 䜜物を育おるには皮を買わなければならないここで䜜物 i の皮の名前は L i 倀段は P i でそれぞれ䞎えられる畑に皮を怍えるず時間 A i 埌に芜が出る芜が出おから時間 B i 埌に若葉が出る若葉が出おから時間 C i 埌に葉が茂る葉が茂っおから時間 D i 埌に花が咲く花が咲いおから時間 E i 埌に実が成る䞀぀の皮から F i 個の実が成りそれらの実は䞀぀あたり S i の䟡栌で売れる䞀郚の䜜物は倚期䜜であり蚈 M i 回実を぀ける単期䜜の堎合は M i = 1で衚される倚期䜜の䜜物は M i 回目の実が成るたでは実が成ったあず葉に戻るある皮に察する収入はその皮から成った党おの実を売った金額から皮の倀段を匕いた倀であるたたその皮の収入効率はその収入を皮を怍えおから党おの実が成り終わるたでの時間で割った倀である あなたの仕事は入力ずしお䞎えられる䜜物の情報に察しおそれらを収入効率の降順に䞊べ替えお出力するプログラムを曞くこずである Input 入力はデヌタセットの列であり各デヌタセットは次のような圢匏で䞎えられる N L 1 P 1 A 1 B 1 C 1 D 1 E 1 F 1 S 1 M 1 L 2 P 2 A 2 B 2 C 2 D 2 E 2 F 2 S 2 M 2 ... L N P N A N B N C N D N E N F N S N M N 䞀行目はデヌタセットに含たれる䜜物の数 N である (1 ≀ N ≀ 50) これに続く N 行には各行に䞀぀の䜜物の情報が含たれる各倉数の意味は問題文䞭で述べた通りである䜜物の名前 L i はアルファベット小文字のみからなる20文字以内の文字列でありたた 1 ≀ P i , A i , B i , C i , D i , E i , F i , S i ≀ 100, 1 ≀ M i ≀ 5である䞀぀のケヌス内に同䞀の名前を持぀䜜物は存圚しないず仮定しお良い 入力の終りはれロを䞀぀だけ含む行で衚される Output 各デヌタセットに぀いお各行に䞀぀䜜物の名前を収入効率の降順に出力せよ収入効率が同じ䜜物に察しおはそれらの名前を蟞曞順の昇順に出力せよ 各デヌタセットの出力の埌には“#”のみからなる1行を出力するこず Sample Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output for the Sample Input eggplant apple carrot banana durian # enoki onion potato tomato # b c a #
35,848
Problem I: Beautiful Spacing Text is a sequence of words, and a word consists of characters. Your task is to put words into a grid with W columns and sufficiently many lines. For the beauty of the layout, the following conditions have to be satisfied. The words in the text must be placed keeping their original order. The following figures show correct and incorrect layout examples for a 4 word text "This is a pen" into 11 columns. Figure I.1: A good layout. Figure I.2: BAD | Do not reorder words. Between two words adjacent in the same line, you must place at least one space character. You sometimes have to put more than one space in order to meet other conditions. Figure I.3: BAD | Words must be separated by spaces. A word must occupy the same number of consecutive columns as the number of characters in it. You cannot break a single word into two or more by breaking it into lines or by inserting spaces. Figure I.4: BAD | Characters in a single word must be contiguous. The text must be justified to the both sides. That is, the first word of a line must startfrom the first column of the line, and except the last line, the last word of a line must end at the last column. Figure I.5: BAD | Lines must be justi ed to both the left and the right sides. The text is the most beautifully laid out when there is no unnecessarily long spaces. For instance, the layout in Figure I.6 has at most 2 contiguous spaces, which is more beautiful than that in Figure I.1, having 3 contiguous spaces. Given an input text and the number of columns, please find a layout such that the length of the longest contiguous spaces between words is minimum. Figure I.6: A good and the most beautiful layout. Input The input consists of multiple datasets, each in the following format. W N x 1 x 2 ... x N W , N , and x i are all integers. W is the number of columns (3 ≀ W ≀ 80,000). N is the number of words (2 ≀ N ≀ 50,000). x i is the number of characters in the i -th word (1 ≀ x i ≀ ( W −1)/2 ). Note that the upper bound on x i assures that there always exists a layout satisfying the conditions. The last dataset is followed by a line containing two zeros. Output For each dataset, print the smallest possible number of the longest contiguous spaces between words. Sample Input 11 4 4 2 1 3 5 7 1 1 1 2 2 1 2 11 7 3 1 3 1 3 3 4 100 3 30 30 39 30 3 2 5 3 0 0 Output for the Sample Input 2 1 2 40 1
35,849
Problem J: Tree Construction Consider a two-dimensional space with a set of points ( x i , y i ) that satisfy x i < x j and y i > y j for all i < j . We want to have them all connected by a directed tree whose edges go toward either right ( x positive) or upward ( y positive). The figure below shows an example tree. Figure 1: An example tree Write a program that finds a tree connecting all given points with the shortest total length of edges. Input The input begins with a line that contains an integer n (1 <= n <= 1000), the number of points. Then n lines follow. The i -th line contains two integers x i and y i (0 <= x i , y i <= 10000), which give the coordinates of the i -th point. Output Print the total length of edges in a line. Sample Input 1 5 1 5 2 4 3 3 4 2 5 1 Output for the Sample Input 1 12 Sample Input 2 1 10000 0 Output for the Sample Input 2 0
35,850
Problem A: Pi is Three π (spelled pi in English) is a mathematical constant representing the circumference of a circle whose di- ameter is one unit length. The name π is said to come from the first letter of the Greek words περιφέρεια (meaning periphery) and περίΌετρος (perimeter). Recently, the government of some country decided to allow use of 3, rather than 3.14, as the approximate value of π in school (although the decision was eventually withdrawn probably due to the blame of many people). This decision is very surprising, since this approximation is far less accurate than those obtained before the common era. Ancient mathematicians tried to approximate the value of π without calculators. A typical method was to calculate the perimeter of inscribed and circumscribed regular polygons of the circle. For example, Archimedes (287–212 B.C.) proved that 223/71 < π < 22/7 using 96-sided polygons, where 223/71 and 22/7 were both accurate to two fractional digits (3.14). The resultant approximation would be more accurate as the number of vertices of the regular polygons increased. As you see in the previous paragraph, π was approximated by fractions rather than decimal numbers in the older ages. In this problem, you are requested to represent π as a fraction with the smallest possible denominator such that the representing value is not different by more than the given allowed error. If more than one fraction meets this criterion, the fraction giving better approximation is preferred. Input The input consists of multiple datasets. Each dataset has a real number R (0 < R ≀ 1) representing the allowed difference between the fraction and π . The value may have up to seven digits after the decimal point. The input is terminated by a line containing 0.0, which must not be processed. Output For each dataset, output the fraction which meets the criteria in a line. The numerator and denominator of the fraction should be separated by a slash as shown in the sample output, and those numbers must be integers. Sample Input 0.15 0.05 0.0 Output for the Sample Input 3/1 19/6
35,851
Score : 100 points Problem Statement The window of Takahashi's room has a width of A . There are two curtains hung over the window, each of which has a horizontal length of B . (Vertically, the curtains are long enough to cover the whole window.) We will close the window so as to minimize the total horizontal length of the uncovered part of the window. Find the total horizontal length of the uncovered parts of the window then. Constraints 1 \leq A \leq 100 1 \leq B \leq 100 A and B are integers. Input Input is given from Standard Input in the following format: A B Output Print the total horizontal length of the uncovered parts of the window. Sample Input 1 12 4 Sample Output 1 4 We have a window with a horizontal length of 12 , and two curtains, each of length 4 , that cover both ends of the window, for example. The uncovered part has a horizontal length of 4 . Sample Input 2 20 15 Sample Output 2 0 If the window is completely covered, print 0 . Sample Input 3 20 30 Sample Output 3 0 Each curtain may be longer than the window.
35,852
Score : 2000 points Problem Statement You are given a permutation P_1 ... P_N of the set { 1 , 2 , ..., N }. You can apply the following operation to this permutation, any number of times (possibly zero): Choose two indices i,j (1 ≩ i < j ≩ N) , such that j - i ≧ K and |P_i - P_j| = 1 . Then, swap the values of P_i and P_j . Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one. Constraints 2≩N≩500,000 1≩K≩N-1 P is a permutation of the set { 1 , 2 , ..., N }. Input The input is given from Standard Input in the following format: N K P_1 P_2 ... P_N Output Print the lexicographically smallest permutation that can be obtained. Sample Input 1 4 2 4 2 3 1 Sample Output 1 2 1 4 3 One possible way to obtain the lexicographically smallest permutation is shown below: 4 2 3 1 4 1 3 2 3 1 4 2 2 1 4 3 Sample Input 2 5 1 5 4 3 2 1 Sample Output 2 1 2 3 4 5 Sample Input 3 8 3 4 5 7 8 3 1 2 6 Sample Output 3 1 2 6 7 5 3 4 8
35,853
Score : 300 points Problem Statement Snuke loves puzzles. Today, he is working on a puzzle using S - and c -shaped pieces. In this puzzle, you can combine two c -shaped pieces into one S -shaped piece, as shown in the figure below: Snuke decided to create as many Scc groups as possible by putting together one S -shaped piece and two c -shaped pieces. Find the maximum number of Scc groups that can be created when Snuke has N S -shaped pieces and M c -shaped pieces. Constraints 1 ≀ N,M ≀ 10^{12} Input The input is given from Standard Input in the following format: N M Output Print the answer. Sample Input 1 1 6 Sample Output 1 2 Two Scc groups can be created as follows: Combine two c -shaped pieces into one S -shaped piece Create two Scc groups, each from one S -shaped piece and two c -shaped pieces Sample Input 2 12345 678901 Sample Output 2 175897
35,854
Drawing Lots Let's play Amidakuji. In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines. In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom. Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right. Input w n a 1 , b 1 a 2 , b 2 . . a n , b n w ( w ≀ 30) is the number of vertical lines. n ( n ≀ 30) is the number of horizontal lines. A pair of two integers a i and b i delimited by a comma represents the i -th horizontal line. Output The number which should be under the 1st (leftmost) vertical line The number which should be under the 2nd vertical line : The number which should be under the w -th vertical line Sample Input 5 4 2,4 3,5 1,2 3,4 Output for the Sample Input 4 1 2 5 3
35,855
最叀の遺跡 問題 昔, そこには集萜があり, 倚くの人が暮らしおいた. 人々は圢も倧きさも様々な建物を建おた. だが, それらの建造物は既に倱われ, 文献ず, 遺跡から芋぀かった柱だけが建造物の䜍眮を知る手がかりだった. 文献には神殿の蚘述がある. 神殿は䞊から芋るず正確に正方圢になっおおり, その四隅には柱があった. 神殿がどの向きを向いおいたかはわからない. たた, 蟺䞊や内郚に柱があったかどうかもわからない. 考叀孊者たちは, 遺跡から芋぀かった柱の䞭で, 正方圢になっおいるもののうち, 面積が最倧のものが神殿に違いないず考えた. 柱の䜍眮の座暙が䞎えられるので, 4 本の柱でできる正方圢のうち面積が最倧のものを探し, その面積を出力するプログラムを曞け. なお, 正方圢の蟺は座暙軞に平行ずは限らないこずに泚意せよ. 䟋 䞋の図の䟋では, 10 本の柱があり, 座暙 (4, 2), (5, 2), (5, 3), (4, 3) にある 4 本ず座暙 (1, 1), (4, 0), (5, 3), (2, 4) にある 4 本が正方圢をなしおいる. 面積が最倧の正方圢は埌者で, その面積は 10 である. 入力 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる入力はれロ぀を含む行で終了する 1 行目には, 遺跡から芋぀かった柱の本数 n が曞かれおいる. 2 行目から n + 1 行目たでの n 行の各々には, 柱の x 座暙ず y 座暙が空癜区切りで曞かれおいる. 1 本の柱が 2 床以䞊珟れるこずはない. n は 1 ≀ n ≀ 3000 を満たす敎数であり, 柱の x 座暙ず y 座暙は 0 以䞊 5000 以䞋の敎数である. 採点甚デヌタのうち, 配点の 30% 分は 1 ≀ n ≀ 100 を満たし, 配点の 60% 分は1 ≀ n ≀ 500 を満たす. デヌタセットの数は 10 を超えない 出力 デヌタセットごずに 1 個の敎数を出力する. 4 本の柱からなる正方圢が存圚する堎合は, そのような正方圢のうち面積が最倧のものの面積を出力し, そのような正方圢が存圚しない堎合は 0 を出力せよ. 入出力䟋 入力䟋 10 9 4 4 3 1 1 4 2 2 4 5 8 4 0 5 3 0 5 5 2 10 9 4 4 3 1 1 4 2 2 4 5 8 4 0 5 3 0 5 5 2 0 出力䟋 10 10 䞊蚘問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
35,856
E: 総和の切り取り 問題 えびちゃんは数列 (a_1, a_2, ..., a_n) を持っおいたす。 えびちゃんは空でもよい郚分配列の総和の最倧倀が気になるので、それを求めおください。 ここで、郚分配列ずは連続する郚分列を指したす。なお、空列の総和は 0 ずしたす。 さらに、えびちゃんがこの数列を q 回曞き換えるので、各曞き換えの盎埌にこの倀を求めおください。 入力圢匏 n q a_1 a_2 ... a_n k_1 x_1 ... k_q x_q 各 k_j , x_j ( 1 \leq j \leq q ) は、 a_{k_j} を x_j に曞き換えるこずを意味したす。 各曞き換えは独立ではなく、その埌の凊理においお配列は曞き換えられたたたであるこずに泚意しおください。 制玄 1\leq n\leq 10^5 1\leq q\leq 10^5 1\leq k_j\leq n |a_i|, |x_j| \leq 10^9 出力圢匏 q+1 行出力しおください。 1 行目には曞き換えを行う前の、 1+i 行目には i 回目の曞き換えの盎埌の郚分配列の総和の最倧倀を出力しおください。 入力䟋1 5 2 1 2 -3 4 -5 3 3 2 -6 出力䟋1 4 10 7 郚分配列 (a_l, 
, a_r) を a[l, r] ず衚すこずにするず、曞き換え前は a[1, 4] および a[4, 4] の総和が 4 で、これが最倧です。 1 回目の曞き換えの埌、数列は (1, 2, 3, 4, -5) ずなり、総和の最倧倀は a[1, 4] の 10 です。 2 回目の曞き換えの埌、数列は (1, -6, 3, 4, -5) ずなり、総和の最倧倀は a[3, 4] の 7 です。 入力䟋2 3 1 -1 -2 -3 1 1 出力䟋2 0 1 空列の総和は 0 であり、曞き換え前はそれが最倧です。
35,857
Get a Rectangular Field Karnaugh is a poor farmer who has a very small field. He wants to reclaim wasteland in the kingdom to get a new field. But the king who loves regular shape made a rule that a settler can only get a rectangular land as his field. Thus, Karnaugh should get the largest rectangular land suitable for reclamation. The map of the wasteland is represented with a 5 x 5 grid as shown in the following figures, where '1' represents a place suitable for reclamation and '0' represents a sandy place. Your task is to find the largest rectangle consisting only of 1's in the map, and to report the size of the rectangle. The size of a rectangle is defined by the number of 1's in it. Note that there may be two or more largest rectangles of the same size. Figure 1. The size of the largest rectangles is 4. There are two largest rectangles (shaded). Figure 2. The size of the largest rectangle is 3. There is one largest rectangle (shaded). Input The input consists of maps preceded by an integer m indicating the number of input maps. m map 1 map 2 map 3 ... map m Two maps are separated by an empty line. Each map k is in the following format: p p p p p p p p p p p p p p p p p p p p p p p p p Each p is a character either '1' or '0'. Two p 's in the same line are separated by a space character. Here, the character '1' shows a place suitable for reclamation and '0' shows a sandy place. Each map contains at least one '1'. Output The size of the largest rectangle(s) for each input map should be shown each in a separate line. Sample Input 3 1 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 0 0 0 1 Output for the Sample Input 4 3 8
35,858
カゞノ あなたの勀めおいる䌚瀟では新たなカゞノゲヌムの開発をしおいる今日は最近提案されたゲヌムに぀いお考察しおみるこずにした このゲヌムでは N 個のサむコロを同時に振っお出た目の合蚈が埗点ずなるプレむダヌは埗点を倧きくするこずを目暙ずしおプレヌするもし出た目が気に入らなければサむコロを振り盎すこずができるがその時は N 個のサむコロ党おを同時に振り盎さなければならないたたサむコロを振るこずのできる回数は最倧で M 回である十分に倧きい目が出たず思ったのであれば M 回より少ない回数でゲヌムを終えおも良く最埌に振ったサむコロの目の合蚈が埗点ずなる 適切な賭け金を蚭定するためには埗点の期埅倀を求めなければならない N ず M が䞎えられた時最適な戊略をずった堎合に埗られる埗点の期埅倀を求めるのが今日のあなたの仕事である ただしこのゲヌムで甚いるサむコロには 1 から 6 たでの目がありそれぞれの目が出る確率は同じである Input 入力は最倧で 100 個のデヌタセットからなる各デヌタセットは次の圢匏で衚される N M 敎数 N  M は 1 ≀ N ≀ 20  1 ≀ M ≀ 10 10 を満たす 入力の終わりは 2 ぀のれロからなる行で衚される Output 各デヌタセットに぀いお最適な戊略をずった時の期埅倀を䞀行に出力せよ出力には 10 -2 を超える絶察誀差があっおはならないこの問題は蚈算誀差が倧きくなる解法が想定されるため粟床のよい型を甚いるこずが掚奚される Sample Input 1 2 2 1 2 2 0 0 Output for the Sample Input 4.25 7 7.9722222222
35,859
RMQ and RAQ Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations: $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$. $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$. Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0. Input $n$ $q$ $query_1$ $query_2$ : $query_q$ In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$th query $query_i$ is given in the following format: 0 $s$ $t$ $x$ or 1 $s$ $t$ The first digit represents the type of the query. '0' denotes $add(s, t, x)$ and '1' denotes $find(s, t)$. Output For each $find$ query, print the minimum value. Constraints $1 ≀ n ≀ 100000$ $1 ≀ q ≀ 100000$ $0 ≀ s ≀ t < n$ $-1000 ≀ x ≀ 1000$ Sample Input 1 6 7 0 1 3 1 0 2 4 -2 1 0 5 1 0 1 0 3 5 3 1 3 4 1 0 5 Sample Output 1 -2 0 1 -1
35,860
Score : 400 points Problem Statement Given is a string S consisting of digits from 1 through 9 . Find the number of pairs of integers (i,j) ( 1 ≀ i ≀ j ≀ |S| ) that satisfy the following condition: Condition: In base ten, the i -th through j -th characters of S form an integer that is a multiple of 2019 . Constraints 1 ≀ |S| ≀ 200000 S is a string consisting of digits from 1 through 9 . Input Input is given from Standard Input in the following format: S Output Print the number of pairs of integers (i,j) ( 1 ≀ i ≀ j ≀ |S| ) that satisfy the condition. Sample Input 1 1817181712114 Sample Output 1 3 Three pairs - (1,5) , (5,9) , and (9,13) - satisfy the condition. Sample Input 2 14282668646 Sample Output 2 2 Sample Input 3 2119 Sample Output 3 0 No pairs satisfy the condition.
35,861
Score : 1000 points Problem Statement There are N integers written on a blackboard. The i -th integer is A_i , and the greatest common divisor of these integers is 1 . Takahashi and Aoki will play a game using these integers. In this game, starting from Takahashi the two player alternately perform the following operation: Select one integer on the blackboard that is not less than 2 , and subtract 1 from the integer. Then, divide all the integers on the black board by g , where g is the greatest common divisor of the integers written on the blackboard. The player who is left with only 1 s on the blackboard and thus cannot perform the operation, loses the game. Assuming that both players play optimally, determine the winner of the game. Constraints 1 ≩ N ≩ 10^5 1 ≩ A_i ≩ 10^9 The greatest common divisor of the integers from A_1 through A_N is 1 . Input The input is given from Standard Input in the following format: N A_1 A_2 
 A_N Output If Takahashi will win, print First . If Aoki will win, print Second . Sample Input 1 3 3 6 7 Sample Output 1 First Takahashi, the first player, can win as follows: Takahashi subtracts 1 from 7 . Then, the integers become: (1,2,2) . Aoki subtracts 1 from 2 . Then, the integers become: (1,1,2) . Takahashi subtracts 1 from 2 . Then, the integers become: (1,1,1) . Sample Input 2 4 1 2 4 8 Sample Output 2 First Sample Input 3 5 7 8 8 8 8 Sample Output 3 Second
35,862
Problem M: Dial Problem ダむダル匏の南京錠がある。この南京錠には、5぀のダむダルず、決定ボタンが甚意されおいる。 5぀あるダむダルを回転させお16進数で5ケタの敎数を䜜り、決定ボタンを抌しお入力するず、入力した倀ずパスワヌドが䞀臎しおいれば開く仕組みになっおいる。5぀のダむダルそれぞれには 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,0,1,2, ... の順で文字が珟れるように曞かれおいる。 持ち䞻はパスワヌドを忘れおしたった。しかし、パスワヌドの5ケタのうち、1぀のケタだけが偶数で残り4぀は奇数であったこずは芚えおいる。 ただし、偶数ずは0,2,4,6,8,a,c,eであり、奇数ずは1,3,5,7,9,b,d,fである。 たたこの鍵は䞍良品で、以䞋の条件でパスワヌドず異なる数字を入力しおも開いおしたうこずが分かっおいる。本来、入力した敎数ずパスワヌドが5぀のケタすべおに぀いお䞀臎しおいなければ鍵は開かない。しかし、パスワヌドの偶数ずなっおいるケタが i ケタ目だった堎合、 i ケタ目の䞀臎刀定を行うずき、その偶数の前埌にある奇数が入力されおいた堎合でも i ケタ目は䞀臎しおいるず誀刀定されおしたうのだ。 䟋えば、パスワヌドが"57677"の南京錠ならば、'6'の前埌には'5'ず'7'の奇数があるため"57677"のほかに、"57577"や"57777"を入力したずきでも開いおしたう。 同様に、パスワヌドが"130bd"の南京錠ならば、'0'の前埌には'1'ず'f'の奇数があるため"130bd"のほかに、"13fbd"や"131bd"を入力したずきでも開いおしたう。 今、パスワヌドの候補が N 個あり、それらのうちどれか1぀が正解のパスワヌドであるこずが分かっおいる。しかたがないので持ち䞻は、鍵が開くたで䜕床も敎数を入力しお詊し続けるこずにした。持ち䞻はできるだけ決定ボタンを抌す回数を少なくしたい。 持ち䞻が最適な戊略をずったずき、最倧で䜕回決定ボタンを抌さなければならないだろうか? その回数を出力せよ。 たた、実際に最倧ずなるずきに入力する敎数の集合を昇順に出力せよ。 答えが䞀意に定たらない堎合は、蟞曞順で最小ずなるものを出力せよ。 Input 入力は以䞋の圢匏で䞎えられる。 N password 1 password 2 ... password N 1行目に N が䞎えられる。 2行目から N +1行目の i 行目には、パスワヌドの候補を衚す5ケタの16進数を衚す文字列 password i が䞎えられる。 Constraints 1 ≀ N ≀ 6000 password i ≠ password j ( i < j ) 文字列は、0から9の数字たたは英小文字aからfの5文字で構成され、そのうち1文字は偶数であり、他の4文字は奇数である Output 鍵が開くたでに最適な戊略をずったずきの決定ボタンを抌す回数の最倧倀を1行に出力せよ。 続いお、最倧ずなるずきに入力する敎数の集合を昇順に出力せよ。 もし、答えが䞀意に定たらない堎合は、蟞曞順で最小ずなるものを出力せよ。 Sample Input 1 1 0111f Sample Output 1 1 0111f Sample Input 2 3 57567 57587 0d351 Sample Output 2 2 0d351 57577 Sample Input 3 6 1811b 1a11b f3b1e f3b1c b0df3 bedf3 Sample Output 3 3 1911b bfdf3 f3b1d
35,863
Score : 100 points Problem Statement We call a 4 -digit integer with three or more consecutive same digits, such as 1118 , good . You are given a 4 -digit integer N . Answer the question: Is N good ? Constraints 1000 ≀ N ≀ 9999 N is an integer. Input Input is given from Standard Input in the following format: N Output If N is good , print Yes ; otherwise, print No . Sample Input 1 1118 Sample Output 1 Yes N is good , since it contains three consecutive 1 . Sample Input 2 7777 Sample Output 2 Yes An integer is also good when all the digits are the same. Sample Input 3 1234 Sample Output 3 No
35,864
Score : 1000 points Problem Statement Snuke participated in a magic show. A magician prepared N identical-looking boxes. He put a treasure in one of the boxes, closed the boxes, shuffled them, and numbered them 1 through N . Since the boxes are shuffled, now Snuke has no idea which box contains the treasure. Snuke wins the game if he opens a box containing the treasure. You may think that if Snuke opens all boxes at once, he can always win the game. However, there are some tricks: Snuke must open the boxes one by one. After he opens a box and checks the content of the box, he must close the box before opening the next box. He is only allowed to open Box i at most a_i times. The magician may secretly move the treasure from a closed box to another closed box, using some magic trick. For simplicity, assume that the magician never moves the treasure while Snuke is opening some box. However, he can move it at any other time (before Snuke opens the first box, or between he closes some box and opens the next box). The magician can perform the magic trick at most K times. Can Snuke always win the game, regardless of the initial position of the treasure and the movements of the magician? Constraints 2 \leq N \leq 50 1 \leq K \leq 50 1 \leq a_i \leq 100 Input Input is given from Standard Input in the following format: N K a_1 a_2 \cdots a_N Output If the answer is no, print a single -1 . Otherwise, print one possible move of Snuke in the following format: Q x_1 x_2 \cdots x_Q It means that he opens boxes x_1, x_2, \cdots, x_Q in this order. In case there are multiple possible solutions, you can output any. Sample Input 1 2 1 5 5 Sample Output 1 7 1 1 2 1 2 2 1 If Snuke opens the boxes 7 times in the order 1 \rightarrow 1 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 2 \rightarrow 1 , he can always find the treasure regardless of its initial position and the movements of the magician. Sample Input 2 3 50 5 10 15 Sample Output 2 -1
35,865
Score : 1100 points Problem Statement There are 2^N players, numbered 1, 2, ..., 2^N . They decided to hold a tournament. The tournament proceeds as follows: Choose a permutation of 1, 2, ..., 2^N : p_1, p_2, ..., p_{2^N} . The players stand in a row in the order of Player p_1 , Player p_2 , ... , Player p_{2^N} . Repeat the following until there is only one player remaining in the row: Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players. The last player who remains in the row is the champion. It is known that, the result of the match between two players can be written as follows, using M integers A_1, A_2, ..., A_M given as input: When y = A_i for some i , the winner of the match between Player 1 and Player y ( 2 \leq y \leq 2^N ) will be Player y . When y \neq A_i for every i , the winner of the match between Player 1 and Player y ( 2 \leq y \leq 2^N ) will be Player 1 . When 2 \leq x < y \leq 2^N , the winner of the match between Player x and Player y will be Player x . The champion of this tournament depends only on the permutation p_1, p_2, ..., p_{2^N} chosen at the beginning. Find the number of permutation p_1, p_2, ..., p_{2^N} chosen at the beginning of the tournament that would result in Player 1 becoming the champion, modulo 10^9 + 7 . Constraints 1 \leq N \leq 16 0 \leq M \leq 16 2 \leq A_i \leq 2^N ( 1 \leq i \leq M ) A_i < A_{i + 1} ( 1 \leq i < M ) Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M Output Print the answer. Sample Input 1 2 1 3 Sample Output 1 8 Examples of p that satisfy the condition are: [1, 4, 2, 3] and [3, 2, 1, 4] . Examples of p that do not satisfy the condition are: [1, 2, 3, 4] and [1, 3, 2, 4] . Sample Input 2 4 3 2 4 6 Sample Output 2 0 Sample Input 3 3 0 Sample Output 3 40320 Sample Input 4 3 3 3 4 7 Sample Output 4 2688 Sample Input 5 16 16 5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003 Sample Output 5 816646464
35,866
Score : 1000 points Problem Statement Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: If all the squares are black or all the squares are white, the complexity is 0 . Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1 . You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is # if the square at the i -th row from the top and the j -th column from the left is black, and A_{ij} is . if that square is white. Find the complexity of the given grid. Constraints 1 \leq H,W \leq 185 A_{ij} is # or . . Input Input is given from Standard Input in the following format: H W A_{11} A_{12} ... A_{1W} : A_{H1} A_{H2} ... A_{HW} Output Print the complexity of the given grid. Sample Input 1 3 3 ... .## .## Sample Output 1 2 Let us divide the grid by the boundary line between the first and second columns. The subgrid consisting of the first column has the complexity of 0 , and the subgrid consisting of the second and third columns has the complexity of 1 , so the whole grid has the complexity of at most 2 . Sample Input 2 6 7 .####.# #....#. #....#. #....#. .####.# #....## Sample Output 2 4
35,867
Problem A: Approximate Circle Consider a set of n points ( x 1 , y 1 ), ..., ( x n , y n ) on a Cartesian space. Your task is to write a program for regression to a circle x 2 + y 2 + a x + b y + c = 0. In other words, your program should find a circle that minimizes the error. Here the error is measured by the sum over square distances between each point and the circle, which is given by: Input The input begins with a line containing one integer n (3 <= n <= 40,000). Then n lines follow. The i -th line contains two integers x i and y i (0 <= x i , y i <= 1,000), which denote the coordinates of the i -th point. You can assume there are no cases in which all the points lie on a straight line. Output Print three integers a , b and c , separated by space, to show the regressed function. The output values should be in a decimal fraction and should not contain an error greater than 0.001. Sample Input 1 4 0 0 100 0 100 100 0 100 Output for the Sample Input 1 -100.000 -100.000 0.000 Sample Input 2 3 0 0 10 0 5 100 Output for the Sample Input 2 -10.000 -99.750 0.000
35,868
F: ボタンの朚 問題文 $N$ 頂点 $N-1$ 蟺からなる朚があり、$i$ 番目の蟺は $u_i$ 番目の頂点ず $v_i$ 番目の頂点を接続しおいたす。 各頂点にはボタンが咲いおおり、$i$ 番目の頂点に咲いおいるボタンをボタン $i$ ず呌ぶこずにしたす。 はじめ、ボタン $i$ の矎しさは $a_i$ です。 ボタン $i$ を抌すたびに、ボタン $i$ の矎しさを隣接するボタンに $1$ ず぀分け䞎えたす。 すなわち、$i$ 番目の頂点に $c_1, ..., c_k$ 番目の頂点が隣接しおいる堎合、ボタン $i$ の矎しさが $k$ 枛少し、ボタン $c_1, ..., c_k$ の矎しさがそれぞれ $1$ ず぀増加したす。 このずき、負の矎しさのボタンを抌しおも良いし、ボタンを抌した結果あるボタンの矎しさが負になっおも良いです。 あなたの目的はボタン $1, 2, ..., N$ の矎しさをそれぞれ $b_1, ..., b_N$ にするこずです。 最小で合蚈䜕回ボタンを抌せば目的を達成できるでしょうか。 制玄 入力はすべお敎数である $1 \leq N \leq 10^5$ $1 \leq u_i, v_i \leq N$ $-1000 \leq a_i, b_i \leq 1000$ $\sum_i a_i = \sum_i b_i$ 䞎えられるグラフは朚である 䞎えられる入力においお目的は必ず達成できる 入力 入力は以䞋の圢匏で暙準入力から䞎えられる。 $N$ $u_1$ $v_1$ $\vdots$ $u_{N-1}$ $v_{N-1}$ $a_1$ $a_2$ $...$ $a_N$ $b_1$ $b_2$ $...$ $b_N$ 出力 目的を達成するためにボタンを抌す合蚈回数の最小倀を出力せよ。 入力䟋1 4 1 2 1 3 3 4 0 3 2 0 -3 4 5 -1 出力䟋1 4 次のように合蚈 $4$ 回ボタンを抌すこずで目的を達成でき、このずきが最小です。 ボタン $1$ を $2$ 回抌したす。ボタン $1, 2, 3, 4$ の矎しさがそれぞれ $-4, 5, 4, 0$ に倉化したす。 ボタン $2$ を $1$ 回抌したす。矎しさがそれぞれ $-3, 4, 4, 0$ に倉化したす。 ボタン $4$ を $1$ 回抌したす。矎しさがそれぞれ $-3, 4, 5, -1$ に倉化したす。 入力䟋2 5 1 2 1 3 3 4 3 5 -9 5 7 1 8 -7 4 5 1 9 出力䟋2 3
35,869
Score : 500 points Problem Statement We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i . Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x , the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5 . Initially, the intensity of Bulb i is A_i . We will now do the following operation K times in a row: For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i . Then, change the intensity of each bulb i to B_i . Find the intensity of each bulb after the K operations. Constraints 1 \leq N \leq 2 \times 10^5 1 \leq K \leq 2 \times 10^5 0 \leq A_i \leq N Input Input is given from Standard Input in the following format: N K A_1 A_2 \ldots A_N Output Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format: A{'}_1 A{'}_2 \ldots A{'}_N Sample Input 1 5 1 1 0 0 1 0 Sample Output 1 1 2 2 1 2 Initially, only Bulb 1 illuminates coordinate 1 , so the intensity of Bulb 1 becomes 1 after the operation. Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2 , so the intensity of Bulb 2 becomes 2 . Sample Input 2 5 2 1 0 0 1 0 Sample Output 2 3 3 4 4 3
35,870
B 階局的蚈算機 (Hierarchical Calculator) Problem Ebi-chan has N formulae: y = a_i x for i =1, ..., N (inclusive). Now she considers a subsequence of indices with length k : s_1 , s_2 , ... , s_k . At first, let x_0 be 1 and evaluate s_1 -th formulae with x = x_0 . Next, let x_1 be the output of s_1 and evaluate s_2 -th formulae with x = x_1 , and so on. She wants to maximize the final output of the procedure, x_{s_k} . If there are many candidates, she wants the """shortest one""". If there are still many candidates, she wants the """lexicographically smallest one""". Sequence s is lexicographically smaller than sequence t , if and only if either of the following conditions hold: there exists m < |s| such that s_i = t_i for i in 1 to m (inclusive) and s_{m+1} < t_{m+1} , or s_i = t_i for i in 1 to |s| (inclusive) and |s| < |t| , where |s| is the length of the s . Input N a_1 a_2 $\cdots$ a_N Constraints 1 \leq N \leq 60 -2 \leq a_i \leq 2 for i=1, ...,N (inclusive) Every input is given as the integer. Output Output k+1 lines. First line, the length of the sequence, k . Following k lines, the index of the i -th element of the subsequence, s_i (one element per line). Sample Input 1 4 2 0 -2 1 Sample Output for Input 1 1 1 She evaluates the first one and gets the maximum value 2 . Sample Input 2 3 2 -2 -2 Sample Output for Input 2 3 1 2 3 She evaluates all of them and gets the maximum value 8 . Sample Input 3 2 -1 0 Sample Output for Input 3 0 She evaluates none of them and gets the maximum value 0 . Empty sequence is the shorter and lexicographically smaller than any other sequences. Sample Input 4 5 -1 2 1 -2 -1 Sample Output for Input 4 3 1 2 4 She evaluates $\langle$ 1, 2, 4 $\rangle$ ones and gets the maximum value 4 . Note that $\langle$ 2, 4, 5 $\rangle$ is not lexicographically smallest one.
35,871
Score : 1500 points Problem Statement We have a grid with 3 rows and N columns. The cell at the i -th row and j -th column is denoted ( i , j ). Initially, each cell ( i , j ) contains the integer i+3j-3 . A grid with N=5 columns Snuke can perform the following operation any number of times: Choose a 3×3 subrectangle of the grid. The placement of integers within the subrectangle is now rotated by 180° . An example sequence of operations (each chosen subrectangle is colored blue) Snuke's objective is to manipulate the grid so that each cell ( i , j ) contains the integer a_{i,j} . Determine whether it is achievable. Constraints 5≀N≀10^5 1≀a_{i,j}≀3N All a_{i,j} are distinct. Input The input is given from Standard Input in the following format: N a_{1,1} a_{1,2} ... a_{1,N} a_{2,1} a_{2,2} ... a_{2,N} a_{3,1} a_{3,2} ... a_{3,N} Output If Snuke's objective is achievable, print Yes . Otherwise, print No . Sample Input 1 5 9 6 15 12 1 8 5 14 11 2 7 4 13 10 3 Sample Output 1 Yes This case corresponds to the figure in the problem statement. Sample Input 2 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Sample Output 2 No Sample Input 3 5 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15 Sample Output 3 Yes The objective is already achieved with the initial placement of the integers. Sample Input 4 6 15 10 3 4 9 16 14 11 2 5 8 17 13 12 1 6 7 18 Sample Output 4 Yes Sample Input 5 7 21 12 1 16 13 6 7 20 11 2 17 14 5 8 19 10 3 18 15 4 9 Sample Output 5 No
35,872
Bozosort Bozosort, as well as Bogosort, is a very inefficient sort algorithm. It is a random number-based algorithm that sorts sequence elements following the steps as below: Randomly select two elements and swap them. Verify if all the elements are sorted in increasing order. Finish if sorted, else return to 1. To analyze Bozosort, you have decided to simulate the process using several predetermined pairs of elements. You are given several commands to swap two elements. Make a program to evaluate how many times you have to run the command before the sequence is aligned in increasing order. Input The input is given in the following format. $N$ $a_1$ $a_2$ ... $a_N$ $Q$ $x_1$ $y_1$ $x_2$ $y_2$ $...$ $x_Q$ $y_Q$ The first line provides the number of sequence elements $N$ ($2 \leq N \leq 300,000$). The second line provides an array of integers $a_i$ ($1 \leq a_i \leq 10^9$) that constitutes the sequence. Each of the subsequent $Q$ lines provides a pair of integers $x_i,y_i$ ($1 \leq x_i,y_i \leq N$) that represent the $i$-th command, which swaps the two elements indicated by $x_i$ and $y_i$ ($x_i \ne y_i$). Output If neat alignment in increasing order is realized the first time after execution of multiple commands, output at what time it was. Output 0 if the initial sequence is aligned in increasing order, and -1 if exhaustive execution still failed to attain the goal. Sample Input 1 6 9 7 5 6 3 1 3 1 6 2 5 3 4 Sample Output 1 2 Sample Input 2 4 4 3 2 1 2 1 2 3 4 Sample Output 2 -1 Sample Input 3 5 1 1 1 2 2 1 1 2 Sample Input 3 0
35,873
Problem D: Dungeon Wall In 2337, people are bored at daily life and have crazy desire of having extraordinary experience. These days,“Dungeon Adventure” is one of the hottest attractions, where brave adventurers risk their lives to kill the evil monsters and save the world. You are a manager of one of such dungeons. Recently you have been receiving a lot of complaints from soldiers who frequently enter your dungeon; they say your dungeon is too easy and they do not want to enter again. You are considering making your dungeon more difficult by increasing the distance between the entrance and the exit of your dungeon so that more monsters can approach the adventurers. The shape of your dungeon is a rectangle whose width is W and whose height is H . The dungeon is a grid which consists of W × H square rooms of identical size 1 × 1. The southwest corner of the dungeon has the coordinate (0; 0), and the northeast corner has ( W , H ). The outside of the dungeon is surrounded by walls, and there may be some more walls inside the dungeon in order to prevent adventurers from going directly to the exit. Each wall in the dungeon is parallel to either x -axis or y -axis, and both ends of each wall are at integer coordinates. An adventurer can move from one room to another room if they are adjacent vertically or horizontally and have no wall between. You would like to add some walls to make the shortest path between the entrance and the exit longer. However, severe financial situation only allows you to build at most only one wall of a unit length. Note that a new wall must also follow the constraints stated above. Furthermore, you need to guarantee that there is at least one path from the entrance to the exit. You are wondering where you should put a new wall to maximize the minimum number of steps between the entrance and the exit. Can you figure it out? Input W H N sx 0 sy 0 dx 0 dy 0 sx 1 sy 1 dx 1 dy 1 . . . ix iy ox oy The first line contains three integers: W , H and N (1 ≀ W , H ≀ 50, 0 ≀ N ≀ 1000). They are separated with a space. The next N lines contain the specifications of N walls inside the dungeon. Each wall specification is a line containing four integers. The i -th specification contains sx i , sy i , dx i and dy i , separated with a space. These integers give the position of the i -th wall: it spans from ( sx i , sy i ) to ( dx i , dy i ). The last two lines contain information about the locations of the entrance and the exit. The first line contains two integers ix and iy , and the second line contains two integers ox and oy . The entrance is located at the room whose south-west corner is ( ix , iy ), and the exit is located at the room whose southwest corner is ( ox , oy ). Output Print the maximum possible increase in the minimum number of required steps between the entrance and the exit just by adding one wall. If there is no good place to build a new wall, print zero. Sample Input 1 3 4 4 1 0 1 1 1 3 1 4 1 2 2 2 2 1 2 3 0 0 1 0 Output for the Sample Input 1 6 Sample Input 2 50 2 0 0 0 49 0 Output for the Sample Input 2 2 Sample Input 3 50 2 0 0 0 49 1 Output for the Sample Input 3 0
35,874
Score: 500 points Problem Statement Does there exist an undirected graph with N vertices satisfying the following conditions? The graph is simple and connected. The vertices are numbered 1, 2, ..., N . Let M be the number of edges in the graph. The edges are numbered 1, 2, ..., M , the length of each edge is 1 , and Edge i connects Vertex u_i and Vertex v_i . There are exactly K pairs of vertices (i,\ j)\ (i < j) such that the shortest distance between them is 2 . If there exists such a graph, construct an example. Constraints All values in input are integers. 2 \leq N \leq 100 0 \leq K \leq \frac{N(N - 1)}{2} Input Input is given from Standard Input in the following format: N K Output If there does not exist an undirected graph with N vertices satisfying the conditions, print -1 . If there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for): M u_1 v_1 : u_M v_M If there exist multiple graphs satisfying the conditions, any of them will be accepted. Sample Input 1 5 3 Sample Output 1 5 4 3 1 2 3 1 4 5 2 3 This graph has three pairs of vertices such that the shortest distance between them is 2 : (1,\ 4) , (2,\ 4) , and (3,\ 5) . Thus, the condition is satisfied. Sample Input 2 5 8 Sample Output 2 -1 There is no graph satisfying the conditions.
35,875
Score : 700 points Problem Statement Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C , filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}) . The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N . Here, the curves may not go outside the board or cross each other. Determine whether this is possible. Constraints 1 ≀ R,C ≀ 10^8 1 ≀ N ≀ 10^5 0 ≀ x_{i,1},x_{i,2} ≀ R(1 ≀ i ≀ N) 0 ≀ y_{i,1},y_{i,2} ≀ C(1 ≀ i ≀ N) All given points are distinct. All input values are integers. Input Input is given from Standard Input in the following format: R C N x_{1,1} y_{1,1} x_{1,2} y_{1,2} : x_{N,1} y_{N,1} x_{N,2} y_{N,2} Output Print YES if the objective is achievable; print NO otherwise. Sample Input 1 4 2 3 0 1 3 1 1 1 4 1 2 0 2 2 Sample Output 1 YES The above figure shows a possible solution. Sample Input 2 2 2 4 0 0 2 2 2 0 0 1 0 2 1 2 1 1 2 1 Sample Output 2 NO Sample Input 3 5 5 7 0 0 2 4 2 3 4 5 3 5 5 2 5 5 5 4 0 3 5 1 2 2 4 4 0 5 4 1 Sample Output 3 YES Sample Input 4 1 1 2 0 0 1 1 1 0 0 1 Sample Output 4 NO
35,876
Problem E: The Devil of Gravity Haven't you ever thought that programs written in Java, C++, Pascal, or any other modern computer languages look rather sparse? Although most editors provide sufficient screen space for at least 80 characters or so in a line, the average number of significant characters occurring in a line is just a fraction. Today, people usually prefer readability of programs to efficient use of screen real estate. Dr. Faust, a radical computer scientist, believes that editors for real programmers shall be more space efficient. He has been doing research on saving space and invented various techniques for many years, but he has reached the point where no more essential improvements will be expected with his own ideas. After long thought, he has finally decided to take the ultimate but forbidden approach. He does not hesitate to sacrifice anything for his ambition, and asks a devil to give him supernatural intellectual powers in exchange with his soul. With the transcendental knowledge and ability, the devil provides new algorithms and data structures for space efficient implementations of editors. The editor implemented with those evil techniques is beyond human imaginations and behaves somehow strange. The mighty devil Dr. Faust asks happens to be the devil of gravity. The editor under its control saves space with magical magnetic and gravitational forces. Your mission is to defeat Dr. Faust by re-implementing this strange editor without any help of the devil. At first glance, the editor looks like an ordinary text editor. It presents texts in two-dimensional layouts and accepts editing commands including those of cursor movements and character insertions and deletions. A text handled by the devil's editor, however, is partitioned into text segments, each of which is a horizontal block of non-blank characters. In the following figure, for instance, four text segments " abcdef ", " ghijkl ", " mnop ", " qrstuvw " are present and the first two are placed in the same row. abcdef ghijkl mnop qrstuvw The editor has the following unique features. A text segment without any supporting segments in the row immediately below it falls by the evil gravitational force. Text segments in the same row and contiguous to each other are concatenated by the evil magnetic force. For instance, if characters in the segment " mnop " in the previous example are deleted, the two segments on top of it fall and we have the following. abcdef qrstuvw ghijkl After that, if " x " is added at the tail (i.e., the right next of the rightmost column) of the segment " qrstuvw ", the two segments in the bottom row are concatenated. abcdef qrstuvwxghijkl Now we have two text segments in this figure. By this way, the editor saves screen space but demands the users' extraordinary intellectual power. In general, after a command execution, the following rules are applied, where S is a text segment, left( S ) and right( S ) are the leftmost and rightmost columns of S , respectively, and row( S ) is the row number of S . If the columns from left( S ) to right( S ) in the row numbered row( S )-1 (i.e., the row just below S ) are empty (i.e., any characters of any text segments do not exist there), S is pulled down to row( S )-1 vertically, preserving its column position. If the same ranges in row( S )-2, row( S )-3, and so on are also empty, S is further pulled down again and again. This process terminates sooner or later since the editor has the ultimate bottom, the row whose number is zero. If two text segments S and T are in the same row and right( S )+1 = left( T ), that is, T starts at the right next column of the rightmost character of S , S and T are automatically concatenated to form a single text segment, which starts at left( S ) and ends at right( T ). Of course, the new segment is still in the original row. Note that any text segment has at least one character. Note also that the first rule is applied prior to any application of the second rule. This means that no concatenation may occur while falling segments exist. For instance, consider the following case. dddddddd cccccccc bbbb aaa If the last character of the text segment " bbbb " is deleted, the concatenation rule is not applied until the two segments " cccccccc " and " dddddddd " stop falling. This means that " bbb " and " cccccccc " are not concatenated. The devil's editor has a cursor and it is always in a single text segment, which we call the current segment. The cursor is at some character position of the current segment or otherwise at its tail. Note that the cursor cannot be a support. For instance, in the previous example, even if the cursor is at the last character of " bbbb " and it stays at the same position after the deletion, it cannot support " cccccccc " and " dddddddd " any more by solely itself and thus those two segments shall fall. Finally, the cursor is at the leftmost " d " The editor accepts the following commands, each represented by a single character. F: Move the cursor forward (i.e., to the right) by one column in the current segment. If the cursor is at the tail of the current segment and thus it cannot move any more within the segment, an error occurs. B: Move the cursor backward (i.e., to the left) by one column in the current segment. If the cursor is at the leftmost position of the current segment, an error occurs. P: Move the cursor upward by one row. The column position of the cursor does not change. If the new position would be out of the legal cursor range of any existing text segment, an error occurs. N: Move the cursor downward by one row. The column position of the cursor does not change. If the cursor is in the bottom row or the new position is out of the legal cursor range of any existing text segment, an error occurs. D: Delete the character at the cursor position. If the cursor is at the tail of the current segment and so no character is there, an error occurs. If the cursor is at some character, it is deleted and the current segment becomes shorter by one character. Neither the beginning (i.e., leftmost) column of the current segment nor the column position of the cursor changes. However, if the current segment becomes empty, it is removed and the cursor falls by one row. If the new position would be out of the legal cursor range of any existing text segment, an error occurs. Note that after executing this command, some text segments may lose their supports and be pulled down toward the hell. If the current segment falls, the cursor also falls with it. C: Create a new segment of length one immediately above the current cursor position. It consists of a copy of the character under the cursor. If the cursor is at the tail, an error occurs. Also if the the position of the new segment is already occupied by another segment, an error occurs. After executing the command, the created segment becomes the new current segment and the column position of the cursor advances to the right by one column. Lowercase and numeric characters (` a ' to ` z ' and ` 0 ' to ` 9 '): Insert the character at the current cursor position. The current segment becomes longer by one character. The cursor moves forward by one column. The beginning column of the current segment does not change. Once an error occurs, the entire editing session terminates abnormally. Input The first line of the input contains an integer that represents the number of editing sessions. Each of the following lines contains a character sequence, where the first character is the initial character and the rest represents a command sequence processed during a session. Each session starts with a single segment consisting of the initial character in the bottom row. The initial cursor position is at the tail of the segment. The editor processes each command represented by a character one by one in the manner described above. You may assume that each command line is non-empty and its length is at most one hundred. A command sequence ends with a newline. Output For each editing session specified by the input, if it terminates without errors, your program should print the current segment at the completion of the session in a line. If an error occurs during the session, just print " ERROR " in capital letters in a line. Sample Input 3 12BC3BC4BNBBDD5 aaaBCNBBBCb aaaBBCbNBC Output for the Sample Input 15234 aba ERROR
35,877
問題 A : Koto Distance 問題文 Koto は蚀わずず知れた碁盀の目の街である この街は東西方向に W メヌトル南北方向に H メヌトルに䌞びる長方圢の領域によっおできおいる この街の西端から x メヌトル南端から y メヌトルの点は (x, y) ず蚘される ここの街に䜏む人は叀くから䌝わる独自の文化を重んじおおりその䞀぀にKoto距離ずいう倉わった距離尺床がある 2぀の点 (x_1, y_1)  (x_2, y_2) の Koto 距離はmin (|x_1 - x_2|, |y_1 - y_2|) によっお定矩される 最近この街党䜓に Wifi を䜿えるようにする蚈画が立ち䞊がった 珟圚の蚈画では芪機を N 個䜜るこずになっおいる i 番目の芪機は点 (x_i, y_i) に蚭眮されKoto距離が w_i 以䞋の領域に察しお Wifi を提䟛する 芪機を蚈画どおり建おた堎合に街の内郚及び境界䞊に Wifi を提䟛できるかどうかを刀定せよ なおKoto距離は䞀般に䞉角䞍等匏を満たさないため距離の公理を満たさないずいうこずはここだけの秘密である 入力圢匏 入力は以䞋の圢匏で䞎えられる N W H x_1 y_1 w_1 ... x_N y_N w_N 出力圢匏 街の内郚および境界䞊に Wifi を提䟛できるなら “Yes” をそうでない堎合は “No” を出力せよ 制玄 1 ≀ N ≀ 10^5 1 ≀ W ≀ 10^5 1 ≀ H ≀ 10^5 0 ≀ x_i ≀ W 0 ≀ y_i ≀ H 1 ≀ w_i ≀ 10^5 同䞀座暙に芪機は耇数存圚しない 入出力䟋 入力䟋 1 3 9 9 2 2 2 5 5 2 8 8 2 出力䟋 1 Yes 番目の芪機が提䟛するWifiの範囲は以䞋の通りである 入力䟋 2 2 7 7 2 2 1 6 6 1 出力䟋 2 No 入力䟋 3 3 10 20 5 10 5 2 10 1 8 10 1 出力䟋 3 Yes
35,878
電子レンゞ (Microwave) 問題 JOI 君は食事の準備のためA ℃の肉を電子レンゞで B ℃たで枩めようずしおいる 肉は枩床が 0 ℃未満のずき凍っおいる たた枩床が 0 ℃より高いずき凍っおいない 枩床がちょうど 0 ℃のずきの肉の状態は凍っおいる堎合ず凍っおいない堎合の䞡方があり埗る JOI 君は肉の加熱にかかる時間は以䞋のようになるず仮定しお肉を枩めるのにかかる時間を芋積もるこずにした 肉が凍っおいおその枩床が 0 ℃より小さいずき C 秒で 1 ℃枩たる 肉が凍っおいおその枩床がちょうど 0 ℃のずき D 秒で肉が解凍され凍っおいない状態になる 肉が凍っおいないずき E 秒で 1 ℃枩たる この芋積もりにおいお肉を B ℃にするのに䜕秒かかるかを求めよ 入力 入力は 5 行からなり1 行に 1 個ず぀敎数が曞かれおいる 1 行目にはもずもずの肉の枩床 A が曞かれおいる 2 行目には目的の枩床 B が曞かれおいる 3 行目には凍った肉を 1 ℃枩めるのにかかる時間 C が曞かれおいる 4 行目には凍った肉を解凍するのにかかる時間 D が曞かれおいる 5 行目には凍っおいない肉を 1 ℃枩めるのにかかる時間 E が曞かれおいる もずもずの枩床 A は -100 以䞊 100 以䞋目的の枩床 B は 1 以䞊 100 以䞋でありA ≠ 0 および A < B を満たす 枩めるのにかかる時間 C, D, E はすべお 1 以䞊 100 以䞋である 出力 肉を B ℃にするのにかかる秒数を 1 行で出力せよ 入出力䟋 入力䟋 1 -10 20 5 10 3 出力䟋 1 120 入力䟋 2 35 92 31 50 11 出力䟋 2 627 入出力䟋 1 ではもずもずの肉は -10 ℃で凍っおいるかかる時間は以䞋のようになる -10 ℃から 0 ℃たで枩めるのに 5 × 10 = 50 秒 0 ℃の肉を解凍するのに 10 秒 0 ℃から 20 ℃たで枩めるのに 3 × 20 = 60 秒 したがっおかかる時間の合蚈は 120 秒である 入出力䟋 2 ではもずもずの肉は凍っおいないしたがっお肉を 35 ℃から 92 ℃たで枩めるのにかかる時間は 627 秒である 情報オリンピック日本委員䌚䜜 『第 16 回日本情報オリンピック JOI 2016/2017 予遞競技課題』
35,879
G: Toss Cut Tree Problem Statement You are given two trees T, U . Each tree has N vertices that are numbered 1 through N . The i -th edge ( 1 \leq i \leq N-1 ) of tree T connects vertices a_i and b_i . The i -th edge ( 1 \leq i \leq N-1 ) of tree U connects vertices c_i and d_i . The operation described below will be performed N times. On the i -th operation, flip a fair coin. If it lands heads up, remove vertex i and all edges directly connecting to it from tree T . If it lands tails up, remove vertex i and all edges directly connecting to it from tree U . After N operations, each tree will be divided into several connected components. Let X and Y be the number of connected components originated from tree T and U , respectively. Your task is to compute the expected value of X \times Y . More specifically, your program must output an integer R described below. First, you can prove X \times Y is a rational number. Let P and Q be coprime integers that satisfies \frac{P}{Q} = X \times Y . R is the only integer that satisfies R \times Q $\equiv$ P $ \bmod \;$ 998244353, 0 \leq R < 998244353 . Input N a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_{N-1} d_{N-1} Constraints 1 \leq N \leq 2 \times 10^5 1 \leq a_i, b_i, c_i, d_i \leq N The given two graphs are trees. All values in the input are integers. Output Print R described above in a single line. Sample Input 1 3 1 2 2 3 1 2 3 1 Output for Sample Input 1 1 A coin is flipped 3 times. Therefore, there are 2^3 = 8 outcomes in total. Suppose that the outcome was (tail, head, tail) in this order. Vertex 2 of tree T and vertex 1 , 3 of tree U are removed along with all edges connecting to them. T , U are decomposed to 2 , 1 connected components, respectively. Thus, the value of XY is 2 \times 1 = 2 in this case. It is possible to calculate XY for the other cases in the same way and the expected value of XY is 1 . Sample Input 2 4 1 2 1 4 2 3 1 4 4 2 2 3 Output for Sample Input 2 374341634 The expected number of XY is \frac{13}{8} .
35,880
Baseball Simulation Ichiro likes baseball and has decided to write a program which simulates baseball. The program reads events in an inning and prints score in that inning. There are only three events as follows: Single hit put a runner on the first base. the runner in the first base advances to the second base and the runner in the second base advances to the third base. the runner in the third base advances to the home base (and go out of base) and a point is added to the score. Home run all the runners on base advance to the home base. points are added to the score by an amount equal to the number of the runners plus one. Out The number of outs is increased by 1. The runners and the score remain stationary. The inning ends with three-out. Ichiro decided to represent these events using "HIT", "HOMERUN" and "OUT", respectively. Write a program which reads events in an inning and prints score in that inning. You can assume that the number of events is less than or equal to 100. Input The input consists of several datasets. In the first line, the number of datasets n is given. Each dataset consists of a list of events (strings) in an inning. Output For each dataset, prints the score in the corresponding inning. Sample Input 2 HIT OUT HOMERUN HIT HIT HOMERUN HIT OUT HIT HIT HIT HIT OUT HIT HIT OUT HIT OUT OUT Output for the Sample Input 7 0
35,881
぀の倚角圢 ダ゚さんは本以䞊の真っすぐな棒を繋げお倚角圢を䜜り、恋人のゞョり君にプレれントするこずにしたした。棒はそれらの端点でのみ繋げるこずができたす。端点はすべお同じ平面䞊に眮きたす。䞀぀の接合点で繋がる棒は本だけで、それらがなす角床は自由に決めるこずができたす。 ダ゚さんは、自分が持っおいる棒をすべお䜿っお倧きさが同じくらいの぀の倚角圢を䜜ろうずしおいたす。 䞎えられたすべおの棒を䜿っお、぀の倚角圢を、それらの呚囲の長さの差の絶察倀が最小ずなるように䜜る。各棒の長さが䞎えられたずき、぀の倚角圢の呚囲の長さの差の絶察倀を求めるプログラムを䜜成せよ。぀の倚角圢を䜜成できない堎合はそのこずを報告せよ。ただし、長さが$a_1 \leq a_2 \leq ... \leq a_m$である$m$ ($3 \leq m$)本の棒で、$a_m a_1+a_2+ ... +a_{m-1}$を満たすずき、これら$m$本の棒でひず぀の倚角圢を䜜成できるものずする。 入力 入力は以䞋の圢匏で䞎えられる。 $N$ $a_1$ $a_2$ ... $a_N$ 行目に棒の数$N$ ($6 \leq N \leq 40$)が䞎えられる。行目に各棒の長さ$a_i$ ($1 \leq a_i \leq 100$)が䞎えられる。 出力 䞎えられたすべおの棒を䜿っお぀の倚角圢を䜜れる堎合は、長さの差の絶察倀の最小倀を行に出力する。぀の倚角圢を䜜れない堎合は「-1」を行に出力する。 入出力䟋 入力䟋 6 2 2 3 2 2 2 出力䟋 1 入力䟋 7 2 2 3 2 2 2 1 出力䟋 0 入力䟋 6 1 1 1 1 2 4 出力䟋 -1
35,882
Score : 600 points Problem Statement We have 3N cards arranged in a row from left to right, where each card has an integer between 1 and N (inclusive) written on it. The integer written on the i -th card from the left is A_i . You will do the following operation N-1 times: Rearrange the five leftmost cards in any order you like, then remove the three leftmost cards. If the integers written on those three cards are all equal, you gain 1 point. After these N-1 operations, if the integers written on the remaining three cards are all equal, you will gain 1 additional point. Find the maximum number of points you can gain. Constraints 1 \leq N \leq 2000 1 \leq A_i \leq N Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_{3N} Output Print the maximum number of points you can gain. Sample Input 1 2 1 2 1 2 2 1 Sample Output 1 2 Let us rearrange the five leftmost cards so that the integers written on the six cards will be 2\ 2\ 2\ 1\ 1\ 1 from left to right. Then, remove the three leftmost cards, all of which have the same integer 2 , gaining 1 point. Now, the integers written on the remaining cards are 1\ 1\ 1 . Since these three cards have the same integer 1 , we gain 1 more point. In this way, we can gain 2 points - which is the maximum possible. Sample Input 2 3 1 1 2 2 3 3 3 2 1 Sample Output 2 1 Sample Input 3 3 1 1 2 2 2 3 3 3 1 Sample Output 3 3
35,883
暙高差 今たで登ったこずのある山の暙高を蚘録したデヌタがありたす。このデヌタを読み蟌んで、䞀番高い山ず䞀番䜎い山の暙高差を出力するプログラムを䜜成しおください。 Input 入力は以䞋の圢匏で䞎えられたす。 山の高さ ... ... 山の高さが耇数行に枡っお䞎えられたす。入力される倀はすべお 0 以䞊 1,000,000 以䞋の実数です。入力される山の高さの数は 50 以䞋です。 Output 䞀番高い山ず䞀番䜎い山の暙高差を実数で出力する。出力は0.01以䞋の誀差を含んでもよい。 Sample Input 3776.0 1819.0 645.2 2004.1 1208.6 Output for the Sample Input 3130.8
35,884
Score : 200 points Problem Statement We have a rectangular parallelepiped of size A×B×C , built with blocks of size 1×1×1 . Snuke will paint each of the A×B×C blocks either red or blue, so that: There is at least one red block and at least one blue block. The union of all red blocks forms a rectangular parallelepiped. The union of all blue blocks forms a rectangular parallelepiped. Snuke wants to minimize the difference between the number of red blocks and the number of blue blocks. Find the minimum possible difference. Constraints 2≀A,B,C≀10^9 Input The input is given from Standard Input in the following format: A B C Output Print the minimum possible difference between the number of red blocks and the number of blue blocks. Sample Input 1 3 3 3 Sample Output 1 9 For example, Snuke can paint the blocks as shown in the diagram below. There are 9 red blocks and 18 blue blocks, thus the difference is 9 . Sample Input 2 2 2 4 Sample Output 2 0 For example, Snuke can paint the blocks as shown in the diagram below. There are 8 red blocks and 8 blue blocks, thus the difference is 0 . Sample Input 3 5 3 5 Sample Output 3 15 For example, Snuke can paint the blocks as shown in the diagram below. There are 45 red blocks and 30 blue blocks, thus the difference is 9 .
35,885
Problem A: Hit and Blow Hit and blow is a popular code-breaking game played by two people, one codemaker and one codebreaker. The objective of this game is that the codebreaker guesses correctly a secret number the codemaker makes in his or her mind. The game is played as follows. The codemaker first chooses a secret number that consists of four different digits, which may contain a leading zero. Next, the codebreaker makes the first attempt to guess the secret number. The guessed number needs to be legal (i.e. consist of four different digits). The codemaker then tells the numbers of hits and blows to the codebreaker. Hits are the matching digits on their right positions, and blows are those on different positions. For example, if the secret number is 4321 and the guessed is 2401, there is one hit and two blows where 1 is a hit and 2 and 4 are blows. After being told, the codebreaker makes the second attempt, then the codemaker tells the numbers of hits and blows, then the codebreaker makes the third attempt, and so forth. The game ends when the codebreaker gives the correct number. Your task in this problem is to write a program that determines, given the situation, whether the codebreaker can logically guess the secret number within the next two attempts. Your program will be given the four-digit numbers the codebreaker has guessed, and the responses the codemaker has made to those numbers, and then should make output according to the following rules: if only one secret number is possible, print the secret number; if more than one secret number is possible, but there are one or more critical numbers, print the smallest one; otherwise, print “????” (four question symbols). Here, critical numbers mean those such that, after being given the number of hits and blows for them on the next attempt, the codebreaker can determine the secret number uniquely. Input The input consists of multiple data sets. Each data set is given in the following format: N four-digit-number 1 n-hits 1 n-blows 1 ... four-digit-number N n-hits N n-blows N N is the number of attempts that has been made. four-digit-number i is the four-digit number guessed on the i -th attempt, and n-hits i and n-blows i are the numbers of hits and blows for that number, respectively. It is guaranteed that there is at least one possible secret number in each data set. The end of input is indicated by a line that contains a zero. This line should not be processed. Output For each data set, print a four-digit number or “????” on a line, according to the rules stated above. Sample Input 2 1234 3 0 1245 3 0 1 1234 0 0 2 0123 0 4 1230 0 4 0 Output for the Sample Input 1235 ???? 0132
35,886
Score : 700 points Problem Statement 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}} -th. The score of a participant is the product of his/her ranks in the two contests. Process the following Q queries: In the i -th query, you are given two positive integers A_i and B_i . Assuming that Takahashi was ranked A_i -th in the first contest and B_i -th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. Constraints 1 \leq Q \leq 100 1\leq A_i,B_i\leq 10^9(1\leq i\leq Q) All values in input are integers. Input Input is given from Standard Input in the following format: Q A_1 B_1 : A_Q B_Q Output For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's. Sample Input 1 8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323 Sample Output 1 1 12 4 11 14 57 31 671644785 Let us denote a participant who was ranked x -th in the first contest and y -th in the second contest as (x,y) . In the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1 .
35,887
Problem K Min-Max Distance Game Alice and Bob are playing the following game. Initially, $n$ stones are placed in a straight line on a table. Alice and Bob take turns alternately. In each turn, the player picks one of the stones and removes it. The game continues until the number of stones on the straight line becomes two. The two stones are called result stones . Alice's objective is to make the result stones as distant as possible, while Bob's is to make them closer. You are given the coordinates of the stones and the player's name who takes the first turn. Assuming that both Alice and Bob do their best, compute and output the distance between the result stones at the end of the game. Input The input consists of a single test case with the following format. $n$ $f$ $x_1$ $x_2$ ... $x_n$ $n$ is the number of stones $(3 \leq n \leq 10^5)$. $f$ is the name of the first player, either Alice or Bob. For each $i$, $x_i$ is an integer that represents the distance of the $i$-th stone from the edge of the table. It is guaranteed that $0 \leq x_1 < x_2 < ... < x_n \leq 10^9$ holds. Output Output the distance between the result stones in one line. Sample Input 1 5 Alice 10 20 30 40 50 Sample Output 1 30 Sample Input 2 5 Bob 2 3 5 7 11 Sample Output 2 2
35,888
Score : 1000 points Problem Statement There is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i -th card from the top is A_i . Snuke will repeat the following operation until two cards remain: Choose three consecutive cards from the stack. Eat the middle card of the three. For each of the other two cards, replace the integer written on it by the sum of that integer and the integer written on the card eaten. Return the two cards to the original position in the stack, without swapping them. Find the minimum possible sum of the integers written on the last two cards remaining. Constraints 2 \leq N \leq 18 0 \leq A_i \leq 10^9 (1\leq i\leq N) 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 minimum possible sum of the integers written on the last two cards remaining. Sample Input 1 4 3 1 4 2 Sample Output 1 16 We can minimize the sum of the integers written on the last two cards remaining by doing as follows: Initially, the integers written on the cards are 3 , 1 , 4 , and 2 from top to bottom. Choose the first, second, and third card from the top. Eat the second card with 1 written on it, add 1 to each of the other two cards, and return them to the original position in the stack. The integers written on the cards are now 4 , 5 , and 2 from top to bottom. Choose the first, second, and third card from the top. Eat the second card with 5 written on it, add 5 to each of the other two cards, and return them to the original position in the stack. The integers written on the cards are now 9 and 7 from top to bottom. The sum of the integers written on the last two cards remaining is 16 . Sample Input 2 6 5 2 4 1 6 9 Sample Output 2 51 Sample Input 3 10 3 1 4 1 5 9 2 6 5 3 Sample Output 3 115
35,889
B - ラむオン あなたは動物園に来おラむオンを芋おいる。 この動物園には n 個のラむオンのオリがある。 あなたはラむオンが党郚で䜕頭いるのか知りたくなったのだが、 䞀人で数えるのは倧倉だ。 そこで近くにいた動物園の来園者 m 人に協力しおもらうこずにした。 ラむオンのオリは、それぞれ 1 番から n 番たでの数字が぀いおおり、 順番に䞊んでいる。 䞀぀のオリには 0 頭以䞊 x 頭以䞋のラむオンがいる。 m 人の来園者で i 番目の人 (1 ≀ i ≀ m) には l_i 番から r_i 番たでの 䞡端を含むすべおのオリのラむオンの数の総和を数えおもらった。 この情報を元に、 1 から n 各オリの䞭のラむオンの数を求めるこずにした。 入力圢匏 入力は以䞋の圢匏で䞎えられる n x m l_1 r_1 s_1 ... l_m r_m s_m 1行目は3぀の敎数 n x m で、 それぞれオリの数、䞀぀のオリの䞭のラむオンの最倧の数、 数えるのに協力した人の数である。 2行目から続く m 行は各行3぀の敎数で、 それぞれ i 番目の人が数えた結果 l_i r_i s_i である。 l_i 番から r_i 番たでのオリのラむオンを数えたら 合蚈 s_i 頭いたこずを衚しおいる。 出力圢匏 数えおもらった結果が党お正しいずしお、 1 から n の 各オリの䞭のラむオンの数を空癜区切りの n 個の敎数で出力せよ。 そのような答が耇数あるずきは、 ラむオンの数の合蚈が最倧になるものをどれでも良いので䞀぀出力せよ。 条件を満たすラむオンの配眮が䞀぀もないずきは -1 を出力せよ。 制玄 1 ≀ n ≀ 6 1 ≀ x ≀ 10 1 ≀ m ≀ 10 1 ≀ l_i ≀ r_i ≀ n 0 ≀ s_i ≀ 60 入力倀はすべお敎数である。 入出力䟋 入力䟋 1 3 5 1 1 2 5 出力䟋 1 2 3 5 その他"4 1 5"や"0 5 5"なども正しい出力である。 入力䟋 2 4 5 2 1 3 15 3 4 3 出力䟋 2 -1 条件を満たすラむオンの配眮が䞀぀もないずきは -1 を出力せよ。
35,890
Problem D: Revenge of Champernowne Constant Champernowne constant is an irrational number. Its decimal representation starts with "0.", followed by concatenation of all positive integers in the increasing order. You will be given a sequence S which consists of decimal digits. Your task is to write a program which computes the position of the first occurrence of S in Champernowne constant after the decimal point. Input The input has multiple test cases. Each line of the input has one digit sequence. The input is terminated by a line consisting only of # . It is guaranteed that each sequence has at least one digit and its length is less than or equal to 100. Output For each sequence, output one decimal integer described above. You can assume each output value is less than 10 16 . Sample Input 45678 67891011 21 314159265358979 # Output for the Sample Input 4 6 15 2012778692735799
35,891
Score : 800 points Problem Statement Takahashi Lake has a perimeter of L . On the circumference of the lake, there is a residence of the lake's owner, Takahashi. Each point on the circumference of the lake has a coordinate between 0 and L (including 0 but not L ), which is the distance from the Takahashi's residence, measured counter-clockwise. There are N trees around the lake; the coordinate of the i -th tree is X_i . There is no tree at coordinate 0 , the location of Takahashi's residence. Starting at his residence, Takahashi will repeat the following action: If all trees are burnt, terminate the process. Specify a direction: clockwise or counter-clockwise. Walk around the lake in the specified direction, until the coordinate of a tree that is not yet burnt is reached for the first time. When the coordinate with the tree is reached, burn that tree, stay at the position and go back to the first step. Find the longest possible total distance Takahashi walks during the process. Partial Score A partial score can be obtained in this problem: 300 points will be awarded for passing the input satisfying N \leq 2000 . Constraints 2 \leq L \leq 10^9 1 \leq N \leq 2\times 10^5 1 \leq X_1 < ... < X_N \leq L-1 All values in input are integers. Input Input is given from Standard Input in the following format: L N X_1 : X_N Output Print the longest possible total distance Takahashi walks during the process. Sample Input 1 10 3 2 7 9 Sample Output 1 15 Takahashi walks the distance of 15 if the process goes as follows: Walk a distance of 2 counter-clockwise, burn the tree at the coordinate 2 and stay there. Walk a distance of 5 counter-clockwise, burn the tree at the coordinate 7 and stay there. Walk a distance of 8 clockwise, burn the tree at the coordinate 9 and stay there. Sample Input 2 10 6 1 2 3 6 7 9 Sample Output 2 27 Sample Input 3 314159265 7 21662711 77271666 89022761 156626166 160332356 166902656 298992265 Sample Output 3 1204124749
35,892
Problem E: Light Source Problem 二次元平面䞊に n 個の円状の光源が配眮されおいる。ある光源が光を受けるず、䞋図のようにその光源の䞭心点から扇状に光が攟出される。 光源の䞭心点は( x , y )、半埄は r で衚される。 光ずなる扇圢は角 β を䞭心に- Ξ /2, + Ξ /2の方向ぞ察称に広がり、その半埄は α である。 光源の円が扇型の光に完党に芆われるずき、光源はその光を受けたずみなされる。光源から攟出される光の匷さは、受けた光の匷さの合蚈ずなる。ただし、攟出される光の匷さには䞊限があり、䞊限を超えた堎合、光の匷さは䞊限倀ず同じになる。なお、ある光や光源によっお光が遮られるこずはない。 ある地点に存圚する光源を目的光源ずする。目的光源では光が攟出されず、受ける光の匷さに制限はない。 あなたは座暙(0,0)から、ある匷さの扇圢の光を、任意の方向に床だけ攟出するこずができる。目的光源が受ける光の匷さの合蚈の最倧倀を求めるプログラムを䜜成せよ。ただし、党おの光源においお、攟出された光が元の光源に戻るような入力デヌタは䞎えられないず仮定しおよい。たた、この問題では、領域の境界からの距離が0.000001以内の堎合、領域䞊ずみなすこずにする。 Input n Ξ 0 α 0 power x 1 y 1 r 1 Ξ 1 α 1 β 1 maxpower 1 . . x n y n r n Ξ n α n β n maxpower n x n+1 y n+1 r n+1 1行目には目的光源を陀く光源の数 n が䞎えられる。 2行目に最初に光を攟出する座暙(0,0)の情報、3行目からn+2行目に目的でない光源の情報、n+3行目に目的光源の情報がそれぞれ空癜区切りで䞎えられる。 各情報に察しお、 x i , y i は光源の䞭心点の座暙、 r i は光源の半埄、 Ξ i は光が広がる角床、 α i は光の半埄、 β i は光が向かう方向を衚す。2行目の power は最初に攟出される光の匷さ、3行目からn+2行目の maxpower i は攟出される光の䞊限を衚す。 光の方向 β i はx軞の正の向きから反時蚈回りに回転し、各角床の単䜍は床ずする。 Constraints 入力は以䞋の条件を満たす。 入力は党お敎数からなる 1 ≀ n ≀ 100 -1000 ≀ x i , y i ≀ 1000 1 ≀ r i ≀ 1000 1 ≀ Ξ i ≀ 180 1 ≀ α i ≀ 1000 0 ≀ β i < 360 0 ≀ power , maxpower i ≀ 1000 Output 目的光源を党お囲うような光の匷さの合蚈の最倧倀を1行に出力せよ。 Sample Input 1 1 90 10 20 3 3 1 90 10 315 10 6 0 1 Sample Output 1 30 Sample Input 2 2 90 10 10 -3 0 1 45 10 90 10 -6 0 2 30 3 180 10 -9 0 1 Sample Output 2 10
35,893
10問解いたら䜕点取れる 遞手の皆さん、パ゜コン甲子園にようこそ。パ゜コン甲子園は今幎で10呚幎になりたすが、出題される問題数や合蚈埗点は幎によっお異なりたす。各問題には難易床に応じお埗点が決められおいたす。問題数が10問で、それぞれの問題の埗点が䞎えられるずき、それらの合蚈を出力するプログラムを䜜成しお䞋さい。 入力 入力は以䞋の圢匏で䞎えられる。 s 1 s 2 . . s 10 入力は10行からなり、i 行目に問題 i の埗点を衚す敎数 s i (0≀ s i ≀ 100)が䞎えられる。 出力 合蚈埗点を行に出力する。 入力䟋1 1 2 3 4 5 6 7 8 9 10 出力䟋1 55 入力䟋2 4 4 8 8 8 10 10 12 16 20 出力䟋2 100
35,894
Score : 200 points Problem Statement In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i ( 1 \leq i \leq N ), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i , excluding the endpoints. Find the maximum number of robots that we can keep. Constraints 1 \leq N \leq 100,000 0 \leq X_i \leq 10^9 ( 1 \leq i \leq N ) 1 \leq L_i \leq 10^9 ( 1 \leq i \leq N ) If i \neq j , X_i \neq X_j . All values in input are integers. Input Input is given from Standard Input in the following format: N X_1 L_1 X_2 L_2 \vdots X_N L_N Output Print the maximum number of robots that we can keep. Sample Input 1 4 2 4 4 3 9 3 100 5 Sample Output 1 3 By removing Robot 2 , we can keep the other three robots. Sample Input 2 2 8 20 1 10 Sample Output 2 1 Sample Input 3 5 10 1 2 1 4 1 6 1 8 1 Sample Output 3 5
35,895
Score : 1000 points Problem Statement Welcome to CODE FESTIVAL 2016! In order to celebrate this contest, find a string s that satisfies the following conditions: The length of s is between 1 and 5000 , inclusive. s consists of uppercase letters. s contains exactly K occurrences of the string "FESTIVAL" as a subsequence. In other words, there are exactly K tuples of integers (i_0, i_1, ..., i_7) such that 0 ≀ i_0 < i_1 < ... < i_7 ≀ |s|-1 and s[i_0]='F', s[i_1]='E', ..., s[i_7]='L' . It can be proved that under the given constraints, the solution always exists. In case there are multiple possible solutions, you can output any. Constraints 1 ≀ K ≀ 10^{18} Input The input is given from Standard Input in the following format: K Output Print a string that satisfies the conditions. Sample Input 1 7 Sample Output 1 FESSSSSSSTIVAL Sample Input 2 256 Sample Output 2 FFEESSTTIIVVAALL
35,896
Problem G: Dominating Set What you have in your hands is a map of Aizu-Wakamatsu City. The lines on this map represent streets and the dots are street corners. Lion Dor Company is going to build food stores at some street corners where people can go to buy food. It is unnecessary and expensive to build a food store on every corner. Their plan is to build the food stores so that people could get food either right there on the corner where they live, or at the very most, have to walk down only one street to find a corner where there was a food store. Now, all they have to do is figure out where to put the food store. The problem can be simplified as follows. Let G = ( V, E ) be unweighted undirected graph. A dominating set D of G is a subset of V such that every vertex in V - D is adjacent to at least one vertex in D . A minimum dominating set is a dominating set of minimum number of vertices for G . In the example graph given below, the black vertices are the members of the minimum dominating sets. Design and implement an algorithm for the minimum domminating set problem. Input Input has several test cases. Each test case consists of the number of nodes n and the number of edges m in the first line. In the following m lines, edges are given by a pair of nodes connected by the edge. The graph nodess are named with the numbers 0, 1,..., n - 1 respectively. The input terminate with a line containing two 0. The number of test cases is less than 20. Constrants n ≀ 30 m ≀ 50 Output Output the size of minimum dominating set for each test case. Sample Input 5 4 0 1 0 4 1 2 3 4 5 4 0 1 0 4 1 2 3 4 0 0 Output for the Sample Input 2 2
35,897
I: Islands Survival 問題 $N$ 頂点 $M$ 蟺の単玔連結無向グラフがある 頂点には $1, 2, \dots, N$ ず番号が぀けられおいる 蟺には $1, 2, \dots, M$ ず番号が぀けられおおり蟺 $i$ は頂点 $a_i$ ず $b_i$ を぀ないでいる たた蟺 $i$ は時刻 $t_i$ に消えるどの蟺も通過するために単䜍時間がかかる あなたは最初時刻 0 においお頂点 1 にいる あなたは最適に行動するこずで時刻 $T$ たでに埗られるスコアを最倧化したい スコアは最初 0 でありむベントは以䞋に埓っお起きる 今の時刻 $t'$ が $t' \geq T$ を満たすならば終了するそうでなければ 2. ぞ $t_i = t'$ なるすべおの蟺 $i$ が消える あなたがいる頂点を $v$ ずするずき頂点 $v$ を含む連結成分に含たれる頂点数を $x$ ずするずスコアに $x$ が加算される あなたは頂点 $v$ ず隣接しおいる頂点のいずれかに移動するか頂点 $v$ に留たるただし前者の堎合既に消えた蟺を䜿うこずはできない $t' \gets t' + 1$ ずしお 1. ぞ 埗られるスコアの最倧倀を求めよ 制玄 $2 \le N \le 10^5$ $N - 1 \le M \le \min(2 \times 10^5, N(N - 1) / 2)$ $1 \le T \le 10^5$ $1 \le a_i , b_i \le N$ $1 \le t_i \le T$ 䞎えられるグラフは単玔か぀連結 入力圢匏 入力は以䞋の圢匏で䞎えられる $N \ M \ T$ $a_1 \ b_1 \ t_1$ $\vdots$ $a_M \ b_M \ t_M$ 出力 スコアの最倧倀を出力せよたた末尟に改行も出力せよ サンプル サンプル入力1 5 4 2 1 2 2 2 3 1 1 4 2 4 5 1 サンプル出力1 8 時刻 0 に 5時刻 1 に 3 のスコアを埗られる サンプル入力2 4 4 3 1 2 2 2 3 1 3 4 3 4 1 1 サンプル出力2 8 時刻 0 に 4時刻 1 に 2時刻 2 に 2 のスコアを埗られる
35,898
Coin Combination Problem You have 4 bags A, B, C and D each of which includes N coins (there are totally 4N coins). Values of the coins in each bag are a i , b i , c i and d i respectively. Find the number of combinations that result when you choose one coin from each bag (totally 4 coins) in such a way that the total value of the coins is V . You should distinguish the coins in a bag. Constraints 1 ≀ N ≀ 1000 1 ≀ a i , b i , c i , d i ≀ 10 16 1 ≀ V ≀ 10 16 All input values are given in integers Input The input is given in the following format. N V a 1 a 2 ... a N b 1 b 2 ... b N c 1 c 2 ... c N d 1 d 2 ... d N Output Print the number of combinations in a line. Sample Input 1 3 14 3 1 2 4 8 2 1 2 3 7 3 2 Sample Output 1 9 Sample Input 2 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Sample Output 2 625
35,899
プログラミングコンテスト 今幎も癜虎倧孊でプログラミングコンテストが開催されるこずになりたした。コンテストではいく぀かの問題が出題され、それぞれ難易床に応じた埗点が割り圓おられおいたす。 実行委員䌚は、解いた問題の数ずそれらの埗点の䞡方を考慮し、次のルヌルに基づいお各チヌムのスコアを蚈算するこずにしたした。 「あるチヌムが正解した問題のうち、埗点が A 以䞊であるものが A 問以䞊あるこずを満たすような最倧の A を、そのチヌムのスコアずする」 あるチヌムが正解した問題の数ず、それらの問題の埗点から、チヌムのスコアを蚈算するプログラムを䜜成せよ。 Input 入力は以䞋の圢匏で䞎えられる。 N p 1 p 2 ... p N 行目にチヌムが正解した問題の数 N (1 ≀ N ≀ 100) が䞎えられる。行目に正解した各問題の埗点 p i (1 ≀ p i ≀ 100) が䞎えられる。 Output チヌムのスコアを行に出力する。 Sample Input 1 7 5 4 3 10 2 4 1 Sample Output 1 4 埗点が 4 以䞊の問題を 4 問以䞊正解しおいるので、スコアは 4 ずなる。 Sample Input 2 3 1 1 100 Sample Output 2 1 埗点が 1 以䞊の問題を 1 問以䞊正解しおいるので、スコアは 1 ずなる。 Sample Input 3 4 11 15 58 1 Sample Output 3 3 埗点が 3 以䞊の問題を 3 問以䞊正解しおいるので、スコアは 3 ずなる。
35,900