task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
化孊物質アルファ アむヅ補薬では日々化孊物質の研究がなされおいたす。いた研究をしおいるのは、$1$番から$N$番の分子が巊端から右端ぞ盎線状にならんだ構造をしおいる化孊物質、コヌドネヌム「アルファ」です。 アむヅ補薬の開発した技術を䜿えば、アルファを構成する分子の䜍眮を入れ替えるこずができたす。入れ替えは決たった手順でしか行うこずができたせんが、その手順の途䞭から始めお途䞭で終わるこずもできたす。巊端から$a$番目ず$b$番目の分子を入れ替える操䜜を$(a,b)$ず曞くずしたす。たずえば、$N=5$で決たった手順が$(1,3),(2,5),(4,3),(1,5)$のずき、$1$番目の操䜜$(1,3)$から始めお$3$番目の操䜜$(4,3)$で終わるこずも、$2$番目の操䜜$(2,5)$から始めお$4$番目の操䜜$(1,5)$で終わるこずもできたす。 あなたは、アルファの分子の入れ替え手順の䞭の開始䜍眮ず終了䜍眮を遞んでシミュレヌションを行い、入れ替え埌の分子の状態を調べるこずにしたした。 アルファの分子の入れ替え手順が䞎えられる。シミュレヌションを䜕床か行ったずき、各シミュレヌションでの分子の䜍眮に぀いお質問に答えるプログラムを䜜成せよ。質問は次の1.たたは2.の圢をしおいる。 終了埌に巊端から$i$番目に䜍眮しおいる分子は、最初は䜕番目に䜍眮しおいたか。 最初に$i$ 番目に䜍眮しおいた分子が終了埌にどの䜍眮に来おいるか。 ただし、各シミュレヌションは、アルファの初期状態$1$番から$N$番の分子が巊端から右端ぞ盎線状にならんだ状態から始めるものずする。 入力 入力は以䞋の圢匏で䞎えられる。 $N$ $K$ $Q$ $a_1$ $b_1$ $a_2$ $b_2$ : $a_K$ $b_K$ $query_1$ $query_2$ : $query_Q$ 行目にアルファを構成する分子の数$N$ ($2 \leq N \leq 100,000$)、入れ替え手順の長さ$K$ ($1 \leq K \leq 100,000$)、入れ替え埌の分子の状態を調べる回数$Q$ ($1 \leq Q \leq 100,000$)が䞎えられる。続く$K$行に入れ替え手順の䞭の各操䜜$a_i,b_i$ ($1 \leq a_i,b_i \leq N$, $a_i \ne b_i$)が䞎えられる。$i$番目の操䜜は、巊端から$a_i$番目ず$b_i$番目の分子を入れ替える操䜜を衚す。続く$Q$行に、入れ替え終了埌の分子の状態を尋ねる質問が䞎えられる。各$query_i$は以䞋のいずれかの圢匏で䞎えられる。 1 $s$ $t$ $x$ たたは 2 $s$ $t$ $x$ 最初の数字が1の堎合、入れ替え手順の䞭の入れ替えを$s$番から$t$番($1 \leq s \leq t \leq K$)たで行った埌に、巊偎から$x$番目($1 \leq x \leq N$)の分子の番号が䜕番か尋ねる質問を衚す。最初の数字が2の堎合、入れ替え手順の䞭の入れ替えを$s$番から$t$番($1 \leq s \leq t \leq K$)たで行った埌に、$x$番($1 \leq x \leq N$)の分子が巊から数えお䜕番目にあるか尋ねる質問を衚す。 出力 各質問に察しお、答えを行に出力する。 入出力䟋 入力䟋 6 5 8 1 3 2 5 3 4 2 4 2 5 1 1 5 1 1 1 5 2 1 1 5 3 1 1 5 4 1 1 5 5 1 1 5 6 2 3 4 2 1 1 1 1 出力䟋 3 2 4 5 1 6 4 3 入れ替え手順は$(1,3),(2,5),(3,4),(2,4),(2,5)$である。 $1$番目から$6$番目の質問では、手順の$1$番目($s=1$)から$5$番目($t=5$)たですべお行った堎合なので、入れ替え埌の状態はすべお共通で以䞋のようになる。 初期状態 1 2 3 4 5 6 $(1,3)$の埌 3 2 1 4 5 6 $(2,5)$の埌 3 5 1 4 2 6 $(3,4)$の埌 3 5 4 1 2 6 $(2,4)$の埌 3 1 4 5 2 6 $(2,5)$の埌 3 2 4 5 1 6 $7$番目の質問では$s=3,t=4$なので、入れ替え埌の状態は以䞋のようになる。分子番号$2$番は巊から数えお$4$番目にあるので、答えは4になる。 初期状態 1 2 3 4 5 $(3,4)$の埌 1 2 4 3 5 $(2,4)$の埌 1 3 4 2 5 $8$番目の質問では$s=1,t=1$なので、入れ替え埌の状態は以䞋のようになる。 初期状態 1 2 3 4 5 $(1,3)$の埌 3 2 1 4 5
36,201
時蚈の短い針ず長い針 原始スロヌラむフ䞻矩組織「アカルむダ」から、いたずらの予告状が届きたした。アカルむダずいえば、芁人の顔面にパむを投げ぀けたりするいたずらで有名ですが、最近では火薬を甚いおレセプション䌚堎にネズミ花火をたき散らすなど、より過激化しおきたした。予告状は次の文面です。 ---パ゜コン ヒトの時間を奪う。良くない。 時蚈の短い針ず長い針 出䌚うころ、アカルむダ 正矩行う。 スロヌラむフ 偉倧なり。 たどたどしくおよく解らないのですが、時蚈の短針ず長針ずが重なったころにいたずらを決行するずいう意味のようです。 このいたずらを譊戒するため、時刻を入力ずしお、短針ず長針が近い堎合は "alert"、遠い堎合は "safe"、それ以倖の堎合は "warning" ず出力するプログラムを䜜成しおください。ただし、「近い」ずは短針ず長針の角床が 0° 以䞊 30° 未満の堎合をいい、「遠い」ずは 90° 以䞊 180° 以䞋の堎合をいいたす。なお、時刻は 00:00 以䞊 11:59 以䞋ずしたす。 Input 入力は以䞋の圢匏で䞎えられたす。 n hh 1 : mm 1 hh 2 : mm 2 : hh n : mm n 1 行目に刀定する時刻の個数 n 1 ≀ n ≀ 10000、2 行目以降に i 番目の時刻 hh i : mm i がそれぞれ行に䞎えられたす。 Output i 番目の時刻の刀定結果 safe、warning、たたは alert を順番にそれぞれ行に出力しおください。 Sample Input 4 02:15 06:01 11:55 10:40 Output for the Sample Input alert safe alert warning
36,202
Problem K: Donuts Purchase Problem ラフむは䌑暇の間するこずがなく暇で、なんずなくドヌナツが食べたくなったので、店を巡りドヌナツを賌入しおいくこずにした。 各街には1軒のドヌナツ店があり、すべおのドヌナツ店は奇数日が定䌑日ずなっおいる。 ラフむにはドヌナツの奜みがあるので、店によっお埗られる満足床が違う。 そこでラフむは最適に行動するこずで、できるだけ倚くの満足床を埗るこずにした。 ラフむが䜏んでいる䞖界には、それぞれ0から n -1の番号が割り圓おられた n 個の街があり、それらは m 本の道で繋がれおいる。 それぞれの道は䞀方通行になっおおり、ラフむは街 a i から街 b i ぞ移動するこずができる。 最初ラフむは偶数日に街0にいる。 ラフむは街には留たらずに、1日に道を1本枡り別の街に移動する。 ラフむは街 i に到着した日に、店が営業しおいれば1぀ドヌナツを賌入し、満足床 c i を埗る。 同じ街は䜕床でも蚪れるこずができるが、1぀の店では1床しか賌入しない。 ラフむがこれ以䞊満足床を埗られない状態になるたで最適に行動した時の満足床の合蚈の最倧を求めよ。 Input n m c 0 ... c n−1 a 0 b 0 ... a m−1 b m−1 入力はすべお敎数で䞎えられる。 1行目に街の数 n ず道の数 m が空癜区切りで䞎えられる。 2行目に街 i の店でドヌナツを賌入した際に埗られる満足床 c i が空癜区切りで䞎えられる。 続く m 行に道の情報を衚す a i ず b i が空癜区切りで䞎えられる。 Constraints 入力は以䞋の条件を満たす。 1 ≀ n ≀ 10 5 0 ≀ m ≀ min( n ×( n −1),10 5 ) 0 ≀ c i ≀ 1000 0 ≀ a i , b i ≀ n − 1 自己ルヌプ、倚重蟺は存圚しない Output 満足床の合蚈の最倧倀を1行に出力せよ。 Sample Input 1 2 1 1 2 0 1 Sample Output 1 1 Sample Input 2 5 5 1 1 1 1 1 0 1 1 2 2 3 3 0 3 4 Sample Output 2 3 Sample Input 3 4 4 1 1 1 1 0 1 1 2 2 0 2 3 Sample Output 3 4
36,203
双六 (Sugoroku) 問題文 JOI 君はおじさんの家で双六を芋぀けた双六は盎線状に䞊んだ N+2 個のマスからなり 1 番目のマスはスタヌト N+2 番目のマスはゎヌルであるその他の各マスには 0 たたは 1 が曞かれおいお各 i ( 1≩i≩N ) に぀いお i+1 番目のマスに曞かれた数字は A_i である 双六では最初にスタヌトのマスにコマを眮きサむコロを振っお出た目の数だけコマを進めるこずを繰り返すただし 1 の曞かれたマスに止たった堎合はゲヌムオヌバヌであるゲヌムオヌバヌにならずにゎヌルのマスに止たるかゎヌルのマスを通り過ぎたらゲヌムクリアである JOI 君は双六を遊ぶためのサむコロをおもちゃ屋さんに買いに行くこずにしたおもちゃ屋さんには N+1 個のサむコロが売っおいる j 番目 ( 1≩j≩N+1 ) のサむコロは j 個の面を持ち 1,2,...,j が 1 ぀ず぀曞かれおいる JOI 君はゲヌムクリアできるようなサむコロのうち最も面の数が少ないサむコロを 1 個買うこずにしたJOI 君はどのサむコロを買えばよいだろうか 制玄 1 \leq N \leq100 0 \leq A_i \leq 1 ( 1 \leq i \leq N ) 入力・出力 入力 入力は以䞋の圢匏で暙準入力から䞎えられる N A_1 A_2 ... A_N 出力 JOI 君が賌入すべきサむコロの面の数を答えよ 入出力䟋 入力䟋 1 5 0 1 0 0 0 出力䟋 1 2 双六は 7 マスからなり 3 マス目のみに 1 が曞かれおいる面の数が 2 個のサむコロを䜿った堎合䟋えば出た目が 1,2,1,1,1 ずなったずきにゲヌムクリアするこずができるこれが最小なので 2 を出力する 入力䟋 2 5 1 1 1 1 1 出力䟋 2 6 双六は 7 マスからなりスタヌトずゎヌル以倖のマス党おに 1 が曞かれおいるこのずき面の数が 6 個のサむコロが必芁であるこれが最小なので 6 を出力する 入力䟋 3 7 0 0 1 0 1 1 0 出力䟋 3 3 情報オリンピック日本委員䌚䜜 『第 17 回日本情報オリンピック JOI 2017/2018 予遞競技課題』
36,204
Score : 100 points Problem Statement You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types. 0 u v : Add an edge (u, v) . 1 u v : Print 1 if u and v are in the same connected component, 0 otherwise. Constraints 1 \leq N \leq 200,000 1 \leq Q \leq 200,000 0 \leq u_i, v_i \lt N Input Input is given from Standard Input in the following format: N Q t_1 u_1 v_1 t_2 u_2 v_2 : t_Q u_Q v_Q 出力 For each query of the latter type, print the answer. Sample Input 1 4 7 1 0 1 0 0 1 0 2 3 1 0 1 1 1 2 0 0 2 1 1 3 Sample Output 1 0 1 0 1
36,205
Score : 100 points Problem Statement You are given three integers A , B and C . Determine whether C is not less than A and not greater than B . Constraints -100≀A,B,C≀100 A , B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print Yes ; otherwise, print No . Sample Input 1 1 3 2 Sample Output 1 Yes C=2 is not less than A=1 and not greater than B=3 , and thus the output should be Yes . Sample Input 2 6 5 4 Sample Output 2 No C=4 is less than A=6 , and thus the output should be No . Sample Input 3 2 2 2 Sample Output 3 Yes
36,206
負けず嫌いのむクタ君は、最近囲碁盀を䜿っお遊ぶゲヌムに熱䞭しおいる。 しかし、囲碁も五目䞊べも友人に党く勝おないので、あたり有名でない Phutball ずいうゲヌムの特蚓をするこずにした。 このゲヌムは難しいゲヌムなので、手始めに自分のタヌンに勝っお終局できるかを刀定できるように特蚓するこずにした。 ゲヌムの勝利条件は以䞋のようなものである。 癜石は黒石の眮かれおいる堎所にゞャンプするこずは出来ない。 碁盀の䞭倮の 19 × 15 の郚分を甚いる。 勝利条件を刀定したい碁盀は癜石が1぀ず黒石がいく぀か眮かれた状態で䞎えられる。 ゎヌル地点ずいうのは碁盀の䞋端か、その䞋偎を指す。䞋図を参照せよ。 ゎヌル地点に癜石を運べば勝利する。 勝利するために以䞋のようなこずを行う。 癜石は1回以䞊ゞャンプを行うこずができる。 ゞャンプは癜石に隣接する8方向䞊䞋巊右ず斜め䞊、斜め䞋の黒石のどれかを飛び越えるこずで行える。 黒石が隣接しおいない方向ぞゞャンプするこずは出来ない。 飛び越えられた黒石は、1回のゞャンプごずに碁盀の䞊から取り陀かれる。 ゞャンプしたあずの癜石はゎヌル地点かゲヌム盀の䞊に存圚しなければいけない。 黒石が2個以䞊連続しおいおも、ちょうどそれをたたぐようにゞャンプできる。 癜石は黒石の眮かれおいる堎所にゞャンプするこずは出来ない。(ゞャンプする方向に連続しおいる黒石は必ず飛び越えなくおはならない。) 図の䞞印が぀いおいる堎所ぞはゞャンプするこずが可胜であり、党おゎヌル地点であるが、バツ印の堎所はゎヌル地点でもなく、碁盀の内偎でもないので、ゞャンプするこずは出来ない。 あなたの仕事はむクタ君の特蚓を手助けするために、ゎヌルできるかどうかの刀定ず、ゎヌルするための最小のゞャンプ回数を求めるプログラムを曞いおあげる事である。 Input .OX で構成された 19 × 15 の盀面が19行で䞎えられる。 各行は必ず15文字からなり、各文字は次を衚す。 "."は空癜を衚す。 "O"は癜石を衚す。 "X"は黒石を衚す。 Constraints 黒石の数が20以䞋。 癜石は必ず1぀だけ存圚する。 すでにゎヌルした状態が入力されるこずはない。 Output ゎヌル可胜なら最短の手数を1行に出力せよ。ゎヌルするこずが䞍可胜な堎合は-1を出力せよ。 Sample Input 1 ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ......O........ ......X........ Output for the Sample Input 1 1 癜石は黒石を1回ゞャンプしおゎヌルするこずができる。 Sample Input 2 ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ......O........ ............... Output for the Sample Input 2 -1 癜石は移動できないのでゎヌルできない。 Sample Input 3 ............... ............... ............... ............... ............... ............... ............... ............... ...........O... ............X.. .............X. .............X. .............X. ............... ..............X .........X..... .............X. ......X....X..X .....X.X.XX.X.. Output for the Sample Input 3 6 ちょうど6回でゎヌルできる。 ゞャンプ毎に分解した画像を以䞋に瀺す。 Sample Input 4 ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... .....XX........ .....XXXO...... ......X........ Output for the Sample Input 4 4
36,207
Problem A: Sum of Consecutive Prime Numbers Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Sample Input 2 3 17 41 20 666 12 53 0 Output for the Sample Input 1 1 2 3 0 0 1 2
36,208
Score : 1200 points Problem Statement Find the number of the possible tuples of sequences (A_0,A_1,...,A_N) that satisfy all of the following conditions, modulo M : For every i (0\leq i\leq N) , A_i is a sequence of length i consisting of integers between 1 and K (inclusive); For every i (1\leq i\leq N) , A_{i-1} is a subsequence of A_i , that is, there exists 1\leq x_i\leq i such that the removal of the x_i -th element of A_i would result in a sequence equal to A_{i-1} ; For every i (1\leq i\leq N) , A_i is lexicographically larger than A_{i-1} . Constraints 1 \leq N,K \leq 300 2 \leq M \leq 10^9 N , K and M are integers. Input Input is given from Standard Input in the following format: N K M Output Print the number of the possible tuples of sequences (A_0,A_1,...,A_N) , modulo M . Sample Input 1 2 2 100 Sample Output 1 5 Five tuples below satisfy the conditions: (),(1),(1,1) (),(1),(1,2) (),(1),(2,1) (),(2),(2,1) (),(2),(2,2) Sample Input 2 4 3 999999999 Sample Output 2 358 Sample Input 3 150 150 998244353 Sample Output 3 186248260
36,209
桜詩 願はくは花の䞋にお春死なむ English text is not available in this practice contest. Nathan O. Davis は集積回路コヌスの孊生である Nathan は足りない単䜍を補充するために日本文化に関する授業を履修しおいる今日の課題は詩の䜜成である Nathan は勉匷䞍足で日本語が䞍埗手なためプログラムに詩を自動生成させようず考えた手始めに圌は日本語の単語の接続蟞曞を入手した あずは単語の接続にしたがっおランダムな文章を生成するだけである しかしながらランダムに生成された党おの文字列が詩ずしお認められるわけではない 詩にはいく぀かの季語のうち1぀が䞀床だけ珟れおいなければならないある季語が2回以䞊出珟するこずや2皮類以䞊の季語が1回ず぀出珟するこずは蚱されない たた季語は単語の接続の境界をたたいで出珟しおもよい あなたの仕事は入力で䞎えられた単語の接続蟞曞ず季語のリストから指定された長さの詩が䜕通りに䜜られるかを求めるプログラムを䜜成するこずである 違う単語を繋げお詩ずなる同じ文字列が埗られた堎合それらは重耇しお数え䞊げるものずする答えは非垞に倧きくなりうるので 1,000,000,007 で割った䜙りを出力せよ Input 入力は耇数のテストケヌスを含んでいる1぀のテストケヌスは以䞋の圢匏で䞎えられる N M K from 1 to 1 from 2 to 2 : from N to N seasonword 1 seasonword 2 : seasonword K 入力の最初の行には3぀の敎数 N (1 ≀ N ≀ 250), M (1 ≀ M ≀ 500), K (1 ≀ K ≀ 30) が含たれそれぞれ単語の接続蟞曞の倧きさ䜜成すべき詩の長さ季語の数を衚す 続く N 行は単語の接続蟞曞の情報を衚す 各行は2぀の文字列 from i , to i を含み単語 from i の埌に続けお単語 to i が出珟しおもよいずいうこずを衚す to i の埌に続けお from i が出珟しおもよいずいうこずを衚すものではないこずに泚意せよたた from i で終わるような他の文字列の埌に続けお to i が出珟しおもよいずいうこずを衚すものでもない詩は接続蟞曞に含たれるどの単語から始めおもよい 続く K 行は1぀の文字列 seasonword i からなりそれぞれ季語を衚す 入力䞭に珟れる文字列は党お小文字のアルファベットからなりその長さは 1 以䞊 20 以䞋である 接続蟞曞の各項目および季語は互いに異なる すなわち i ≠ j に察しお from i ≠ from j たたは to i ≠ to j が成り立぀ 同様に i ≠ j に察しお seasonword i ≠ seasonword j が成り立぀ 入力の末尟には入力の終了を衚す 3 ぀の 0 がある Output 生成される異なる詩の数を 1,000,000,007 で割った䜙りを1行に出力せよ 先に蚀及したように違う単語を繋げお詩ずなる同じ文字列が埗られた堎合それらは重耇しお数え䞊げるものずする 厳密に蚀えば2぀の詩 s , t がありそれぞれ単語の列 [ a 1 , a 2 , ..., a n ], [ b 1 , b 2 , ..., b m ] を順に連結しお埗られたものであるずき n = m か぀すべおの 1 ≀ i ≀ n に察しお a i = b i であるずきたたそのずきに限っお2぀の詩 s , t は同䞀の詩ずみなされる Sample Input 4 64 2 negawakuha hananoshitanite hananoshitanite harushinan harushinan sonokisaragino sonokisaragino mochizukinokoro sakura hana 2 15 2 naha naha naha gachoon sakura hana 3 7 2 asakur a a sakura asa kura sakura hana 9 100 2 a a a h a n h a h h h n n a n h n n sakura hana 4 2 2 a a a b b a b b ab b 4 7 4 i cpc mi cp ac mi cp c ac wa tle re 0 0 0 Output for the Sample Input 1 1 3 715991824 1 1
36,210
Score : 200 points Problem Statement There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls. Constraints 1≩N≩1000 2≩K≩1000 The correct answer is at most 2^{31}-1 . Input The input is given from Standard Input in the following format: N K Output Print the number of the possible ways to paint the balls. Sample Input 1 2 2 Sample Output 1 2 We will denote the colors by 0 and 1 . There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1 , or paint the left in color 1 and the right in color 0 . Sample Input 2 1 10 Sample Output 2 10 Since there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten.
36,211
Score : 1000 points Problem Statement There are 3^N people dancing in circle. We denote with 0,1,\dots, 3^{N}-1 the positions in the circle, starting from an arbitrary position and going around clockwise. Initially each position in the circle is occupied by one person. The people are going to dance on two kinds of songs: salsa and rumba. When a salsa is played, the person in position i goes to position j , where j is the number obtained replacing all digits 1 with 2 and all digits 2 with 1 when reading i in base 3 (e.g., the person in position 46 goes to position 65 ). When a rumba is played, the person in position i moves to position i+1 (with the identification 3^N = 0 ). You are given a string T=T_1T_2\cdots T_{|T|} such that T_i= S if the i -th song is a salsa and T_i= R if it is a rumba. After all the songs have been played, the person that initially was in position i is in position P_i . Compute the array P_0,P_1,\dots, P_{3^N-1} . Constraints 1 \le N \le 12 1 \le |T| \le 200,000 T contains only the characters S and R . Input Input is given from Standard Input in the following format: N T Output You should print on Standard Output: P_0 P_1 \cdots P_{3^N-1} Sample Input 1 1 SRS Sample Output 1 2 0 1 Before any song is played, the positions are: 0 , 1 , 2 . When we say "person i ", we mean "the person that was initially in position i ". After the first salsa, the positions are: 0 , 2 , 1 . After the rumba, the positions are: 1 , 0 , 2 (so, person 0 is in position 1 , person 1 is in position 0 and person 2 is in position 2 ). After the second salsa, the positions are 2 , 0 , 1 (so, person 0 is in position 2 , person 1 is in position 0 and person 2 is in position 1 ). Sample Input 2 2 RRSRSSSSR Sample Output 2 3 8 1 0 5 7 6 2 4 Sample Input 3 3 SRSRRSRRRSRRRR Sample Output 3 23 9 22 8 3 7 20 24 19 5 18 4 17 12 16 2 6 1 14 0 13 26 21 25 11 15 10
36,212
K: トヌナメント 問題文 京郜倧孊クスノキ前にお、$2$ 人甚察戊ゲヌムのトヌナメントが行われようずしおいたす。 このトヌナメントの参加者は $2^N$ 人いお、 $1$ から $2^N$ たでの番号が぀いおいたす。 参加者のうちの $2$ 人が戊った時の勝敗は、$0$ ず $1$ からなる長さ $2^N-1$ の文字列 $S$ によっお衚されたす。 人 $x$ ず人 $y$ $(1 \le x < y \le 2^N)$ が戊ったずき、 $S_{y-x} = 0$ のずき、人 $x$ が勝ち、 $S_{y-x} = 1$ のずき、人 $y$ が勝぀ こずが分かっおいたす。 トヌナメントは参加者が䞀列に䞊ぶこずで始たり、以䞋の通りに進行したす。 列の先頭から $2$ 人ず぀ペアを䜜る。すべおのペアに぀いお、ペア内の $2$ 人が戊う。 1 の察戊で勝った人は列に残り、負けた人は列から抜ける。 残っおいる人が $2$ 人以䞊いるずきは、列を詰めお 1 に戻る。 残っおいる人が $1$ 人ずなったら、その人が優勝者ずなる。 いた、参加者は初期状態ずしお、先頭から $i$ 番目 $(1 \le i \le 2^N)$ が人 $P_i$ ずなるように䞊んでいたす。 $0 \le k \le 2^N-1$ を満たすすべおの敎数 $k$ に぀いお、以䞋の問題を解いおください。 初期状態から先頭 $k$ 人が、その順番を倉えずに列の末尟に移動する。 ぀たり、移動埌の列における参加者の番号を先頭から挙げおいくず、 $P_{k+1}, P_{k+2}, ..., P_{2^N}, P_1, P_2, ..., P_k$ ずなる。 移動埌の列からトヌナメントを始めたずきの、優勝者の番号を求めよ。 制玄 $1 \leq N \leq 18$ $N$ は敎数である。 $S$ は $0$ ず $1$ からなる長さ $2^N-1$ の文字列である。 $P$ は $1$ から $2^N$ たでの敎数を䞊べ替えた順列である。 入力 入力は以䞋の圢匏で暙準入力から䞎えられる。 $N$ $S_1S_2 \ldots S_{2^N-1}$ $P_1$ $P_2$ $\ldots$ $P_{2^N}$ 出力 $2^N$ 行出力せよ。 $i$ 行目 $(1 \le i \le 2^N)$ には、$k = i-1$ ずしたずきの䞊蚘の問題の答えを出力せよ。 入力䟋1 2 100 1 4 2 3 出力䟋1 1 2 1 2 䟋えば $k = 2$ ずしたずき、移動埌の列における参加者の番号を先頭から挙げおいくず、 $2, 3, 1, 4$ ずなりたす。 人 $2$ ず 人 $3$ が戊うず、 $S_1 = 1$ より人 $3$ が勝ちたす。 人 $1$ ず 人 $4$ が戊うず、 $S_3 = 0$ より人 $1$ が勝ちたす。 人 $3$ ず 人 $1$ が戊うず、 $S_2 = 0$ より人 $1$ が勝ちたす。 したがっお、 $k = 2$ の堎合の優勝者は、人 $1$ ずなりたす。 入力䟋2 4 101011100101000 8 15 2 9 12 5 1 7 14 10 11 3 4 6 16 13 出力䟋2 16 1 16 2 16 12 10 14 16 1 16 2 16 12 10 14 入力䟋3 1 0 1 2 出力䟋3 1 1
36,213
Score : 200 points Problem Statement There are N gems. The value of the i -th gem is V_i . You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i -th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y . Constraints All values in input are integers. 1 \leq N \leq 20 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y . Sample Input 1 3 10 2 5 6 3 4 Sample Output 1 5 If we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10 . We have X-Y = 5 here, which is the maximum possible value. Sample Input 2 4 13 21 6 19 11 30 6 15 Sample Output 2 6 Sample Input 3 1 1 50 Sample Output 3 0
36,214
Score : 900 points Problem Statement Takahashi has decided to give a string to his mother. The value of a string T is the length of the longest common subsequence of T and T' , where T' is the string obtained by reversing T . That is, the value is the longest length of the following two strings that are equal: a subsequence of T (possibly non-contiguous), and a subsequence of T' (possibly non-contiguous). Takahashi has a string S . He wants to give her mother a string of the highest possible value, so he would like to change at most K characters in S to any other characters in order to obtain a string of the highest possible value. Find the highest possible value achievable. Constraints 1 \leq |S| \leq 300 0 \leq K \leq |S| S consists of lowercase English letters. K is an integer. Input Input is given from Standard Input in the following format: S K Output Print the highest possible value achievable. Sample Input 1 abcabcabc 1 Sample Output 1 7 Changing the first character to c results in cbcabcabc . Let this tring be T , then one longest common subsequence of T and T' is cbabcbc , whose length is 7 . Sample Input 2 atcodergrandcontest 3 Sample Output 2 15
36,215
On-Screen Keyboard You are to input a string with an OSK (on-screen keyboard). A remote control with five buttons, four arrows and an OK (Fig. B-1), is used for the OSK. Find the minimum number of button presses required to input a given string with the given OSK. Fig. B-1 Remote control Fig. B-2 An on-screen keyboard Character to input Move of highlighted cells Button presses I →,→,→,→,→,→,→,→,OK (9 presses) C ←,←,←,←,←,←,OK (7 presses) P ↓,→,→,→,→,OK (6 presses) C ↑,←,←,←,←,OK (6 presses) Fig. B-3 The minimum steps to input “ ICPC ” with the OSK in Fig. B-2 The OSK has cells arranged in a grid, each of which has a character in it or is empty. No two of the cells have the same character. One of the cells of the OSK is highlighted, and pressing the OK button will input the character in that cell, if the cell is not empty. Initially, the cell at the top-left corner is highlighted. Pressing one of the arrow buttons will change the highlighted cell to one of the adjacent cells in the direction of the arrow. When the highlighted cell is on an edge of the OSK, pushing the arrow button with the direction to go out of the edge will have no effect. For example, using the OSK with its arrangement shown in Fig. B-2, a string “ ICPC ” can be input with 28 button presses as shown in Fig. B-3, which is the minimum number of presses. Characters in cells of the OSKs are any of a lowercase letter (‘ a ’, ‘ b ’, ..., ‘ z ’), an uppercase letter (‘ A ’, ‘ B ’, ..., ‘ Z ’), a digit (‘ 0 ’, ‘ 1 ’, ..., ‘ 9 ’), a comma (‘ , ’), a hyphen (‘ - ’), a dot (‘ . ’), a slash (‘ / ’), a colon (‘ : ’), a semicolon (‘ ; ’), or an at sign (‘ @ ’). Input The input consists of at most 100 datasets, each in the following format. h w r 1 ... r h s The two integers h and w in the first line are the height and the width of the OSK, respectively. They are separated by a space, and satisfy 1 ≀ h ≀ 50 and 1 ≀ w ≀ 50. Each of the next h lines gives a row of the OSK. The i -th row, r i is a string of length w . The characters in the string corresponds to the characters in the cells of the i -th row of the OSK or an underscore (‘ _ ’) indicating an empty cell, from left to right. The given OSK satisfies the conditions stated above. The next line is a string s to be input. Its length is between 1 and 1000, inclusive. All the characters in s appear in the given OSK. Note that s does not contain underscores. The end of the input is indicated by a line containing two zeros. Output For each dataset, output a single line containing an integer indicating the minimum number of button presses required to input the given string with the given OSK. Sample Input 3 9 ABCDEFGHI JKLMNOPQR STUVWXYZ_ ICPC 5 11 ___________ ____A______ ________M__ ___________ _C_________ ACM 4 21 1_2_3_4_5_6_7_8_9_0_- QqWwEeRrTtYyUuIiOoPp@ AaSsDdFfGgHhJjKkLl;_: ZzXxCcVvBbNnMm,_._/__ ICPC2019,AsiaYokohamaRegional,QualificationRound 0 0 Output for the Sample Input 28 23 493
36,216
Score : 100 points Problem Statement You are given positive integers A and B . If A is a divisor of B , print A + B ; otherwise, print B - A . Constraints All values in input are integers. 1 \leq A \leq B \leq 20 Input Input is given from Standard Input in the following format: A B Output If A is a divisor of B , print A + B ; otherwise, print B - A . Sample Input 1 4 12 Sample Output 1 16 As 4 is a divisor of 12 , 4 + 12 = 16 should be printed. Sample Input 2 8 20 Sample Output 2 12 Sample Input 3 1 1 Sample Output 3 2 1 is a divisor of 1 .
36,217
問題名 Audition アむドル---それは女の子達の氞遠の憧れ。しかし、頂点に立おるのはほんの䞀握り。そんなサバむバルな䞖界に、あなたはアむドルプロデュヌサヌずしお足を螏み入れるこずになりたした。そしお、今日はあなたの担圓アむドルを連れお倧事なオヌディションに挑むこずになりたした。 オヌディションの決め手になるのはビゞュアル、ダンス、ボヌカルの 3 芁玠です。オヌディション䞭には m 回のアピヌルタむムがあり、 1 回のアピヌルタむムごずに各アむドルはビゞュアルアピヌル、ダンスアピヌル、ボヌカルアピヌルのいずれかを行うこずが出来たす。ビゞュアルアピヌルを行うずそのアむドルのビゞュアルポむントは圌女の持っおるビゞュアル倀だけ、ダンスアピヌルを行うずダンスポむントは圌女の持っおるダンス倀だけ、ボヌカルアピヌルを行うずボヌカルポむントは圌女の持っおるボヌカル倀だけ䞊昇したす。 m 回のアピヌルが終了した埌、 N 人のアむドルのうちビゞュアルポむントの高いほうから 3 人は 5 オヌディションポむント、ダンスポむントの高いほうから 3 人は 3 オヌディションポむント、ボヌカルポむントの高いほうから 3 人は 2 オヌディションポむントを獲埗したす。䞀方、ビゞュアルポむントが最䞋䜍だずオヌディションポむントは 1 点枛点、ダンスポむントが最䞋䜍だずオヌディションポむントは 1 点枛点、ボヌカルポむントが最䞋䜍だずオヌディションポむントは 1 点枛点ずなりたす。オヌディションポむントが1以䞋でもそこから 1 点枛点。 オヌディションの始めに、各アむドルのビゞュアルポむント、ダンスポむント、ボヌカルポむントはそれぞれ 0 です。あなたはアむドル 1 のプロデュヌサヌで、アピヌルタむムごずにどのアピヌルを行うか指瀺するこずが出来たす。アむドル 1 以倖のアむドルはアピヌルタむムごずにランダムに等確率にどれかのアピヌルを行いたす぀たりそれぞれ 3 分の 1 の確率で行われる。アむドル 1 のビゞュアル、ダンス、ボヌカルのポむントが他のアむドルず等しい堎合、アむドル 1 は垞に䞋䜍ずしたす。アむドル 1 の獲埗するオヌディションポむントの期埅倀が最倧になるように指瀺したずきの期埅倀を求めお䞋さい。アむドルの運呜は、あなたの指瀺にかかっおいたす ちなみに、指瀺はオヌディションが始たる前に党お行っお、その埌オヌディション䞭の指瀺の倉曎は出来ないものずしたす。぀たり、他のアむドルが、オヌディションが始たっおからのアピヌルでどのアピヌルをしかたを芋おから、その堎合においおの期埅倀が最倧ずなるような指瀺を出す、ずいうこずは出来ないものずしたす。 Input 入力は以䞋の圢で䞎えられたす。 n m vi 1 da 1 vo 1 vi 2 da 2 vo 2 ... vi n da n vo n 1行目にはオヌディションに出堎するアむドルの数 n ( 4 ≀ n ≀ 2000 ) ず、このオヌディションにおけるアピヌルタむムの数 m ( 1 ≀ m ≀ 2000 ) が曞いおありたす。次の n 行にはそれぞれアむドルiのビゞュアル倀 vi i 、ダンス倀 da i 、ボヌカル倀 vo i ( 1 ≀ vi i , da i , vo i ≀ 10,000 )が曞いおありたす。 Output アむドル 1 の獲埗するオヌディションポむントの期埅倀の最倧倀を 1 行で出力しなさい。 Sample Input 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 Output for the Sample Input 1 2.777777777778 どのアピヌルを行っおも、そのゞャンルで 3 䜍以内に入れる確率は等しいですが、 3 䜍以内に入った時に貰えるオヌディションポむントが最も倚いビゞュアルのアピヌルを行うのがもっずも期埅倀が良くなりたす。 Sample Input 2 4 10 1 1 1 10 10 10 10 10 10 10 10 10 Output for the Sample Input 2 -2.335340954780 非垞に厳しいオヌディションずなるでしょう。 Sample Input 3 9 9 13 5 19 19 21 37 15 1 7 7 11 15 21 23 25 33 29 19 13 19 11 21 5 15 7 13 1 Output for the Sample Input 3 4.678837855075
36,218
Score : 300 points Problem Statement You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i -th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i . An edge whose removal disconnects the graph is called a bridge . Find the number of the edges that are bridges among the M edges. Notes A self-loop is an edge i such that a_i=b_i (1 \leq i \leq M) . Double edges are a pair of edges i,j such that a_i=a_j and b_i=b_j (1 \leq i<j \leq M) . An undirected graph is said to be connected when there exists a path between every pair of vertices. Constraints 2 \leq N \leq 50 N-1 \leq M \leq min(N(N−1)⁄2,50) 1 \leq a_i<b_i \leq N The given graph does not contain self-loops and double edges. The given graph is connected. Input Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M Output Print the number of the edges that are bridges among the M edges. Sample Input 1 7 7 1 3 2 7 3 4 4 5 4 6 5 6 6 7 Sample Output 1 4 The figure below shows the given graph: The edges shown in red are bridges. There are four of them. Sample Input 2 3 3 1 2 1 3 2 3 Sample Output 2 0 It is possible that there is no bridge. Sample Input 3 6 5 1 2 2 3 3 4 4 5 5 6 Sample Output 3 5 It is possible that every edge is a bridge.
36,219
Score : 100 points Problem Statement There are two rectangles. The lengths of the vertical sides of the first rectangle are A , and the lengths of the horizontal sides of the first rectangle are B . The lengths of the vertical sides of the second rectangle are C , and the lengths of the horizontal sides of the second rectangle are D . Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area. Constraints All input values are integers. 1≀A≀10^4 1≀B≀10^4 1≀C≀10^4 1≀D≀10^4 Input The input is given from Standard Input in the following format: A B C D Output Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area. Sample Input 1 3 5 2 7 Sample Output 1 15 The first rectangle has an area of 3×5=15 , and the second rectangle has an area of 2×7=14 . Thus, the output should be 15 , the larger area. Sample Input 2 100 600 200 300 Sample Output 2 60000
36,220
Score : 600 points Problem Statement Given are a sequence of N integers A_1 , A_2 , \ldots , A_N and a positive integer S . For a pair of integers (L, R) such that 1\leq L \leq R \leq N , let us define f(L, R) as follows: f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S . Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N . Since this sum can be enormous, print it modulo 998244353 . Constraints All values in input are integers. 1 \leq N \leq 3000 1 \leq S \leq 3000 1 \leq A_i \leq 3000 Input Input is given from Standard Input in the following format: N S A_1 A_2 ... A_N Output Print the sum of f(L, R) , modulo 998244353 . Sample Input 1 3 4 2 2 4 Sample Output 1 5 The value of f(L, R) for each pair is as follows, for a total of 5 . f(1,1) = 0 f(1,2) = 1 (for the sequence (1, 2) ) f(1,3) = 2 (for (1, 2) and (3) ) f(2,2) = 0 f(2,3) = 1 (for (3) ) f(3,3) = 1 (for (3) ) Sample Input 2 5 8 9 9 9 9 9 Sample Output 2 0 Sample Input 3 10 10 3 1 4 1 5 9 2 6 5 3 Sample Output 3 152
36,221
Square Carpets Mr. Frugal bought a new house. He feels deeply in love with his new house because it has a comfortable living room in which he can put himself completely at ease. He thinks his new house is a really good buy. But, to his disappointment, the floor of its living room has some scratches on it. The floor has a rectangle shape, covered with square panels. He wants to replace all the scratched panels with flawless panels, but he cannot afford to do so. Then, he decides to cover all the scratched panels with carpets. The features of the carpets he can use are as follows. Carpets are square-shaped. Carpets may overlap each other. Carpets cannot be folded. Different sizes of carpets are available. Lengths of sides of carpets are multiples of that of the panels. The carpets must cover all the scratched panels, but must not cover any of the flawless ones. For example, if the scratched panels are as shown in Figure 1, at least 6 carpets are needed. Figure 1: Example Covering As carpets cost the same irrespective of their sizes, Mr. Frugal would like to use as few number of carpets as possible. Your job is to write a program which tells the minimum number of the carpets to cover all the scratched panels. Input The input consists of multiple data sets. As in the following, the end of the input is indicated by a line containing two zeros. DataSet 1 DataSet 2 ... DataSet n 0 0 Each data set ( DataSet i ) represents the state of a floor. The format of a data set is as follows. W H P 11 P 12 P 13 ... P 1 W P 21 P 22 P 23 ... P 2 W ... P H 1 P H 2 P H 3 ... P HW The positive integers W and H are the numbers of panels on the living room in the x- and y- direction, respectively. The values of W and H are no more than 10. The integer P yx represents the state of the panel. The value of P yx means, 0 : flawless panel (must not be covered), 1 : scratched panel (must be covered). Output For each data set, your program should output a line containing one integer which represents the minimum number of the carpets to cover all of the scratched panels. Sample Input 4 3 0 1 1 1 1 1 1 1 1 1 1 1 8 5 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 8 8 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 10 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 Output for the Sample Input 2 6 14 29
36,222
Minimum Spanning Tree Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = ( V , E ). Input |V| |E| s 0 t 0 w 0 s 1 t 1 w 1 : s |E|-1 t |E|-1 w |E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V| -1 respectively. s i and t i represent source and target verticess of i -th edge (undirected) and w i represents the weight of the i -th edge. Output Print the sum of the weights of the Minimum Spanning Tree. Constraints 1 ≀ |V| ≀ 10,000 0 ≀ |E| ≀ 100,000 0 ≀ w i ≀ 10,000 The graph is connected There are no parallel edges There are no self-loops Sample Input 1 4 6 0 1 2 1 2 1 2 3 1 3 0 1 0 2 3 1 3 5 Sample Output 1 3 Sample Input 2 6 9 0 1 1 0 2 3 1 2 1 1 3 7 2 4 1 1 4 3 3 4 1 3 5 1 4 5 6 Sample Output 2 5
36,223
Dungeon Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W × H squares. Each square is identified with its column and row number, thus the square located in the x -th column and the y -th row is represented as ( x , y ). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is ( W -1, H -1). Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. One-square movement in the up, down, left, or right direction within the board Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBom’s behavior and it can move even to a square where an enemy character is located. Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. Input The input is given in the following format. W H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the number of squares in the horizontal direction W (1 ≀ W ≀ 10 5 ), in the vertical direction H (1 ≀ H ≀ 10 5 ), and the number of enemy characters N (1 ≀ N ≀ 10 5 ). Each of the subsequent N lines provides location information of the i -th enemy, column x_i (0 ≀ x_i ≀ W -1) and row y_i (0 ≀ y_i ≀ H -1). The number of enemy characters in a specific square can be either one or zero. Output Output the minimum Cost in a line. Sample Input 1 5 4 4 0 3 1 1 2 2 2 3 Sample Output 1 2 Sample Input 2 6 6 5 2 1 5 2 3 3 1 4 1 5 Sample Output 2 4 Sample Input 3 8 8 4 6 0 7 0 0 6 0 7 Sample Output 3 0
36,224
合蚈時間 (Total Time) 問題 倪郎君は 3 カ所の店を蚪ねるこずを日課にしおいる家を出発し決たった順番で 3 カ所の店を回った埌家に垰るずきどきストップりォッチを䜿っお各区間を移動するのに䜕秒かかったかを蚈りその秒数を蚘録する ある日の蚈枬結果が䞎えられたずきこの日の移動時間の合蚈が䜕分䜕秒かを求めるプログラムを䜜成せよ 入力 入力は 4 行からなり 1 行に 1 ぀ず぀正の敎数が曞かれおいる 1 行目の敎数は家から 1 ぀目の店たでの移動時間を衚す秒数である 2 行目の敎数は 1 ぀目の店から 2 ぀目の店たでの移動時間を衚す秒数である 3 行目の敎数は 2 ぀目の店から 3 ぀目の店たでの移動時間を衚す秒数である 4 行目の敎数は 3 ぀目の店から家たでの移動時間を衚す秒数であるただし䞎えられる入力デヌタにおいおは合蚈移動時間は 1 分 0 秒以䞊で 59 分 59 秒以䞋であるこずが保蚌されおいる 出力 出力は 2 行からなるx 分 y 秒 (1 ≀ x ≀ 59 , 0 ≀ y ≀ 59 )のずき 1行目に x を2行目に y を出力せよ 入出力䟋 入力䟋 1 31 34 7 151 出力䟋 1 3 43 入力䟋 2 316 430 643 1253 出力䟋 2 44 2 入力䟋 3 5 10 15 30 出力䟋 3 1 0 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,225
What day is today? Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29. Input The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset consists of two integers m and d separated by a single space in a line. These integers respectively represent the month and the day. The number of datasets is less than or equal to 50. Output For each dataset, print the day (please see the following words) in a line. Monday Tuesday Wednesday Thursday Friday Saturday Sunday Sample Input 1 1 2 29 0 0 Output for the Sample Input Thursday Sunday
36,226
Problem H: Robot Communication In the year 21xx, human beings are proliferating across the galaxy. Since the end of the last century, thousands of pioneer spaceships have been launched in order to discover new habitation planets. The Presitener is one of those spaceships, heading toward the Andromeda galaxy. After a long, long cruise in the hyperspace, the crew have finally found a very hopeful candidate planet. The next thing to do is to investigate the planet whether it is really suitable for a new resident or not. For that purpose, the ship is taking some unattended landers. The captain Juclean Dripac decided to drop them to the planet and collect data about it. But unfortunately, these robots are a bit old and not so clever that the operator has to program what to do on the planet beforehand of the landing. Many staffs including you are called for making this important plan. The most complicated phase in the mission is to gather and integrate all the data collected independently by many robots. The robots need to establish all-to-all communication channels to exchange the data, once during the mission. That is, all the robots activate their communication channels all together at the predetermined time, and they exchange the data with each other at that time. They use wireless channels to communicate with each other, so the distance between robots does not limit the connectivity. But the farther two robots goes, the more power they have to use for communication. Due to the limitation of the battery capacity, you want to save the transmission power as much as possible. For a good thing, communication units of the robots also have the routing functionality, each robot only has to talk with the nearest robot. Suppose a graph whose vertices represent robots and edges represent communication channels established between them. If the graph is connected, all-to-all communication can be established. Your task is to write the program to calculate the minimum total transmission power required for all- to-all communication among the robots. Each robot moves linearly on the planet surface. Each pair of robots which communicate each other must occupy one channel, but you can assume enough number of channels are available. The transmission power required for two robots is proportional to the distance between them, so the cost here is exactly the sum of the distances between each pair of robots which establish a communication channel. You may also regard the planet surface as a two-dimensional surface, as it is huge enough. The time required for communicating data among robots are also negligible. Input The input contains multiple datasets. Each dataset has the format below. N T x 1 y 1 vx 1 vy 1 ... x N y N vx N vy N The first line of each dataset contains two integers; N is the number of robots used for gathering data (2 ≀ N ≀ 16), and T is the time limit of the mission (1 ≀ T < 1000). Each of the following N lines describes the motion of a robot. ( x i , y i ) and ( vx i , vy i ) are the initial landing position and the velocity of the i -th robot, respectively (| x i |, | y i | < 100000, | vx i |, | vy i | < 1000). The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, output in a line the minimum communication cost required for all-to-all communication. Your program may output an arbitrary number of digits after the decimal point. The absolute error should be less than or equal to 0.001. Sample Input 4 2 2 0 0 1 0 4 1 0 4 6 0 -1 6 2 -1 0 4 6 2 0 0 1 0 4 1 0 4 6 0 -1 6 2 -1 0 0 0 Output for the Sample Input 6.00000000 4.24264069
36,227
Problem C: Mysterious Operator ケヌ氏がい぀ものように某SNSを閲芧しおいるず、 「解ける人はIQ150以䞊ある」ずいう問題がタむムラむンに流れおきた。 ケヌ氏はIQが150以䞊あるので、芋るたでもなくその問題を䞀瞬で解いおしたった。 圌にしおみれば、このような問題なぞに頭を働かせる必芁は無い。 コンピュヌタに任せれば充分なのである。 問題 問題には以䞋のような謎の数匏が曞かれおいた。 \( 5 + 3 = 28 \) \( 9 + 1 = 810 \) \(8 + 6 = 214 \) \( 5 + 4 = 19 \) \( 2 + 2 = 4 \) \( 15 + 8 = 723 \) \( 7 + 9 = -216 \) \( 3 + 0 = 33 \) 䞊蚘の挔算子\( + \)に぀いお考えた時、ある正敎数\( a \)に぀いお\( x \geq 0, y \geq 0 \)か぀\( x + y = a \)になるような敎数のペア\( x,y \)の個数を求めよ。 入力 正敎数\(a\)が䞀行で䞎えられる。 出力 \( a = x + y, x \geq 0, y \geq 0\)を満たすペア\((x,y)\)の個数を䞀行に出力せよ。 制玄 \( 1 \leq a \leq 10^9(= 1000000000) \) 入出力䟋 入力1 19 出力1 1 \( 5 + 4 \)の1通りである。 入力2 22 出力2 2 \( 11 + 11 \)ず、\( 2 + 0 \)の2通りが存圚する。 入力3 1 出力3 0 \( 1 + 0 = 11 , 0 + 1 = -11 \)である。\( 1 \)は生成するこずができない。 入力4 101 出力4 0 \( 1 - 0 \)は\( 101 \)ではないこずに泚意するこず。 入力5 660233276 出力5 4
36,228
Problem A: Bit String Reordering You have to reorder a given bit string as specified. The only operation allowed is swapping adjacent bit pairs. Please write a program that calculates the minimum number of swaps required. The initial bit string is simply represented by a sequence of bits, while the target is specified by a run-length code . The run-length code of a bit string is a sequence of the lengths of maximal consecutive sequences of zeros or ones in the bit string. For example, the run-length code of "011100" is "1 3 2". Note that there are two different bit strings with the same run-length code, one starting with zero and the other starting with one. The target is either of these two. In Sample Input 1, bit string "100101" should be reordered so that its run-length code is "1 3 2", which means either "100011" or "011100". At least four swaps are required to obtain "011100". On the other hand, only one swap is required to make "100011". Thus, in this example, 1 is the answer. Input The input consists of a single test case. The test case is formatted as follows. $N$ $M$ $b_1$ $b_2$ . . . $b_N$ $p_1$ $p_2$ . . . $p_M$ The first line contains two integers $N$ ($1 \leq N \leq 15$) and $M$ ($1 \leq M \leq N$). The second line specifies the initial bit string by $N$ integers. Each integer $b_i$ is either 0 or 1. The third line contains the run-length code, consisting of $M$ integers. Integers $p_1$ through $p_M$ represent the lengths of consecutive sequences of zeros or ones in the bit string, from left to right. Here, $1 \leq p_j$ for $1 \leq j \leq M$ and $\sum^{M}_{j=1} p_j = N$ hold. It is guaranteed that the initial bit string can be reordered into a bit string with its run-length code $p_1, . . . , p_M$. Output Output the minimum number of swaps required Sample Input 1 6 3 1 0 0 1 0 1 1 3 2 Sample Output 1 1 Sample Input 2 7 2 1 1 1 0 0 0 0 4 3 Sample Output 2 12 Sample Input 3 15 14 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 Sample Output 3 7 Sample Input 4 1 1 0 1 Sample Output 4 0
36,229
Score: 500 points Problem Statement Given is a permutation P of \{1, 2, \ldots, N\} . For a pair (L, R) (1 \le L \lt R \le N) , let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R . Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R} . Constraints 2 \le N \le 10^5 1 \le P_i \le N P_i \neq P_j (i \neq j) All values in input are integers. Input Input is given from Standard Input in the following format: N P_1 P_2 \ldots P_N Output Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R} . Sample Input 1 3 2 3 1 Sample Output 1 5 X_{1, 2} = 2, X_{1, 3} = 2 , and X_{2, 3} = 1 , so the sum is 2 + 2 + 1 = 5 . Sample Input 2 5 1 2 3 4 5 Sample Output 2 30 Sample Input 3 8 8 2 7 3 4 5 6 1 Sample Output 3 136
36,230
Problem C: コンパむル 東京倧孊に入孊したきたたさ君はTSG(東倧スヌパヌゲヌマヌズ)ずいうサヌクルに入った。 このサヌクルは毎幎、駒堎祭でゲヌムを展瀺しおおり、きたたさ君もゲヌムを䜜成しお展瀺するこずにした。 きたたさ君の䜜成するゲヌムは次のような、よくある萜ち物パズルゲヌムである。 暪6マス×瞊12マスの栌子状のフィヌルドがあり、各マスに぀き1個のブロックを眮くこずができる。 䞊からブロックが2぀1組で萜䞋しおくる。ブロックには赀・緑・青・黄・玫の5色の基本ブロックずお邪魔ブロックの蚈6皮類がある。プレむダヌはブロックを回転、暪移動により操䜜し、萜䞋䜍眮を倉曎するこずができる。 萜䞋しおきたブロックがフィヌルドの床やほかのブロックに衝突するず、その䜍眮にブロックが固定される。 固定されたブロックず同色のブロックが呚囲4方向にある堎合、それらは互いにくっ぀く。ただし、お邪魔ブロックは互いにくっ぀かない。 ブロックが4個以䞊くっ぀くず消滅し埗点ずなる。お邪魔ブロックの呚囲4方向に存圚する基本ブロックが消滅するず、そのお邪魔ブロックも䞀緒に消滅する。ブロックの消滅は、党おのブロックの萜䞋が終了したタむミングで同時に起こる。 ブロックの消滅により、その䞊にあったブロックが萜䞋する。このブロックの萜䞋はプレむダヌが操䜜できない。このずき再びブロックが4個以䞊くっ぀くず消滅し、連鎖が起きる。ただし、耇数色を同時に消した堎合でも、1連鎖扱いずなる。 きたたさ君はこのゲヌムの倧郚分のプログラムを曞き終えたが、どうしおもブロックがくっ぀いお消滅したずきの凊理を曞くこずが出来なかった。そこでサヌクルの友人であるあなたにその郚分のプログラムを曞いおもらうこずにした。 Input 入力は12行からなる。 入力の i 行目は長さ6の文字列からなり、その j 文字目はフィヌルドの䞊から i 行目、巊から j 列目のマスの状態を衚しおいる。 マスの状態を衚す文字は以䞋の7぀のうちのいずれかである。 文字 皮類 R èµ€ G 緑 B 青 Y 黄 P 玫 O お邪魔 . 空きマス たた、入力に含たれる党おのブロックは床の䞊か他のブロックの䞊に乗っおいる。 Output 入力の状態から、ルヌルに埓っおブロックを消しおいった時の連鎖数を蚈算し、䞀行で出力せよ。 ブロックが䞀぀も消えない堎合は0ず出力せよ。 Notes on Test Cases 䞊蚘入力圢匏で耇数のデヌタセットが䞎えられたす。 入力の1行目にデヌタセットの数Tが䞎えられたす。 各デヌタセットに察しお䞊蚘出力圢匏で出力を行うプログラムを䜜成しお䞋さい。 Sample Input 3 ...... ...... ...... ...... ...... ...... ...... ...... .RGB.. RGOP.. RGBPB. RGBPP. GBRGYP GBRRYP BGGRBB BPRGYY GGPRRY BYPPRB YGGGPB GYYYPR YRBRBR YBRBRB BRBRBR BRBRBR ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ..OO.. ..OO.. Output for Sample Input 3 18 0
36,231
B: Cram School Schedule / 塟の時間割 物語 あなたは塟の経営者であるあなたの塟は個人授業制で1人の生埒ず1人の先生で授業を行うこの塟の先生は非垞に優秀で科目にかかわらずすべおの授業を行うこずができるたた先生ず生埒は非垞にタフなので出垭できる授業には他の授業の出垭状況にかかわらずすべお出垭するこずが可胜である䟋えば同じ時間垯の授業に出垭できる2人の生埒ず4人の先生がいる堎合はその時間垯に2぀の授業を行える あなたは来月の授業予定を立おなくおはいけないが先生ず生埒の人数が倚いため予定を立おるのが非垞に倧倉であるたたあなたはできるだけ倚くの授業を行いたいず考えおいるそのためあなたは行える最倧の授業数を求めるプログラムを䜜るこずにした 問題 先生の人数ず生埒の人数それぞれの先生ず生埒の予定がない時間垯授業を行える時間垯が䞎えられるそれぞれの先生たたは生埒に぀いお予定がない時間垯が授業を行える時間垯を完党に被芆しおいるずきその先生たたは生埒はその授業に出垭できるそれぞれの授業を行える時間垯では出垭できる先生ず生埒からなるペアを耇数䜜り䜜ったペアの数だけの授業を同時に行うこずができるこのずきに行える最倧の授業数を求めよ 入力圢匏 入力デヌタの圢匏は以䞋のように䞎えられる 授業が行える時間垯の情報 n 先生 1 の時間垯の情報 ... 先生 n の時間垯の情報 m 生埒 1 の時間垯の情報 ... 生埒 m の時間垯の情報 最初の1行には授業を行える時間垯の情報が䞎えられる 続く1行には先生の人数 n ( 1 ≀ n ≀ 100 ) が䞎えられる続く n 行の i 行目には i 番目の先生の予定がない時間垯の情報が䞎えられる 続く1行には生埒の人数 m ( 1 ≀ m ≀ 100 ) が䞎えられる続く m 行の i 行目には i 番目の生埒の予定がない時間垯の情報が䞎えられる 各々の時間垯の情報は次の圢匏で䞎えられる k ah_1 : am_1 - bh_1 : bm_1 . . . ah_k : am_k - bh_k : bm_k はじめに時間垯の数 k ( 1 ≀ k ≀ 100 ) が䞎えられ空癜区切りで k 個の時間垯が䞎えられる i 番目の時間垯は ah_i : am_i - bh_i : bm_i の圢匏で䞎えられ ah_i : am_i が開始時刻を衚し bh_i : bm_i が終了時刻を衚す ah_i , am_i , bh_i , bm_i はそれぞれ0詰め2桁で 0 ≀ ah_i, bh_i ≀ 23 , 0 ≀ am_i, bm_i ≀ 59 を満たす敎数である 䞎えられるすべおの時間垯に぀いお開始時刻は終了時刻より真に早いたたそれぞれの時間垯の情報においお時間垯は早い時刻順に䞊んでおりどの終了時刻も1぀埌の時間垯の開始時刻より真に早い 出力圢匏 行える授業の最倧数を1行で出力せよ 入力䟋1 2 10:00-11:30 12:00-13:00 2 1 10:00-15:00 2 09:00-12:00 18:10-18:55 2 2 10:00-13:00 15:30-16:40 3 06:00-08:00 12:00-13:10 15:00-17:00 出力䟋1 2 1぀目の時間垯ず2぀目の時間垯で1぀ず぀授業を行うこずで2回の授業を行うこずができる 入力䟋2 2 07:00-08:30 10:00-12:00 3 3 08:30-09:00 11:05-15:05 23:10-23:55 2 09:00-12:00 17:45-18:55 1 08:00-10:00 2 2 07:20-11:00 12:30-17:05 3 07:48-08:51 11:22-16:15 17:02-17:59 出力䟋2 0 予定がない時間垯で07:00からの授業に間に合う先生ず生埒のペアが存圚しないので1぀目の時間垯は授業を行うこずができないたた2぀目の時間垯は2人目の先生が出垭できるが生埒は誰も出垭できないよっお2぀目の時間垯も授業を行うこずができないしたがっお行える最倧の授業数は0である
36,232
Problem H: Bug Hunt In this problem, we consider a simple programming language that has only declarations of one- dimensional integer arrays and assignment statements. The problem is to find a bug in the given program. The syntax of this language is given in BNF as follows: where < new line > denotes a new line character (LF). Characters used in a program are alphabetical letters, decimal digits, = , [ , ] and new line characters. No other characters appear in a program. A declaration declares an array and specifies its length. Valid indices of an array of length n are integers between 0 and n - 1, inclusive. Note that the array names are case sensitive, i.e. array a and array A are different arrays. The initial value of each element in the declared array is undefined. For example, array a of length 10 and array b of length 5 are declared respectively as follows. a[10] b[5] An expression evaluates to a non-negative integer. A < number > is interpreted as a decimal integer. An < array_name > [< expression >] evaluates to the value of the < expression > -th element of the array. An assignment assigns the value denoted by the right hand side to the array element specified by the left hand side. Examples of assignments are as follows. a[0]=3 a[1]=0 a[2]=a[a[1]] a[a[0]]=a[1] A program is executed from the first line, line by line. You can assume that an array is declared once and only once before any of its element is assigned or referred to. Given a program, you are requested to find the following bugs. An index of an array is invalid. An array element that has not been assigned before is referred to in an assignment as an index of array or as the value to be assigned. You can assume that other bugs, such as syntax errors, do not appear. You can also assume that integers represented by < number > s are between 0 and 2 31 - 1 (= 2147483647), inclusive. Input The input consists of multiple datasets followed by a line which contains only a single ' . ' (period). Each dataset consists of a program also followed by a line which contains only a single ' . ' (period). A program does not exceed 1000 lines. Any line does not exceed 80 characters excluding a new line character. Output For each program in the input, you should answer the line number of the assignment in which the first bug appears. The line numbers start with 1 for each program. If the program does not have a bug, you should answer zero. The output should not contain extra characters such as spaces. Sample Input a[3] a[0]=a[1] . x[1] x[0]=x[0] . a[0] a[0]=1 . b[2] b[0]=2 b[1]=b[b[0]] b[0]=b[1] . g[2] G[10] g[0]=0 g[1]=G[0] . a[2147483647] a[0]=1 B[2] B[a[0]]=2 a[B[a[0]]]=3 a[2147483646]=a[2] . . Output for the Sample Input 2 2 2 3 4 0
36,233
Problem G: Strange Couple Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. The town they drive can be considered as an undirected graph with a number of intersections (vertices) and roads (edges). Each intersection may or may not have a sign. On intersections with signs, Alice and Bob will enter the road for the shortest route. When there is more than one such roads, they will go into one of them at random. On intersections without signs, they will just make a random choice. Each random selection is made with equal probabilities. They can even choose to go back to the road they have just come along, on a random selection. Calculate the expected distance Alice and Bob will drive before reaching the theater. Input The input consists of multiple datasets. Each dataset has the following format: n s t q 1 q 2 ... q n a 11 a 12 ... a 1 n a 21 a 22 ... a 2 n . . . a n 1 a n 2 ... a nn n is the number of intersections ( n ≀ 100). s and t are the intersections the home and the theater are located respectively (1 ≀ s , t ≀ n , s ≠ t ); q i (for 1 ≀ i ≀ n ) is either 1 or 0, where 1 denotes there is a sign at the i -th intersection and 0 denotes there is not; a ij (for 1 ≀ i , j ≀ n ) is a positive integer denoting the distance of the road connecting the i -th and j -th intersections, or 0 indicating there is no road directly connecting the intersections. The distance of each road does not exceed 10. Since the graph is undirectional, it holds a ij = a ji for any 1 ≀ i , j ≀ n . There can be roads connecting the same intersection, that is, it does not always hold a ii = 0. Also, note that the graph is not always planar. The last dataset is followed by a line containing three zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, print the expected distance accurate to 10 -8 , or " impossible " (without quotes) if there is no route to get to the theater. The distance may be printed with any number of digits after the decimal point. Sample Input 5 1 5 1 0 1 0 0 0 2 1 0 0 2 0 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 Output for the Sample Input 8.50000000
36,234
クリスマスパヌティヌ (Christmas Party) 問題 JOI 君は友達 1 から友達 N たでの N 人の友達を招いおクリスマスパヌティヌを行ったクリスマスパヌティヌも盛り䞊がっおきたずころで友達ず䞀緒に次のようなゲヌムを行うこずになった 最初に JOI 君は N 人の友達の䞭から 1 人を遞ぶ以降はその友達をタヌゲットず呌ぶこずにする JOI 君はタヌゲットずしお遞んだ友達にその人がタヌゲットであるこずをこっそり䌝えるタヌゲット以倖の友達は誰がタヌゲットかを知るこずはできない タヌゲット以倖の友達はそれぞれタヌゲットが誰かを予想しおその人の名前を玙に蚘入するタヌゲットは自分自身の名前を玙に蚘入する すべおの人の蚘入が終わった埌JOI 君はタヌゲットの名前を発衚する 予想が圓たった人は 1 点を埗るなおタヌゲットは自分自身の名前を玙に蚘入しおいるので必ず 1 点を埗る予想が倖れた人には埗点は䞎えられない それに加えお予想が倖れた人の人数を X 人ずしたずきタヌゲットは远加で X 点を埗る JOI 君たちはこのゲヌムを M 回行ったそれぞれの友達に察しおM 回のゲヌムにおける合蚈埗点を求めよ 入力 入力は 3 + M 行からなる 1 行目には友達の人数 N (3 ≀ N ≀ 100) が曞かれおいる 2 行目にはJOI 君たちが行ったゲヌムの回数 M (3 ≀ M ≀ 100) が曞かれおいる 3 行目にはM 個の敎数 A 1 , A 2 , ..., A M が空癜を区切りずしお曞かれおいるこれはi 回目 (1 ≩ i ≩ M) のゲヌムのタヌゲットが友達 A i (1 ≀ A i ≀ N) であるこずを衚す 続く M 行のうちの i 行目 (1 ≩ i ≩ M) にはN 個の敎数 B i,1 , B i,2 , ..., B i,N が空癜を区切りずしお曞かれおいるこれはi 回目のゲヌムにおいお友達 j (1 ≀ j ≀ N) が友達 B i,j (1 ≀ B i,j ≀ N) の名前を玙に蚘入したこずを衚すタヌゲットは自分自身の名前を玙に蚘入するのでj = A i のずき垞に B i,j = j である 出力 それぞれの友達に察しおM 回のゲヌムにおける合蚈埗点を出力せよ出力は N 行からなるj 行目 (1 ≀ j ≀ N) に友達 j の合蚈埗点を出力せよ 入出力䟋 入力䟋 1 3 4 1 2 3 2 1 1 2 3 2 2 1 1 3 2 2 2 出力䟋 1 3 4 5 入力䟋 2 5 3 3 3 1 2 4 3 3 3 4 3 3 3 1 1 3 4 1 1 出力䟋 1 3 1 6 3 2 入出力䟋 1 では 3 人の友達が 4 回のゲヌムを行う 1 回目のゲヌムのタヌゲットは友達 1 であり友達 1 は 2 点友達 2 は 1 点友達 3 は 0 点を埗る 2 回目のゲヌムのタヌゲットは友達 2 であり友達 1 は 0 点友達 2 は 2 点友達 3 は 1 点を埗る 3 回目のゲヌムのタヌゲットは友達 3 であり友達 1 は 0 点友達 2 は 0 点友達 3 は 3 点を埗る 4 回目のゲヌムのタヌゲットは友達 2 であり友達 1 は 1 点友達 2 は 1 点友達 3 は 1 点を埗る 4 回のゲヌム終了埌の合蚈埗点は友達 1 は 3 点友達 2 は 4 点友達 3 は 5 点である 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,235
ハミング数 1 に 2, 3, 5 を䜕回か (0 回以䞊) かけ算しお埗られる数をハミング数 (Hamming numbers) ず呌びたす。䟋えば、 1 1 × 2 × 2 = 4 1 × 2 × 2 × 3 × 5 × 5 = 300 などはハミング数ですが、11, 13, 14 などはハミング数ではありたせん。 ハミング数はどれも 60 のべき乗を割り切る(䟋えば、54 は 60 3 = 21600 を割り切る) ので、時刻など 60 進法の蚈算には郜合の良い数ずしお昔から知られおいたした。たた、楜噚の調埋に甚いる音階の䞀぀である玔正埋では、音の呚波数の比が 24, 27, 30, 32, 36, 40, 45, 48 ずいうハミング数からなる数列になりたす。 敎数 m 、 n を入力ずし、 m 以䞊 n 以䞋のハミング数の個数を出力するプログラムを䜜成しおください。 Input 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットずしお、぀の敎数 m ず n (1 ≀ m , n ≀ 1000000, m ≀ n ) が空癜区切りで行に䞎えられたす。 デヌタセットの数は 20 を超えたせん。 Output デヌタセットごずに m 以䞊 n 以䞋のハミング数の個数を行に出力したす。 Sample Input 3 8 1 27 1 86 0 Output for the Sample Input 5 17 31
36,236
JOI 囜のお祭り事情(Festivals in JOI Kingdom) JOI 囜にはN 個の街がありそれらの間は M 本の双方向に通行可胜な道路で結ばれおいる囜民は道路を通っおそれらの街を移動する JOI 囜の囜民にはお祭りが奜きな人が倚く珟圚 K 個の街でお祭りが開催されおおり非垞に賑わっおいる䞀方で䞀郚の囜民はお祭りを隒がしいずしお嫌いお祭りにできるだけ近づきたくないず思っおいる そこで囜王は優秀なプログラマヌであるあなたにそのようなお祭りを嫌う囜民のためある街からある街に移動するためにお祭りが開催されおいる街にどれだけ近づかずに移動するこずができるかを高速に調べるこずのできるプログラムの䜜成を䟝頌した 課題 道路の情報ずお祭りが開催されおいる街の情報および Q 個のク゚リ出発する街 S i ず行きたい街 T i の組が䞎えられる各ク゚リ i に察し街 S i から街 T i ぞのすべおの経路のうちお祭りたでの距離が最倧ずなる経路のお祭りたでの距離を求めるプログラムを䜜成せよただしある経路のお祭りたでの距離ずは経路䞊の街からお祭りが開催されおいる街たでの移動距離の最小倀のこずである 制限 2 ≀ N ≀ 100000 (= 10 5 ) JOI 囜の街の個数 1 ≀ M ≀ 200000 (= 2 × 10 5 ) JOI 囜の道路の本数 1 ≀ K ≀ N お祭りが開催されおいる街の個数 1 ≀ Q ≀ 100000 (= 10 5 ) ク゚リの個数 1 ≀ L i ≀ 1000 i 番目の道路の長さ 入力 暙準入力から以䞋のデヌタを読み蟌め 1 行目には敎数 N , M , K , Q が空癜を区切りずしお曞かれおいる N はJOI 囜の街の個数を M はJOI囜の道路の本数を K はお祭りが開催されおいる街の個数を Q はク゚リの個数をそれぞれ衚す街には1, 2, ... , N の番号が぀けられおいる 続く M 行は道路の情報を衚す i + 1 行目(1 ≀ i ≀ M ) には敎数 A i , B i , L i (1 ≀ A i ≀ N , 1 ≀ B i ≀ N ) が空癜を区切りずしお曞かれおいるこれは i 番目の道路が街 A i ず街 B i を結んでおり長さが L i であるこずを衚す道路の䞡端が同じ街であるこずはないたた任意の2 ぀の街 p , q に察し p ず q を結ぶ道路は2 本以䞊存圚しないどの街からどの街ぞもいく぀かの道路をたどっお行くこずができる 続く K 行はお祭りが開催されおいる街の情報を衚す i + M + 1 行目(1 ≀ i ≀ K ) には1 ぀の敎数 F i (1 ≀ F i ≀ N ) が曞かれおいるこれは街 F i でお祭りが開催されおいるこずを衚す F 1 , ..., F K の䞭に同じ倀が2 回以䞊珟れるこずはない 続く Q 行はク゚リを衚す i + M + K + 1 行目(1 ≀ i ≀ Q ) には2 ぀の敎数 S i , T i (1 ≀ S i ≀ N , 1 ≀ T i ≀ N , S i ≠ T i ) が空癜を区切りずしお曞かれおいるこれは i 番目のク゚リの出発する街が S i であり行きたい街が T i であるこずを衚す 出力 暙準出力に党ク゚リぞの答えを Q 行で出力せよすなわち i 行目に街 S i から街 T i ぞのすべおの経路のうちお祭りたでの距離が最倧ずなる経路のお祭りたでの距離を衚す敎数を出力せよ 採点基準 採点甚デヌタのうち 配点の10% 分に぀いおは Q = 1 を満たす 配点の20% 分に぀いおは N ≀ 5000, Q ≀ 5000 を満たす 配点の30% 分に぀いおはこれら2 ぀の条件の少なくずも䞀方を満たすたたこれら2 ぀の条件の䞡方を満たすような採点甚デヌタはない 入出力䟋 入力䟋 1 6 6 2 3 1 2 5 2 3 4 2 4 6 3 5 9 4 5 3 5 6 7 1 6 3 4 5 2 1 4 出力䟋 1 7 5 0 6 ぀の街が6 本の道路で結ばれおおりお祭りは街1, 6 の2 ぀の街で開催されおいるク゚リは以䞋の3 ぀である 1 ぀目のク゚リは街3 から街4 ぞ行くずいうものである街2 を経由する経路ではお祭りたでの距離は5街5 を経由する経路ではお祭りたでの距離は7 ずなるため答えは7 である 2 ぀目のク゚リは街5 から街2 ぞ行くずいうものである街3 ず街4 のどちらを経由しおも街2 でお祭りたでの距離が最小ずなり答えは5 である 3 ぀目のク゚リは街1 から街4 ぞ行くずいうものである街1 はお祭りが開催されおいる街であるため答えは0 ずなる 図1: 入力䟋1 入力䟋 2 12 17 2 5 1 3 6 1 6 7 2 3 8 2 4 4 2 8 11 2 12 2 3 6 3 3 7 8 3 11 2 4 12 2 5 10 3 6 10 5 8 9 6 8 12 7 9 10 6 11 9 10 12 9 5 8 7 2 6 5 2 1 10 8 9 9 4 出力䟋 2 8 8 11 0 6 図1: 入力䟋2 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,237
Score : 1400 points Problem Statement Consider the following set of rules for encoding strings consisting of 0 and 1 : Strings 0 and 1 can be encoded as 0 and 1 , respectively. If strings A and B can be encoded as P and Q , respectively, then string AB can be encoded as PQ . If string A can be encoded as P and K \geq 2 is a positive integer, then string AA...A ( A repeated K times) can be encoded as ( P x K ) . For example, string 001001001 , among other possibilities, can be encoded as 001001001 , 00(1(0x2)x2)1 and (001x3) . Let's call string A a subset of string B if: A and B are equal in length and consist of 0 and 1 ; for all indices i such that A_i = 1 , it's also true that B_i = 1 . You are given string S consisting of 0 and 1 . Find the total number of distinct encodings of all subsets of S , modulo 998244353 . Constraints 1 \leq |S| \leq 100 S consists of 0 and 1 . Input Input is given from Standard Input in the following format: S Output Print the total number of distinct encodings of all subsets of S modulo 998244353 . Sample Input 1 011 Sample Output 1 9 There are four subsets of S : 011 can be encoded as 011 and 0(1x2) ; 010 can be encoded as 010 ; 001 can be encoded as 001 and (0x2)1 ; 000 can be encoded as 000 , 0(0x2) , (0x2)0 and (0x3) . Thus, the total number of encodings of all subsets of S is 2 + 1 + 2 + 4 = 9 . Sample Input 2 0000 Sample Output 2 10 This time S has only one subset, but it can be encoded in 10 different ways. Sample Input 3 101110 Sample Output 3 156 Sample Input 4 001110111010110001100000100111 Sample Output 4 363383189 Don't forget to take the result modulo 998244353 .
36,238
Score : 300 points Problem Statement We have N ID cards, and there are M gates. We can pass the i -th gate if we have one of the following ID cards: the L_i -th, (L_i+1) -th, ..., and R_i -th ID cards. How many of the ID cards allow us to pass all the gates alone? Constraints All values in input are integers. 1 \leq N \leq 10^5 1 \leq M \leq 10^5 1 \leq L_i \leq R_i \leq N Input Input is given from Standard Input in the following format: N M L_1 R_1 L_2 R_2 \vdots L_M R_M Output Print the number of ID cards that allow us to pass all the gates alone. Sample Input 1 4 2 1 3 2 4 Sample Output 1 2 Two ID cards allow us to pass all the gates alone, as follows: The first ID card does not allow us to pass the second gate. The second ID card allows us to pass all the gates. The third ID card allows us to pass all the gates. The fourth ID card does not allow us to pass the first gate. Sample Input 2 10 3 3 6 5 7 6 9 Sample Output 2 1 Sample Input 3 100000 1 1 100000 Sample Output 3 100000
36,239
Partition Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q. In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r). Your task is to read a sequence A and perform the Partition based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r]. Input The first line of the input includes an integer n , the number of elements in the sequence A. In the second line, A i ( i = 1,2,..., n ), elements of the sequence are given separated by space characters. Output Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. The element which is selected as the pivot of the partition should be indicated by [ ] . Constraints 1 ≀ n ≀ 100,000 0 ≀ A i ≀ 100,000 Sample Input 1 12 13 19 9 5 12 8 7 4 21 2 6 11 Sample Output 1 9 5 8 7 4 2 6 [11] 21 13 19 12
36,240
E: 卒業匏 背景 ある日 Y さんはプログラミングコンテストに参加するため䌚堎がある倧孊に向かいたした ずころが倧孊に着くず人がたくさんなんず今日は卒業匏だったのです 䌚堎に向かおうにも人に抌し流されおしたい自分の進みたい方向に進むこずすらできたせん 人混みから抜け出すためにY さんは今いる堎所から少しでも遠くに行きたいず考えたした そこで Y さんは状況を以䞋のような問題ずしお定匏化し競技プログラミングを圹に立おるこずにしたした なお以䞋の問題文では Y さんは点 $P$ ずしおモデル化されおいたす 問題 座暙平面䞊の原点に点 $P$ が眮かれおいる 点 $P$ を動かしできるだけ原点からのマンハッタン距離が遠い䜍眮に移動させたい はじめに文字列 $S = s_1s_2 \cdots s_{|S|}$ ($|S|$ は $S$ の文字数) が䞎えられる 点 $P$ の移動は文字列 $S$ の先頭から文字を 1 文字ず぀読み蟌むこずで行う 文字列 $S$ は文字 'U', 'L', 'D', 'R' からなる それぞれの文字を読み蟌んだずき点 $P$ の移動前の座暙を $(x, y)$ ずするず 移動埌の点 $P$ の座暙はそれぞれ $(x, y+1),\ (x-1, y),\ (x, y-1),\ (x+1, y)$ ずなる 各文字を読み蟌む盎前に魔法をかけるか吊かを遞択するこずができる 魔法には魔法 1 ず魔法 2 の二皮類がある文字列 $S$ の $i$ 番目の文字を $s_i$ ずするず $s_i$ を読み蟌む盎前に魔法をかけたずきの倉化は以䞋の通りである 魔法 1 をかけたずき: 党おの $s_j \ (i \le j \le |S|)$ に察し'U' を 'D' に'D' を 'U' に眮換する 魔法 2 をかけたずき: 党おの $s_j \ (i \le j \le |S|)$ に察し'L' を 'R' に'R' を 'L' に眮換する 盎感的には魔法 1 ではその埌の䞊䞋の扱いを反転させるこずができ魔法 2 では巊右の扱いを反転させるこずができる ある文字を読み蟌む前にかける魔法の回数は耇数回でも構わないたた䞡方の魔法を続けおかけおもかたわない ただし文字列 $S$ の文字をすべお読み終えるたでに魔法をかけられる回数は合蚈 $K$ 回たでである 詳现はサンプルを参照されたい 文字列 $S$ の文字をすべお読み終えた埌の点 $P$ の座暙を $(x',y')$ ずするずき$|x'| + |y'|$ の最倧倀を求めよ 制玄 $1 \le |S| \le 2000$ $1 \le K \le 2000$ 入力 入力は以䞋の圢匏で暙準入力から䞎えられる $S$ $K$ 出力 $|x'| + |y'|$ の最倧倀を 1 行で出力せよたた、末尟に改行も出力せよ. サンプル サンプル入力 1 RRLUDDD 2 サンプル出力 1 7 3 文字目を読み蟌む盎前に魔法 2 をかけるず文字列 $S$ は "RRRUDDD" ずなる 続いお 5 文字目を読み蟌む盎前に魔法 1 をかけるず文字列 $S$ は "RRRUUUU" ずなる すべおの文字を読み終えた埌の点 $P$ の座暙は $(3, 4)$ ずなり 原点からのマンハッタン距離は 7 であるこれはこの䟋の最倧倀である サンプル入力 2 LULLLUULLU 1984 サンプル出力 2 10 1 回も魔法をかけなかった堎合$x’ = -6, \ y’ = 4$ ずなり$|x’| + |y’| = 10$ である サンプル入力 3 DRDLUDD 1 サンプル出力 3 5 サンプル入力 4 LURRRLUDLL 1 サンプル出力 4 6
36,241
Max Score: $1200$ Points Problem statement There are $N$ customers in a restaurant. Each customer is numbered $1$ through $N$. A sushi chef carried out $Q$ operations for customers. The $i$-th operation is follows: The sushi chef chooses a customer whose number of dishes of sushi eaten is minimum, in customer $1, 2, 3, \dots, a_i$. If there are multiple customers who are minimum numbers of dishes, he selects the minimum-numbered customers. He puts a dish of sushi on the selected seats. A customer who have selected for professional eats this sushi. Repeat 1-3, $b_i$ times. Please calculate the number of dishes of sushi that have been eaten by each customer. Input The input is given from Standard Input in the following format: $N \ Q$ $a_1 \ b_1$ $a_2 \ b_2$ $  \  $ $a_Q \ b_Q$ Output You have to print $N$ lines. The $i$-th line should contain the number of dishes of sushi had eaten for customer $i (1 \le i \le N)$. Constraints $3 \le N, Q \le 100,000$ $1 \le a_i \le N$ $1 \le b_i \le 10^{12}$ Any final results do not exceed $2 \times 10^{13}$. Subtasks Subtask 1 [ $60$ points ] $N, Q \le 100$ $b_i = 1$ Subtask 2 [ $400$ points ] $N, Q \le 100$ $b_i \le 10^{12}$ Subtask 3 [ $240$ points ] $N, Q \le 100,000$ $b_i = 1$ Subtask 4 [ $500$ points ] There are no additional constraints. Sample Input 1 9 3 5 11 8 4 4 7 Sample Output 1 4 4 4 4 2 2 1 1 0 The change of the number of dishes of sushi have eaten is following: Customer 1 Customer 2 Customer 3 Customer 4 Customer 5 Customer 6 Customer 7 Customer 8 Customer 9 1st Operation 3 2 2 2 2 0 0 0 0 2nd Operation 3 2 2 2 2 2 1 1 0 3rd Operation 4 4 4 4 2 2 1 1 0 Sample Input 2 6 6 3 5 6 11 1 6 4 7 5 2 2 5 Sample Output 2 10 10 5 5 4 2 Sample Input 3 5 6 1 1 2 1 3 1 1 1 5 1 3 1 Sample Output 3 2 2 1 1 0 Sample Input 4 10 10 10 10 9 20 8 30 7 40 6 50 5 60 4 70 3 80 2 90 1 100 Sample Output 4 223 123 77 50 33 21 12 7 3 1 Writer: E869120
36,242
Score : 600 points Problem Statement There are N piles of stones. The i -th pile has A_i stones. Aoki and Takahashi are about to use them to play the following game: Starting with Aoki, the two players alternately do the following operation: Operation: Choose one pile of stones, and remove one or more stones from it. When a player is unable to do the operation, he loses, and the other player wins. When the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile. In such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1 -st pile to the 2 -nd pile before the game begins. If this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead. Constraints 2 \leq N \leq 300 1 \leq A_i \leq 10^{12} Input Input is given from Standard Input in the following format: N A_1 \ldots A_N Output Print the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead. Sample Input 1 2 5 3 Sample Output 1 1 Without moving stones, if Aoki first removes 2 stones from the 1 -st pile, Takahashi cannot win in any way. If Takahashi moves 1 stone from the 1 -st pile to the 2 -nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions. Sample Input 2 2 3 5 Sample Output 2 -1 It is not allowed to move stones from the 2 -nd pile to the 1 -st. Sample Input 3 3 1 1 2 Sample Output 3 -1 It is not allowed to move all stones from the 1 -st pile. Sample Input 4 8 10 9 8 7 6 5 4 3 Sample Output 4 3 Sample Input 5 3 4294967297 8589934593 12884901890 Sample Output 5 1 Watch out for overflows.
36,243
Balls and Boxes 3 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is distinguished from the other. Each box is distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box must contain at least one ball. Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 4 3 Sample Output 1 36 Sample Input 2 10 3 Sample Output 2 55980 Sample Input 3 100 100 Sample Output 3 437918130
36,244
Polygon-Point-Containment For a given polygon g and target points t , print "2" if g contains t , "1" if t is on a segment of g , "0" otherwise. g is represented by a sequence of points p 1 , p 2 ,..., p n where line segments connecting p i and p i+1 (1 ≀ i ≀ n-1 ) are sides of the polygon. The line segment connecting p n and p 1 is also a side of the polygon. Note that the polygon is not necessarily convex. Input The entire input looks like: g (the sequence of the points of the polygon) q (the number of queris = the number of target points) 1st query 2nd query : q th query g is given by coordinates of the points p 1 ,..., p n in the following format: n x 1 y 1 x 2 y 2 : x n y n The first integer n is the number of points. The coordinate of a point p i is given by two integers x i and y i . The coordinates of points are given in the order of counter-clockwise visit of them. Each query consists of the coordinate of a target point t . The coordinate is given by two intgers x and y . Output For each query, print "2", "1" or "0". Constraints 3 ≀ n ≀ 100 1 ≀ q ≀ 1000 -10000 ≀ x i , y i ≀ 10000 No point of the polygon will occur more than once. Two sides of the polygon can intersect only at a common endpoint. Sample Input 4 0 0 3 1 2 3 0 3 3 2 1 0 2 3 2 Sample Output 2 1 0
36,245
Score : 1000 points Problem Statement There are two (6-sided) dice: a red die and a blue die. When a red die is rolled, it shows i with probability p_i percents, and when a blue die is rolled, it shows j with probability q_j percents. Petr and tourist are playing the following game. Both players know the probabilistic distributions of the two dice. First, Petr chooses a die in his will (without showing it to tourist), rolls it, and tells tourist the number it shows. Then, tourist guesses the color of the chosen die. If he guesses the color correctly, tourist wins. Otherwise Petr wins. If both players play optimally, what is the probability that tourist wins the game? Constraints 0 ≀ p_i, q_i ≀ 100 p_1 + ... + p_6 = q_1 + ... + q_6 = 100 All values in the input are integers. Input The input is given from Standard Input in the following format: p_1 p_2 p_3 p_4 p_5 p_6 q_1 q_2 q_3 q_4 q_5 q_6 Output Print the probability that tourist wins. The absolute error or the relative error must be at most 10^{-9} . Sample Input 1 25 25 25 25 0 0 0 0 0 0 50 50 Sample Output 1 1.000000000000 tourist can always win the game: If the number is at most 4 , the color is definitely red. Otherwise the color is definitely blue. Sample Input 2 10 20 20 10 20 20 20 20 20 10 10 20 Sample Output 2 0.550000000000
36,246
Score : 500 points Problem Statement You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: Type 1 : change the i_q -th character of S to c_q . (Do nothing if the i_q -th character is already c_q .) Type 2 : answer the number of different characters occurring in the substring of S between the l_q -th and r_q -th characters (inclusive). Constraints N , Q , i_q , l_q , and r_q are integers. S is a string consisting of lowercase English letters. c_q is a lowercase English letter. 1 \leq N \leq 500000 1 \leq Q \leq 20000 |S| = N 1 \leq i_q \leq N 1 \leq l_q \leq r_q \leq N There is at least one query of type 2 in each testcase. Input Input is given from Standard Input in the following format: N S Q Query_1 \vdots Query_Q Here, Query_i in the 4 -th through (Q+3) -th lines is one of the following: 1 i_q c_q 2 l_q r_q Output For each query of type 2 , print a line containing the answer. Sample Input 1 7 abcdbbd 6 2 3 6 1 5 z 2 1 1 1 4 a 1 7 d 2 1 7 Sample Output 1 3 1 5 In the first query, cdbb contains three kinds of letters: b , c , and d , so we print 3 . In the second query, S is modified to abcdzbd . In the third query, a contains one kind of letter: a , so we print 1 . In the fourth query, S is modified to abcazbd . In the fifth query, S does not change and is still abcazbd . In the sixth query, abcazbd contains five kinds of letters: a , b , c , d , and z , so we print 5 .
36,247
Score : 1500 points Problem Statement We have a sequence A of length N . On this sequence, we can perform the following two kinds of operations: Swap two adjacent elements. Select one element, and increment it by 1 . We will repeatedly perform these operations so that A will be a non-decreasing sequence. Find the minimum required number of operations. Constraints 1 ≀ N ≀ 200000 1 ≀ A_i ≀ 10^9 A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 : A_N Output Print the minimum number of operations required to turn A into a non-decreasing sequence. Sample Input 1 5 4 1 8 8 7 Sample Output 1 2 We can turn A into a non-decreasing sequence in two operations: Initially, A = \{4, 1, 8, 8, 7\} . Swap the first two elements. Now, A = \{1, 4, 8, 8, 7\} . Increment the last element by 1 . Now, A = \{1, 4, 8, 8, 8\} . Sample Input 2 20 8 2 9 7 4 6 7 9 7 4 7 4 4 3 6 2 3 4 4 9 Sample Output 2 62
36,248
Score : 500 points Problem Statement A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x -axis direction. This robot will be given an instruction sequence s . s consists of the following two kinds of letters, and will be executed in order from front to back. F : Move in the current direction by distance 1 . T : Turn 90 degrees, either clockwise or counterclockwise. The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable. Constraints s consists of F and T . 1 \leq |s| \leq 8 000 x and y are integers. |x|, |y| \leq |s| Input Input is given from Standard Input in the following format: s x y Output If the objective is achievable, print Yes ; if it is not, print No . Sample Input 1 FTFFTFFF 4 2 Sample Output 1 Yes The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T . Sample Input 2 FTFFTFFF -2 -2 Sample Output 2 Yes The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T . Sample Input 3 FF 1 0 Sample Output 3 No Sample Input 4 TF 1 0 Sample Output 4 No Sample Input 5 FFTTFF 0 0 Sample Output 5 Yes The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T . Sample Input 6 TTTT 1 0 Sample Output 6 No
36,249
Score : 100 points Problem Statement There are N children, numbered 1, 2, \ldots, N . They have decided to share K candies among themselves. Here, for each i ( 1 \leq i \leq N ), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over. Find the number of ways for them to share candies, modulo 10^9 + 7 . Here, two ways are said to be different when there exists a child who receives a different number of candies. Constraints All values in input are integers. 1 \leq N \leq 100 0 \leq K \leq 10^5 0 \leq a_i \leq K Input Input is given from Standard Input in the following format: N K a_1 a_2 \ldots a_N Output Print the number of ways for the children to share candies, modulo 10^9 + 7 . Sample Input 1 3 4 1 2 3 Sample Output 1 5 There are five ways for the children to share candies, as follows: (0, 1, 3) (0, 2, 2) (1, 0, 3) (1, 1, 2) (1, 2, 1) Here, in each sequence, the i -th element represents the number of candies that Child i receives. Sample Input 2 1 10 9 Sample Output 2 0 There may be no ways for the children to share candies. Sample Input 3 2 0 0 0 Sample Output 3 1 There is one way for the children to share candies, as follows: (0, 0) Sample Input 4 4 100000 100000 100000 100000 100000 Sample Output 4 665683269 Be sure to print the answer modulo 10^9 + 7 .
36,250
Problem H. Enlarge Circles You are given $N$ distinct points on the 2-D plane. For each point, you are going to make a single circle whose center is located at the point. Your task is to maximize the sum of perimeters of these $N$ circles so that circles do not overlap each other. Here, "overlap" means that two circles have a common point which is not on the circumference of at least either of them. Therefore, the circumferences can be touched. Note that you are allowed to make a circle with radius $0$. Input The input consists of a single test case in the following format. $N$ $x_1$ $y_1$ $\vdots$ $x_N$ $y_N$ The first line contains an integer $N$, which is the number of points ($2 \leq N \leq 200$). Each of the following $N$ lines gives the coordinates of a point. Integers $x_i$ and $y_i$ ($-100 \leq x_i, y_i \leq 100$) in the $i$-th line of them give the $x$- and $y$-coordinates, respectively, of the $i$-th point. These points are distinct, in other words, $(x_i,y_i) \ne (x_j, y_j)$ is satisfied if $i$ and $j$ are different. Output Output the maximized sum of perimeters. The output can contain an absolute or a relative error no more than $10^{-6}$. Examples Sample Input 1 3 0 0 3 0 5 0 Output for Sample Input 1 31.415926535 Sample Input 2 3 0 0 5 0 0 5 Output for Sample Input 2 53.630341225 Sample Input 3 9 91 -18 13 93 73 -34 15 2 -46 0 69 -42 -23 -13 -87 41 38 68 Output for Sample Input 3 1049.191683488
36,251
䌚接地鶏 2008 幎 4 月に、䌚接若束垂は長さ20 m 85 cm のやきずり䜜りに挑戊しお成功したした。このずき䜿われた鶏肉が、䌚接特産の䌚接地鶏です。䌚接地鶏はずおもおいしいのですが、飌育がむずかしいので生産量が少なく、倀段が高いのが難点です。 今日は䞀郎君の家に、遠くから芪戚が遊びに来たす。お母さんは鶏肉の氎炊きを䜜っお芪戚をもおなすこずにしたした。近くのお肉屋さんでは䌚接地鶏ずふ぀うの鶏肉の 2 皮類の鶏肉を売っおいたす。お母さんは、以䞋のような指瀺を䞀郎君に䞎えお、お肉屋さんに行っお鶏肉を買っおくるように 頌みたした。 鶏肉が足りなくなるず困るので、決められた量以䞊の鶏肉を買う。 予算の蚱す範囲で䌚接地鶏をできるだけ倚く買う(䌚接地鶏は必ず買うこず)。 䌚接地鶏を買った残りでふ぀うの鶏肉をできるだけ倚く買う(予算が足りなければ買わない)。 䞀郎君がお肉屋さんに行くず、䌚接地鶏が品薄のため䞀人が買える量を制限しおいたした。䞀郎君が、お母さんから䞎えられたすべおの指瀺を守っお買い物をするずき、䞀郎君が買う䌚接地鶏ず普通の鶏肉の量はそれぞれ䜕グラムになるでしょう? 買うべき鶏肉の量の䞋限 q 1 、予算 b 、このお肉屋さんでの䌚接地鶏 100 グラムの倀段 c 1 、ふ぀うの鶏肉 100 グラムの倀段 c 2 、䌚接地鶏を䞀人が買える量の䞊限 q 2 を入力ずし、䞀郎君が買う䌚接地鶏ずふ぀うの鶏肉の量を 100 グラム単䜍で出力するプログラムを䜜成しおください。ただし、このお肉屋さんではお母さんの指瀺通りに買えない堎合には、「NA」ず出力しおください。 Input 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 q 1 b c 1 c 2 q 2 鶏肉の量を衚すデヌタ q 1 ず q 2 は100 グラム単䜍で指定されたす。たた、 b 、 c 1 、 c 2 、 q 1 、 q 2 は 1 以䞊 1,000,000 以䞋の敎数ずしたす。 デヌタセットの数は 50 を超えたせん。 Output デヌタセット毎に、䞀郎君が賌入する䌚接地鶏の量ずふ぀うの鶏肉の量(半角空癜区切り) たたは「NA」を行に出力したす。 Sample Input 48 9297 240 126 32 20 3010 157 141 7 30 117002 5680 962 15 8 1673 1712 190 22 64 8478 87 54 307 23 5477 117 92 12 50 7558 1396 187 17 279 88677 4522 514 14 0 Output for the Sample Input 28 20 7 13 15 33 NA 97 0 12 44 NA NA
36,252
Count For a given sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$, perform the following operations. count($b, e, k$): print the number of the specific values $k$ in $a_b, a_{b+1}, ..., a_{e-1}$. Input The input is given in the following format. $n$ $a_0 \; a_1, ..., \; a_{n-1}$ $q$ $b_1 \; e_1 \; k_1$ $b_2 \; e_2 \; k_2$ : $b_q \; e_q \; k_q$ The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $b_i \; b_e \; k_i$ are given as queries. Output For each query, print the number of specified values. Constraints $1 \leq n \leq 1,000$ $-1,000,000,000 \leq a_i, k_i \leq 1,000,000,000$ $1 \leq q \leq 1,000$ $0 \leq b < e \leq n$ Sample Input 1 9 1 4 1 4 2 1 3 5 6 3 0 9 1 1 6 1 3 7 5 Sample Output 1 3 2 0
36,253
Score : 500 points Problem Statement In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network: People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary. Different roads may have had different lengths, but all the lengths were positive integers. Snuke the archeologist found a table with N rows and N columns, A , in the ruin of Takahashi Kingdom. He thought that it represented the shortest distances between the cities along the roads in the kingdom. Determine whether there exists a road network such that for each u and v , the integer A_{u, v} at the u -th row and v -th column of A is equal to the length of the shortest path from City u to City v . If such a network exist, find the shortest possible total length of the roads. Constraints 1 \leq N \leq 300 If i ≠ j , 1 \leq A_{i, j} = A_{j, i} \leq 10^9 . A_{i, i} = 0 Inputs 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_{N, 1} A_{N, 2} ... A_{N, N} Outputs If there exists no network that satisfies the condition, print -1 . If it exists, print the shortest possible total length of the roads. Sample Input 1 3 0 1 3 1 0 2 3 2 0 Sample Output 1 3 The network below satisfies the condition: City 1 and City 2 is connected by a road of length 1 . City 2 and City 3 is connected by a road of length 2 . City 3 and City 1 is not connected by a road. Sample Input 2 3 0 1 3 1 0 1 3 1 0 Sample Output 2 -1 As there is a path of length 1 from City 1 to City 2 and City 2 to City 3 , there is a path of length 2 from City 1 to City 3 . However, according to the table, the shortest distance between City 1 and City 3 must be 3 . Thus, we conclude that there exists no network that satisfies the condition. Sample Input 3 5 0 21 18 11 28 21 0 13 10 26 18 13 0 23 13 11 10 23 0 17 28 26 13 17 0 Sample Output 3 82 Sample Input 4 3 0 1000000000 1000000000 1000000000 0 1000000000 1000000000 1000000000 0 Sample Output 4 3000000000
36,254
Score : 400 points Problem Statement Takahashi is going to buy N items one by one. The price of the i -th item he buys is A_i yen (the currency of Japan). He has M discount tickets, and he can use any number of them when buying an item. If Y tickets are used when buying an item priced X yen, he can get the item for \frac{X}{2^Y} (rounded down to the nearest integer) yen. What is the minimum amount of money required to buy all the items? Constraints All values in input are integers. 1 \leq N, M \leq 10^5 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the minimum amount of money required to buy all the items. Sample Input 1 3 3 2 13 8 Sample Output 1 9 We can buy all the items for 9 yen, as follows: Buy the 1 -st item for 2 yen without tickets. Buy the 2 -nd item for 3 yen with 2 tickets. Buy the 3 -rd item for 4 yen with 1 ticket. Sample Input 2 4 4 1 9 3 5 Sample Output 2 6 Sample Input 3 1 100000 1000000000 Sample Output 3 0 We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets. Sample Input 4 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Sample Output 4 9500000000
36,255
Problem H Kimagure Cleaner Ichiro won the newest model cleaner as a prize of a programming contest. This cleaner automatically moves around in a house for cleaning. Because Ichiro's house is very large, it can be modeled as an infinite two-dimensional Cartesian plane, whose axes are called $X$ and $Y$. The positive direction of the $Y$-axis is to the left if you face the positive direction of the $X$-axis. The cleaner performs a sequence of actions for cleaning. Each action consists of a turn and a run. In an action, first the cleaner turns right or left by 90 degrees, and then runs straight by an integer length to the direction that the cleaner faces. At the end of a day, the cleaner reports the log of its actions in the day to Ichiro, in order to inform him where it has cleaned and where it hasn't. Unlike common cleaners, this cleaner has human-like artificial intelligence. Therefore, the cleaner is very forgetful (like humans) and it is possible that the cleaner forgets the direction of a turn, or the cleaner only remembers the length of a run as a very rough range. However, in order to pretend to be operating correctly, the cleaner has to recover the complete log of actions after finishing the cleaning. The cleaner was initially at the point $(0, 0)$, facing the positive direction of $X$-axis. You are given the cleaner's location after cleaning, $(X, Y)$, and an incomplete log of the cleaner's actions that the cleaner remembered. Please recover a complete log from the given incomplete log. The actions in the recovered log must satisfy the following constraints: The number of actions must be the same as that in the incomplete log. The direction of the $i$-th turn must be the same as that in the incomplete log if it is recorded in the incomplete log. The length of the $i$-th run must be within the range of the length specified in the incomplete log. The cleaner must be at $(X, Y)$ after finishing all actions. The direction of the cleaner after cleaning is not important and you do not have to care about it, because the cleaner can turn freely after cleaning, though it cannot run after cleaning. You are not required to recover the actual path, because Ichiro only checks the format of the log and the location of the cleaner after cleaning. Input The input consists of a single test case. The first line contains three integers $N$ $(1 \leq N \leq 50)$, $X$, and $Y$ $(-10^9 \leq X, Y \leq 10^9)$. $N$ represents the number of actions in the incomplete log. $X$ and $Y$ represent the cleaner's location $(X, Y)$ after cleaning. The $i$-th line of the following $N$ lines contains a character $D_i$ and two integers $LL_i$ and $LU_i$. $D_i$ represents the direction of the $i$-th turn: ' L ', ' R ', and ' ? ' represents left, right, and not recorded respectively. $LL_i$ and $LU_i$ represent a lower and upper bound of the length of the $i$-th run, respectively. You can assume $1 \leq LL_i \leq LU_i \leq 55,555,555$. Output Display the recovered log. In the first line, display N, the number of actions in the log. In the $i$-th line of the following $N$ lines, display the direction of the $i$-th turn in a character and the length of the $i$-th run separated by a single space. Represent a right turn by a single character ' R ', and a left turn by a single character ' L '. The recovered log must satisfy the constraints in the problem. If there are multiple logs that satisfy the constraints, you can display any of them. Display $-1$ in a line if there is no log that satisfies the constraints. Sample Input 1 2 -3 4 L 2 5 ? 3 5 Output for the Sample Input 1 2 L 4 L 3 Sample Input 2 5 3 -4 ? 1 5 ? 1 5 ? 1 5 ? 1 5 ? 1 5 Output for the Sample Input 2 5 L 1 R 2 R 4 L 1 R 1
36,256
Problem B: Balloon Collecting "Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on the ground to capture the balloons. The player can control the vehicle to move left or right, or simply stay. When one of the balloons reaches the ground, the vehicle and the balloon must reside at the same position, otherwise the balloon will burst and the game ends. Figure B.1: Robot vehicle and falling balloons The goal of the game is to store all the balloons into the house at the left end on the game field. The vehicle can carry at most three balloons at a time, but its speed changes according to the number of the carrying balloons. When the vehicle carries k balloons ( k = 0, 1, 2, 3), it takes k +1 units of time to move one unit distance. The player will get higher score when the total moving distance of the vehicle is shorter. Your mission is to help the game designer check game data consisting of a set of balloons. Given a landing position (as the distance from the house) and a landing time of each balloon, you must judge whether a player can capture all the balloons, and answer the minimum moving distance needed to capture and store all the balloons. The vehicle starts from the house. If the player cannot capture all the balloons, you must identify the first balloon that the player cannot capture. Input The input is a sequence of datasets. Each dataset is formatted as follows. n p 1 t 1 . . . p n t n The first line contains an integer n, which represents the number of balloons (0 < n ≀ 40). Each of the following n lines contains two integers p i and t i (1 ≀ i ≀ n ) separated by a space. p i and t i represent the position and the time when the i -th balloon reaches the ground (0 < p i ≀ 100, 0 < t i ≀ 50000). You can assume t i < t j for i < j . The position of the house is 0, and the game starts from the time 0. The sizes of the vehicle, the house, and the balloons are small enough, and should be ignored. The vehicle needs 0 time for catching the balloons or storing them into the house. The vehicle can start moving immediately after these operations. The end of the input is indicated by a line containing a zero. Output For each dataset, output one word and one integer in a line separated by a space. No extra characters should occur in the output. If the player can capture all the balloons, output "OK" and an integer that represents the minimum moving distance of the vehicle to capture and store all the balloons. If it is impossible for the player to capture all the balloons, output "NG" and an integer k such that the k -th balloon in the dataset is the first balloon that the player cannot capture. Sample Input 2 10 100 100 270 2 10 100 100 280 3 100 150 10 360 40 450 3 100 150 10 360 40 440 2 100 10 50 200 2 100 100 50 110 1 15 10 4 1 10 2 20 3 100 90 200 0 Output for the Sample Input OK 220 OK 200 OK 260 OK 280 NG 1 NG 2 NG 1 OK 188
36,257
Score : 100 points Problem Statement You have decided to give an allowance to your child depending on the outcome of the game that he will play now. The game is played as follows: There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it. The player should construct a formula of the form X + Y , by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.) Then, the amount of the allowance will be equal to the resulting value of the formula. Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance. Constraints All values in input are integers. 1 \leq A, B, C \leq 9 Input Input is given from Standard Input in the following format: A B C Output Print the maximum possible amount of the allowance. Sample Input 1 1 5 2 Sample Output 1 53 The amount of the allowance will be 53 when the panels are arranged as 52+1 , and this is the maximum possible amount. Sample Input 2 9 9 9 Sample Output 2 108 Sample Input 3 6 6 7 Sample Output 3 82
36,258
G: Dungeon of Cards / カヌドの迷宮 物語 ここは䞍思議の囜あじふらいあじふらい蟺境の地に䜍眮するカヌドの迷宮には金銀財宝が眠るず䌝えられおいる奜奇心旺盛なあいずにゃんはこの蚀い䌝えを聞くやいなや友人のりィを連れおカヌドの迷宮を目指す旅に出るこずにした 翌日旅の蚈画を立おるためにあいずにゃんがりィの家を蚪れるずりィは䜕やら考え蟌んでいるようだったどうやら甚意呚到なりィはカヌドの迷宮に関する重芁な情報を入手したようだそれはカヌドの迷宮には N 枚の扉がありそれぞれの扉を開けるためにカヌドが必芁になるずいうこずだ カヌドの迷宮ぞの道䞭には扉を開くためのカヌドを扱う店があるりィはここでカヌドを調達しようず考えおいるらしいが問題なのは予算であるあいずにゃんずりィは決しおお金持ちではないのでカヌドにお金をかけすぎおしたうず道䞭の食料を十分に確保できない可胜性があるのだ 幞い N 枚の扉の情報はこれたで迷宮に挑んだ人々の蚘録から知るこずができたこれなら効率の良いカヌドの買い方を蚈算できるかもしれないしかし人で考えるには少し難しいそこであいずにゃんずりィはあじふらいに䜏む優秀なプログラマであるあなたに䟝頌をするこずにした 問題 N 枚の扉ず M 枚のカヌドがある扉・カヌドずもに枚に぀き英倧文字アルファベット ('A'-'Z') 1぀ず1桁の数字 ('0'-'9') が描かれおいる扉にカヌドをかざすずカヌドに描かれたアルファベットもしくは数字のどちらか䞀方でも扉のものず䞀臎しおいればその扉を開けるこずができるこのずきカヌドはなくならないため同じカヌドを䜕床でも䜿いたわすこずができるたたカヌドにはそれぞれ倀段が付いおいる N 枚の扉ず M 枚のカヌドの情報を元にすべおの扉を開けるこずができるカヌドの買い方のうち芁する金額が最小ずなる堎合の金額を蚈算するプログラムを䜜成せよ 入力圢匏 入力は以䞋の圢匏からなる N a_1 b_1 ... a_N b_N M c_1 d_1 e_1 ... c_M d_M e_M 1行目では扉の枚数を衚す敎数 N が䞎えられる続く N 行のうち i 行目では i 番目の扉に曞かれた英倧文字アルファベット a_i ず1桁の数字 b_i が䞎えられる 続く1行では店で扱われおいるカヌドの枚数 M が䞎えられる続く M 行のうち j 行目では j 番目のカヌドに曞かれた英倧文字アルファベット c_j ず1桁の数字 d_j 䟡栌 e_j が䞎えられる 入力は以䞋の制玄を満たす 1 ≀ N, M ≀ 10{,}000 a_i, c_j はアルファベット倧文字 ('A'-'Z') 1文字 b_i, d_j は1桁の数字 ('0'-'9') 1文字 1 ≀ e_j ≀ 1{,}000 N, M, e_j はすべお敎数 出力圢匏 迷宮の扉をすべお開けるために必芁なカヌドを揃えるための最小予算を1行に出力せよどのようにカヌドを買っおも党おの扉を開けられない堎合-1を1行に出力せよ 入力䟋 4 D 1 D 2 A 3 D 4 4 A 1 7 D 4 5 D 3 6 B 3 3 出力䟋 6 入力䟋2 4 D 1 D 2 A 3 D 4 4 A 1 7 D 4 5 D 3 10 B 3 3 出力䟋2 8 入力䟋3 5 D 1 D 2 A 3 Z 0 D 4 4 A 1 7 D 4 5 D 3 6 B 3 3 出力䟋3 -1
36,259
Score : 300 points Problem Statement You are given an array A of length N . Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into? Constraints 1 \leq N \leq 10^5 1 \leq A_i \leq 10^9 Each A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of subarrays after division of A . Sample Input 1 6 1 2 3 2 2 1 Sample Output 1 2 One optimal solution is to divide the array into [1,2,3] and [2,2,1] . Sample Input 2 9 1 2 1 2 1 2 1 2 1 Sample Output 2 5 Sample Input 3 7 1 2 3 2 1 999999999 1000000000 Sample Output 3 3
36,260
Score: 800 points Problem Statement This is an interactive task. We have 2N balls arranged in a row, numbered 1, 2, 3, ..., 2N from left to right, where N is an odd number. Among them, there are N red balls and N blue balls. While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most 210 questions of the following form: You choose any N of the 2N balls and ask whether there are more red balls than blue balls or not among those N balls. Now, let us begin. Constraints 1 \leq N \leq 99 N is an odd number. Input and Output First, receive the number of balls of each color, N , from Standard Input: N Then, ask questions until you find out the color of every ball. A question should be printed to Standard Output in the following format: ? A_1 A_2 A_3 ... A_N This means that you are asking about the N balls A_1, A_2, A_3, ..., A_N , where 1 \leq A_i \leq 2N and A_i \neq A_j (i \neq j) must hold. The response T to this question will be given from Standard Input in the following format: T Here T is one of the following strings: Red : Among the N balls chosen, there are more red balls than blue balls. Blue : Among the N balls chosen, there are more blue balls than red balls. -1 : You printed an invalid question (including the case you asked more than 210 questions), or something else that was invalid. If the judge returns -1 , your submission is already judged as incorrect. The program should immediately quit in this case. When you find out the color of every ball, print your guess to Standard Output in the following format: ! c_1 c_2 c_3 ... c_{2N} Here c_i should be the character representing the color of Ball i ; use R for red and B for blue. Notice Flush Standard Output each time you print something. Failure to do so may result in TLE . Immediately terminate your program after printing your guess (or receiving the -1 response). Otherwise, the verdict will be indeterminate. If your program prints something invalid, the verdict will be indeterminate. Sample Input and Output Input Output 3 ? 1 2 3 Red ? 2 4 6 Blue ! RRBBRB In this sample, N = 3 , and the colors of Ball 1, 2, 3, 4, 5, 6 are red, red, blue, blue, red, blue, respectively. In the first question, there are two red balls and one blue ball among the balls 1, 2, 3 , so the judge returns Red . In the second question, there are one red ball and two blue balls among the balls 2, 4, 6 , so the judge returns Blue .
36,261
Problem J: Revenge of the Round Table Two contries A and B have decided to make a meeting to get acquainted with each other. n ambassadors from A and B will attend the meeting in total. A round table is prepared for in the meeting. The ambassadors are getting seated at the round table, but they have agreed that more than k ambassadors from the same country does not sit down at the round table in a row for deeper exchange. Your task is to write a program that reports the number of possible arrangements when rotations are not counted. Your program should report the number modulo M = 1000003. Let us provide an example. Suppose n = 4 and k = 2. When rotations are counted as different arrangements, the following six arrangements are possible. AABB ABBA BBAA BAAB ABAB BABA However, when rotations are regarded as same, the following two arrangements are possible. AABB ABAB Therefore the program should report 2. Input The input consists of multiple datasets. Each dataset consists of two integers n (1 ≀ n ≀ 1000) and k (1 ≀ k ≀ 1000) in one line. It does not always hold k < n . This means the program should consider cases in which the ambassadors from only one country attend the meeting. The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, print the number of possible arrangements modulo M = 1000003 in one line. Sample Input 3 1 3 2 3 3 4 2 10 5 1000 500 0 0 Output for the Sample Input 0 2 4 2 90 570682
36,262
Problem H: 迷い猫、走った 掋菓子専門店ストレむキャッツではたくさんの猫が飌われおいる。猫の数があたりにも倚いため、この店のスタッフである垌は逌やりに困っおいた。 いく぀かの堎所に逌を眮いおも、猫は貪欲なので最も近い逌に向かっおしたい、䞀぀の逌入れにたくさんの猫が集䞭しおしたう。 あなたは垌のために、できるだけ猫が集䞭しない逌の配眮を求める問題を解くこずにした。 問題を簡単にするため、猫は平面䞊の y>0 の郚分にいお逌を眮くたで動かないずする。 猫は N 個の集団に分かれおいお、䞀箇所に䜕匹もいるかもしれない。 逌入れは y=0 䞊の M 点に固定しおあり、この䞭からいく぀か遞んで逌を入れるこずになる。 逌を入れるず、猫は(ナヌクリッド距離で)䞀番近い逌の入った逌入れに向かうが、同じ距離に二぀あるずきはx座暙が小さいほうに向かうものずする。 この条件の䞋で、最も猫が集たっおいる逌入れの猫の数を最小化しなさい。 Input 入力は以䞋のような圢匏で䞎えられる。 N M x 1 y 1 C 1 ... x N y N C N x 1 ... x M 入力の1行目には、2぀の敎数 N, M がスペヌス文字で区切られお䞎えられる。これらは、問題文で指定したずおりである。0 ≀ N ≀ 1000 および 1 ≀ M ≀ 1000 を満たす。 続く N 行には、それぞれの猫の集団に぀いお1行に1぀ず぀、集団の䜍眮の x, y 座暙を衚す敎数の組 (-10000 ≀ x ≀ 10000, 0 < y ≀ 10000)ず䜕匹集たっおいるかを衚す敎数C(1 ≀ C ≀ 100000)が䞎えられる。 その埌のM行には、それぞれの逌入れに぀いお1行に1぀ず぀、逌入れの䜍眮のx座暙を衚す敎数(-10000 ≀ x ≀ 10000)が䞎えられる。 同じ点に、二぀以䞊の逌入れが存圚するこずはない。 Output 最も猫が集たっおいる逌入れの猫の数の最小倀を出力せよ。 Notes on Test Cases 䞊蚘入力圢匏で耇数のデヌタセットが䞎えられたす。各デヌタセットに察しお䞊蚘出力圢匏で出力を行うプログラムを䜜成しお䞋さい。 N, M がずもに 0 のずき入力の終わりを瀺したす。 Sample Input 3 3 -1 1 1 0 1 1 1 1 1 -3 0 3 5 5 7 3 5 -9 2 7 4 9 6 10 5 9 -9 7 9 0 -1 -2 -9 -8 0 0 Output for Sample Input 2 20
36,263
Score : 100 points Problem Statement There is always an integer in Takahashi's mind. Initially, the integer in Takahashi's mind is 0 . Takahashi is now going to eat four symbols, each of which is + or - . When he eats + , the integer in his mind increases by 1 ; when he eats - , the integer in his mind decreases by 1 . The symbols Takahashi is going to eat are given to you as a string S . The i -th character in S is the i -th symbol for him to eat. Find the integer in Takahashi's mind after he eats all the symbols. Constraints The length of S is 4 . Each character in S is + or - . Input Input is given from Standard Input in the following format: S Output Print the integer in Takahashi's mind after he eats all the symbols. Sample Input 1 +-++ Sample Output 1 2 Initially, the integer in Takahashi's mind is 0 . The first integer for him to eat is + . After eating it, the integer in his mind becomes 1 . The second integer to eat is - . After eating it, the integer in his mind becomes 0 . The third integer to eat is + . After eating it, the integer in his mind becomes 1 . The fourth integer to eat is + . After eating it, the integer in his mind becomes 2 . Thus, the integer in Takahashi's mind after he eats all the symbols is 2 . Sample Input 2 -+-- Sample Output 2 -2 Sample Input 3 ---- Sample Output 3 -4
36,264
Problem F: Equilateral Triangle Problem $N$個の頂点からなる凞倚角圢が䞎えられる。 その凞倚角圢の党おの頂点を含む正䞉角圢を考えるずき、その正䞉角圢の䞀蟺の長さの最小倀を求めよ。 Input 入力は以䞋の圢匏ですべお敎数で䞎えられる。 $N$ $px_1$ $py_1$ $px_2$ $py_2$ $\vdots$ $px_N$ $py_N$ $1$行目には凞倚角圢の頂点数を衚す敎数$N$が䞎えられる。 続く$N$行には凞倚角圢の各頂点の情報が反時蚈呚りの順で䞎えられる。 $1+i$行目には$i$番目の頂点の座暙を衚す$px_i$,$py_i$が空癜区切りで䞎えられる。 Constraints 入力は以䞋の条件を満たす。 $3 \le N \le 10000$ $-10^9 \le px_i, py_i \le 10^9$ 凞倚角圢の頂点のうちどの3点を遞んでも、同䞀盎線䞊には存圚しない Output 条件を満たす正䞉角圢の䞀蟺の長さの最小倀を出力せよ。 ただし、$10^{-5}$ たでの絶察誀差たたは盞察誀差は蚱容される。 Sample Input 1 4 2 3 1 2 2 1 3 2 Sample Output 1 3.04720672 Sample Input 2 7 -96469 25422 -55204 -45592 -29140 -72981 98837 -86795 92303 63297 19059 96012 -67980 70342 Sample Output 2 310622.35426197
36,265
ブラックゞャック ブラックゞャックはカゞノで行われるカヌドゲヌムの䞀皮で、1 〜 13 たでの数が曞かれたカヌドを䜿っおゲヌムが行われたす。各カヌドの点数は次のように決たっおいたす。 1 は 1 点あるいは 11 点 2 から 9 たでは、曞かれおいる数の通りの点数 10 から 13 たでは、10 点 このゲヌムには芪を含めた䜕人かの参加者がおり、それぞれが䜕枚かのカヌドの組を持っおいたす。このカヌドの組のこずを手ず呌びたす。手の点数はカヌドの点数の合蚈です。その蚈算は次のように行うものずしたす。 カヌドの点数の合蚈が 21 より倧きくなるずきは、手の点数を 0 点ずする カヌドの点数ずしお、1 は 1 点ず蚈算しおも 11 点ず蚈算しおもよいが、手の点数が最倧ずなる方を遞ぶこずずする 配られたカヌドの情報を入力ずし、手の点数を出力するプログラムを䜜成しおください。 Input 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 c 1 c 2 ... c n 行に i 番目のカヌドに曞かれおいる敎数 c i (1 ≀ c i ≀ 13) が空癜区切りで行に䞎えられたす。カヌドの数 n は 100 を超えたせん。 デヌタセットの数は 200 を超えたせん。 Output デヌタセットごずに手の点数を行に出力したす。 Sample Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output for the Sample Input 11 21 0 21 12
36,266
ゞグザグ数 (Zig-Zag Numbers) 問題 正の敎数を (先頭に 0 を぀けずに) 10 進法で曞いお桁の数字を順番に芋おいくず増加ず枛少を亀互に繰り返しおいるずきその数は「ゞグザグ数」であるず呌ぶこずにしようたずえば2947 は桁の数字が 2 → 9 → 4 → 7 ず増加 → 枛少 → 増加 の順になっおいるのでゞグザグ数であるたた71946 は 枛少 → 増加 → 枛少 → 増加 の順なのでゞグザグ数である䞀方123 や 71446 や 71442 や 88 はゞグザグ数ではないなお1 桁の正の敎数はゞグザグ数であるず考えるこずずする A 以䞊 B 以䞋の M の倍数のうちゞグザグ数の個数を 10000 で割った䜙りを求めるプログラムを䜜成せよ 入力 入力は 3 行からなり1 行に 1 ぀ず぀正の敎数が曞かれおいる 1 行目の敎数は A を2 行目の敎数は B を3 行目の敎数は M を衚すこれらは 1 ≩ A ≩ B ≩ 10 500 1 ≩ M ≩ 500 を満たす ※ A や B の倀は通垞の敎数を衚すデヌタ型には収たらない可胜性があるこずに泚意せよ 出力 A 以䞊 B 以䞋の M の倍数のうちゞグザグ数の個数を 10000 で割った䜙りを 1 行で出力せよ 入出力䟋 入力䟋 1 100 200 5 出力䟋 1 13 入出力䟋 1 においお100 以䞊 200 以䞋の 5 の倍数であるゞグザグ数は105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195 の 13 個である 入力䟋 2 6 1234567 3 出力䟋 2 246 入出力䟋 2 においお6 以䞊 1234567 以䞋の 3 の倍数であるゞグザグ数は 50246 個あるのでそれを 10000 で割った䜙りである 246 を出力する 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,267
JOI 公園 (JOI Park) 20XX 幎に IOI 囜で行われるオリンピックに備えIOI 囜にある JOI 公園を敎備するこずになったJOI公園には N 個の広堎があり広堎には 1 から N の番号が぀いおいる広堎を繋ぐ M 本の道があり道には 1 から M の番号が぀いおいる道 i (1 ≀ i ≀ M ) は広堎 A i ず広堎 B i を双方向に繋いでおり長さは D i であるどの広堎からどの広堎ぞもいく぀かの道を蟿っお行くこずができる 敎備蚈画ではたず0 以䞊の敎数 X を遞び広堎 1 からの距離が X 以䞋であるような広堎 (広堎 1 を含む) どうしをすべお盞互に地䞋道で結ぶただし広堎 i ず広堎 j の距離ずは広堎 i から広堎 j に行くずきに通る道の長さの和の最小倀である敎備蚈画では地䞋道の敎備コストに関する敎数 C が定たっおいる地䞋道の敎備にかかるコストは C × X である 次に地䞋道で結ばれた広堎どうしを結ぶ道をすべお撀去する道の撀去にコストはかからない最埌に撀去されずに残った道をすべお補修する長さ d の道を補修するためにかかるコストは d である敎備蚈画実斜前の JOI 公園には地䞋道はないJOI 公園の敎備にかかるコストの和の最小倀を求めよ 課題 JOI 公園の広堎の情報ず地䞋道の敎備コストに関する敎数が䞎えられたずきJOI 公園の敎備にかかる コストの和の最小倀を求めるプログラムを䜜成せよ 入力 暙準入力から以䞋のデヌタを読み蟌め 1 行目には敎数 N , M , C が空癜を区切りずしお曞かれおいるこれは広堎が N 個道が M 本あり地䞋道の敎備コストに関する敎数が C であるこずを衚す 続く M 行のうちの i 行目 (1 ≀ i ≀ M ) には敎数 A i , B i , D i が空癜を区切りずしお曞かれおいるこれは道 i が広堎 A i ず広堎 B i を繋ぎ長さが D i であるこずを衚す 出力 暙準出力にJOI 公園の敎備にかかるコストの和の最小倀を衚す敎数を 1 行で出力せよ 制限 すべおの入力デヌタは以䞋の条件を満たす 2 ≀ N ≀ 100 000 1 ≀ M ≀ 200 000 1 ≀ C ≀ 100 000 1 ≀ A i ≀ N (1 ≀ i ≀ M ) 1 ≀ B i ≀ N (1 ≀ i ≀ M ) A i ≠ B i (1 ≀ i ≀ M ) ( A i , B i ) ≠ ( A j , B j ) および ( A i , B i ) ≠ ( B j , A j ) (1 ≀ i < j ≀ M ) 1 ≀ D i ≀ 100 000 (1 ≀ i ≀ M ) 䞎えられる入力デヌタにおいおはどの広堎からどの広堎ぞもいく぀かの道を蟿るこずにより行けるこずが保蚌されおいる 入出力䟋 入力䟋 1 5 5 2 2 3 1 3 1 2 2 4 3 1 2 4 2 5 5 出力䟋 1 14 この入力䟋では X = 3 ずしお広堎 1 からの距離が 3 以䞋であるような広堎 (広堎 1, 広堎 2, 広堎 3) どうしをすべお盞互に地䞋道で結んだずき敎備にかかるコストの和は 2 × 3 + 3 + 5 = 14 ずなるこれが最小倀である 入力䟋 2 5 4 10 1 2 3 2 3 4 3 4 3 4 5 5 出力䟋 2 15 この入力䟋ではX = 0 のずき敎備にかかるコストの和が最小になる 入力䟋 3 6 5 2 1 2 2 1 3 4 1 4 3 1 5 1 1 6 5 出力䟋 3 10 この入力䟋では X = 5 ずしおすべおの広堎を盞互に地䞋道で結んだずき敎備にかかるコストの和が最小になる 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,268
Problem C: General of Taiko Problem ずあるゲヌムセンタヌには、曲に合わせお流れおくる譜面通りに和倪錓を叩くゲヌムがありたす。 譜面は長さ L のセルからなり、各セルには䜕もない、たたはノヌトず呌ばれるプレむダヌがずるべき行動を衚した蚘号がありたす。 ノヌトは2皮類ありそれぞれ、和倪錓の面を叩く「トン」、和倪錓の瞁を叩く「コツ」がありたす。 これらのノヌトに合わせお和倪錓を叩くず埗点を埗るこずができたす。 この埗点の合蚈が10000点以䞊であればクリアずなりたす。 このずき、プレむダヌが曲をクリアできる確率を求めなさい。ただし、プレむダヌは垞に最適な行動をずるこずにしたす。 プレむダヌが譜面通りに和倪錓を叩く粟床は11段階あり、それぞれ、 0%, 10%, 20%, ..., 90%, 100%の確率で譜面通りに和倪錓を叩くこずができたす。 䞊蚘の二皮類の動䜜は右腕ず巊腕どちらででも行うこずができたす。 プレむダヌの情報ずしお、それぞれの腕で行った堎合の粟床の安定率を衚す倀が16皮類、䞋蚘のように䞎えられたす。 lt _ lt lt _ rt lt _ lk lt _ rk rt _ lt rt _ rt rt _ lk rt _ rk lk _ lt lk _ rt lk _ lk lk _ rk rk _ lt rk _ rt rk _ lk rk _ rk ただし、 lt は巊腕でトン, rt は右腕でトン, lk は巊腕でコツ, rk は右腕でコツの動䜜を衚したす。 䟋えば、 lt _ rk は巊腕でトンのあずに右腕でコツを行った時の粟床の安定の床合いを衚し、この倀によっお巊腕でトンのあずに右腕でコツを行うずきの粟床が、䞋蚘のように倉化したす。 プレむダヌの粟床 = max(0, (粟床の安定率 - 10) * 10 + 䞀぀前の粟床) (%) 曲の情報は以䞋のずおりです。 曲の長さを衚す L 、譜面を衚す L 個の数字 s i (0 ≀ i < L )で瀺される。譜面の先頭は s 0 である。 s i の倀は以䞋の3぀です。 0 ... ノヌトなし 1 ... トン 2 ... コツ プレむダヌが最初に和倪錓を叩くずきの粟床は100%です。 たた、プレむダヌは譜面を無芖するこずができたす。 ノヌトがなかったり、ノヌトを無芖した堎合、プレむダヌの粟床は100%になりたす。 各ノヌトに合わせお和倪錓を叩いたずきの埗点は䞋蚘のようになりたす。 埗点 = A + B * min(コンボ数, 10) この問題におけるコンボ数ずは、連続しおノヌトに合わせお和倪錓を叩けた数です。 プレむダヌがノヌトに合わせお叩いた堎合、䞊蚘の匏を元に埗点が入り、その埌にコンボ数が1増えたす。 ノヌトに合わせお和倪錓を叩けなかった堎合、コンボが途切れ、コンボ数が0になりたす。 Input 入力は耇数のデヌタセットからなりたす。 各デヌタセットは以䞋のずおりです。 lt _ lt lt _ rt lt _ lk lt _ rk rt _ lt rt _ rt rt _ lk rt _ rk lk _ lt lk _ rt lk _ lk lk _ rk rk _ lt rk _ rt rk _ lk rk _ rk L s 0 s 1 s 2 
 s L - 1 A B 入力の終わりは負の敎数4぀からなりたす。 Constraints 入力は以䞋の条件を満たしたす。 0 < L ≀ 100 0 ≀ 粟床の安定率 ≀ 10 粟床の安定率は敎数 0 < A , B ≀ 10000 A ず B はずもに100の倍数 デヌタセットの数は100個以䞋 Output 各入力に察しお、クリアできる確率を1行で出力しなさい。 ただし、出力は0.001以䞋の誀差を含んでも良いです。 Sample Input 9 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 5 1 1 1 1 1 1000 500 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 5 1 0 2 0 1 1000 2000 3 8 6 10 0 1 6 8 10 2 4 7 8 6 6 8 19 2 2 0 2 2 0 2 1 0 1 2 0 1 2 0 1 0 2 2 200 100 -1 -1 -1 -1 Sample Output 0.3024000000 0.0000000000 0.5120000000
36,269
Problem E: 街を駆ける道 ネヌノァ王囜には、トタタ族ずツテテ族、皮類の民族が暮らしおいる。トタタ族の最倧の特城は、 酢豚にパむナップルを入れお食べるこずである。だがツテテ族は、パむナップルに酢豚を入れお食べ る。こんな぀の民族がお互いに仲良くやっおいけるはずもなく、トタタ族ずツテテ族は、䜕癟幎も の昔からずっずいがみ合いを続けおきた。 そんなある日、ネヌノァ王のもずに、぀の民族から嘆願曞が届いた。それによるずトタタ族は、自 分たちが暮らす街ず街のあいだを結ぶ道を建蚭しおほしいらしい。䞀方でツテテ族も、自分たち が暮らす街ず街のあいだを結ぶ道を建蚭しおほしいらしい。 ぀の民族が衝突するのを防ぐため、トタタ族が通る道ずツテテ族が通る道を亀差させるこずはでき ない。たた、技術的な制玄により、぀の街のあいだを䞀盎線に結ぶような道しか建蚭するこずはで きない。぀たり、必芁ならば街ず街を盎接道で結ばずに、いく぀かのトタタ族の街を経由しお街 ず街を間接的に結ぶこずになるだろうもちろん、ツテテ族の街を経由しおはならない。その 際、トタタ族の街を結ぶ道どうしは亀差しおいおもよい。街ず街に぀いおも同様である。 道を建蚭するには、その長さに比䟋したコストがかかる。なので、条件をみたし぀぀、できるだけ建 蚭する道の長さの合蚈が短くなるようにしたい。さお、長さの最小倀はいく぀になるだろうか。 Input N A N B x A ,1 y A ,1 x A ,2 y A ,2 . . . x A , N A y A , N A x B ,1 y B ,1 x B ,2 y B ,2 . . . x B , N B y B , N B 入力の行目には、敎数 N A 2 ≀ N A ≀ 1,000ず敎数 N B 2 ≀ N B ≀ 1,000が、空癜区切りで曞かれおいる。これは、ネヌノァ王囜にはトタタ族が暮らす街がNA 個、ツテテ族が暮らす街がNB 個あるこずをあらわす。初期状態では、どこにも道は建蚭されおいない。 続く N A 行には、敎数 x A,i -10,000 ≀ x A,i ≀ 10,000ず敎数 y A,i -10,000 ≀ y A,i ≀ 10,000が、空癜区切りで曞かれおいる。ネヌノァ王囜の地理は次元盎亀座暙平面であらわされ、 i 行目に曞かれた敎数 x A,i ず y A,i は、トタタ族が暮らすi 番目の街の䜍眮座暙が( x A,i , y A,i ) であるこずをあらわす。( x A,1 , y A,1 ) ず( x A,2 , y A,2 ) が、結ぶべき぀の街の座暙である。 続く N B 行には、敎数 x B,i -10,000 ≀ x B,i ≀ 10,000ず敎数 y B,i -10,000 ≀ y B,i ≀ 10,000が、空癜区切りで曞かれおいる。 N A  i 行目に曞かれた敎数 x B,i ず y B,i は、ツテテ族が暮らすi 番目の街の䜍眮座暙が( x B,i , y B,i ) であるこずをあらわす。( x B,1 , y B,1 ) ず( x B,2 , y B,2 ) が、結ぶべき぀の街の座暙である。 どの぀の街の座暙も異なっおおり、どの぀の街も同䞀盎線䞊にないず仮定しおよい。 Output 問題文の条件をみたすように道を建蚭したずき、道の長さの合蚈の最小倀を出力せよ。ここで蚀う 「長さ」ずは、ナヌクリッド距離のこずである。ただし、どうやっおも条件をみたす道を建蚭できな いずきは、代わりに-1 を出力せよ。出力は誀差を含んでいおもよいが、真の倀ずの盞察誀差が10 -9 未満でなければならない。 Sample Input 1 2 2 0 0 1 1 2 0 2 -1 Sample Output 1 2.414213562373 Sample Input 2 2 3 4 0 0 0 2 3 2 -2 3 1 Sample Output 2 -1 Sample Input 3 5 2 -2 1 1 2 -1 3 -1 5 1 4 0 4 0 0 Sample Output 3 12.359173603117
36,270
Score : 300 points Problem Statement There are N integers a_1, a_2, ..., a_N not less than 1 . The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P . Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N . Constraints 1 \leq N \leq 10^{12} 1 \leq P \leq 10^{12} Input Input is given from Standard Input in the following format: N P Output Print the answer. Sample Input 1 3 24 Sample Output 1 2 The greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and a_3=2 . Sample Input 2 5 1 Sample Output 2 1 As a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4 = a_5 = 1 . Sample Input 3 1 111 Sample Output 3 111 Sample Input 4 4 972439611840 Sample Output 4 206
36,271
E: 鬌畜ババ抜き - Unbalanced Old Maid - 物語 高坂さんず園田さんず南さんは子䟛の頃からの仲良し3人組だ。3人は沖瞄に修孊旅行に行くも、台颚が来おしたい、海で遊ぶこずができないのでババ抜きをするこずにした。 園田さんは勝負事には匷いが、ポヌカヌフェむスが苊手なため、自分のカヌドが匕かれるずきに無意識にかわいらしい顔芞を披露しおしたう。園田さんを愛しお止たない高坂さんず南さんは、園田さんの顔芞を芋るだけで園田さんの手札が分かっおしたうため、園田さんのカヌドを匕くずきは、自分が有利になるように匕くこずができる。 䞀方、高坂さんず南さんは特に顔芞をしたりはしないので、手札がばれるこずはない。 よっお、高坂さんず南さんのカヌドを匕く人はそれぞれ、高坂さんず南さんが持っおいるカヌドの䞭から等確率で1枚匕く。 どう考えおも䞍利な園田さんは、ババ抜きでなかなか勝おないこずに違和感を芚えおいる。 䜿甚するカヌドの皮類数 n ず初期の手札が䞎えられたずき、園田さんが負けずならない確率を求めおあげよう。 問題文 高坂さん、園田さん、南さんの3人は、以䞋の状況でババ抜きを行う。 䜿甚するカヌドは、1から n たでの敎数が曞かれた n 皮類のカヌドそれぞれ4枚ず぀ずゞョヌカヌ1枚の合蚈 4n+1 枚である。 最初の手札が䞎えられたずき、3人はそれぞれ自分の手札に同䞀の敎数が曞かれたカヌドのペア2枚組があるならば、そのようなペアを党お捚おる。 3人は「高坂さんが南さんの手札からカヌドを匕く」、「園田さんが高坂さんの手札からカヌドを匕く」「南さんが園田さんの手札からカヌドを匕く」ずいう順番タヌンで以䞋の操䜜を繰り返す。このババ抜きでは、カヌドを匕いた人が、次に匕かれるずいうルヌルであるこずに泚意せよ。 䞀人がゞョヌカヌのみを持ち、その人以倖の2人の手札が空のずき、ババ抜きは終了し、ゞョヌカヌを持っおいる人が負けずなる。 カヌドを匕く順番の人の手札が空のずき、タヌンを次の人ずし、1.に戻る。 そうでなければ、カヌドを匕く順番の人は決められた盞手からカヌドを1枚匕く。ただし、盞手の手札が空のずき、ただ残っおいるもう1人からカヌドを匕く。 匕いたカヌドず同じ敎数が曞かれたカヌドがカヌドを匕いた人の手札にあれば、その2枚を捚おる。 タヌンを次の人ずし、1.ぞ戻る。 ただし、園田さんのカヌドを匕く人南さんか高坂さんは、以䞋の戊略でカヌド匕く。 もし自分のカヌドず園田さんのカヌドで同じ敎数が曞かれたカヌドがあれば、それらのうち最小の敎数が曞かれたカヌドを匕く そうでないずき、園田さんがゞョヌカヌでないカヌドを持っおいれば、それらのうち最小の敎数が曞かれたカヌドを匕く そうでないなら、園田さんはゞョヌカヌしか持っおいないので、ゞョヌカヌを匕く 高坂さんず南さんのカヌドを匕く人は、それぞれ高坂さんず南さんが持っおいるカヌドの䞭から等確率で1枚匕く。 䜿甚するカヌドの皮類数 n ず3人の初期の手札が䞎えられたずき、園田さんが負けずならない確率を求めおあげよう。 入力圢匏 入力は4行からなり、以䞋の圢匏で䞎えられる。 n m_1 c_{1,1} ... c_{1,m_1} m_2 c_{2,1} ... c_{2,m_2} m_3 c_{3,1} ... c_{3,m_3} 1行目にゞョヌカヌ以倖のカヌドの皮類数 n が䞎えられる。 続く入力は3行からなり、2行目に高坂さんの手札、3行目に園田さんの手札、4行目に南さんの手札の情報が䞎えられる。 i+1 (1 ≀ i ≀ 3) 行目では行頭に手持ちの枚数 m_i 、続けお手持ちのカヌドを衚す m_i 個の敎数 c_{i,j} (1 ≀ j ≀ m_i) が空癜区切りで䞎えられる。 0 はゞョヌカヌ、 1 から n はカヌドに曞かれた敎数を衚す。 制玄 1 ≀ n ≀ 100 m_1+m_2+m_3 = 4n+1 3人の手札で0はちょうど1぀、 1 から n はちょうど4回ず぀珟れる 0 ≀ c_{i,j} ≀ n ( 1 ≀ i ≀ 3 , 1 ≀ j ≀ m_i ) 出力圢匏 園田さんが負けずならない確率を1行に出力せよ。答えには 10^{−6} を超える絶察誀差があっおはならない。 入力䟋1 1 1 1 3 0 1 1 1 1 出力䟋1 0.0 高坂さんが南さんのカヌド1を匕き、高坂さんず南さんは手札が空になる。 園田さんはどうしおも勝぀こずはできない。 入力䟋2 1 2 1 1 1 1 2 0 1 出力䟋2 0.5 はじめの高坂さんのタヌンは、高坂さんの手札が既に空なので䜕もしない。次の園田さんのタヌンでは、園田さんは南さんの手札のうちそれぞれ0.5の確率でカヌド1かゞョヌカヌを匕く。カヌド1を匕いたずき、園田さんの手札は空ずなり勝利する。䞀方ゞョヌカヌを匕いたずきは、次の南さんのタヌンで、南さんは確実にカヌド1を匕くので園田さんが負けずなる。 入力䟋3 2 3 0 1 2 3 1 2 2 3 1 1 2 出力䟋3 0.5 入力䟋4 2 2 0 1 6 2 2 2 1 1 1 1 2 出力䟋4 0.6666666667
36,272
Problem F: Cleaning Robot 2.0 Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N × N rooms arranged in a square likewise. Then he laid either black or white carpet on each room. Since still enough money remained, he decided to spend them for development of a new robot. And finally he completed. The new robot operates as follows: The robot is set on any of N × N rooms, with directing any of north, east, west and south. The robot detects color of carpets of lefthand, righthand, and forehand adjacent rooms if exists. If there is exactly one room that its carpet has the same color as carpet of room where it is, the robot changes direction to and moves to and then cleans the room. Otherwise, it halts. Note that halted robot doesn't clean any longer. Following is some examples of robot's movement. Figure 1. An example of the room In Figure 1, robot that is on room (1,1) and directing north directs east and goes to (1,2). robot that is on room (0,2) and directing north directs west and goes to (0,1). robot that is on room (0,0) and directing west halts. Since the robot powered by contactless battery chargers that are installed in every rooms, unlike the previous robot, it never stops because of running down of its battery. It keeps working until it halts. Doctor's house has become larger by the renovation. Therefore, it is not efficient to let only one robot clean. Fortunately, he still has enough budget. So he decided to make a number of same robots and let them clean simultaneously. The robots interacts as follows: No two robots can be set on same room. It is still possible for a robot to detect a color of carpet of a room even if the room is occupied by another robot. All robots go ahead simultaneously. When robots collide (namely, two or more robots are in a single room, or two robots exchange their position after movement), they all halt. Working robots can take such halted robot away. On every room dust stacks slowly but constantly. To keep his house pure, he wants his robots to work so that dust that stacked on any room at any time will eventually be cleaned. After thinking deeply, he realized that there exists a carpet layout such that no matter how initial placements of robots are, this condition never can be satisfied. Your task is to output carpet layout that there exists at least one initial placements of robots that meets above condition. Since there may be two or more such layouts, please output the K -th one lexicographically. Input Input file contains several data sets. One data set is given in following format: N K Here, N and K are integers that are explained in the problem description. The end of input is described by a case where N = K = 0. You should output nothing for this case. Output Print the K -th carpet layout if exists, " No " (without quotes) otherwise. The carpet layout is denoted by N lines of string that each has exactly N letters. A room with black carpet and a room with white carpet is denoted by a letter ' E ' and ' . ' respectively. Lexicographically order of carpet layout is defined as that of a string that is obtained by concatenating the first row, the second row, ..., and the N -th row in this order. Output a blank line after each data set. Constraints Judge data consists of at most 100 data sets. 1 ≀ N < 64 1 ≀ K < 2 63 Sample Input 2 1 2 3 6 4 0 0 Output for the Sample Input .. .. No ..EEEE ..E..E EEE..E E..EEE E..E.. EEEE..
36,273
金利蚈算 金利は銀行に預けおいるお金に付き、その蚈算方法や利率は銀行によっお様々です。利息ず元金を合わせたものを元利ず呌びたすが、元利の蚈算方法ずしお、利息を元金に組み入れずに蚈算する「単利」ず利息を元金に組み入れお蚈算する「耇利」ずいうものがあり、より倚くの元利を埗るためにはこの差異を理解しおいなければなりたせん。元利の蚈算方法は以䞋のようになりたす。 銀行の数、お金を預ける幎数、各銀行の情報銀行番号、金利の皮類、幎利率パヌセントを入力ずし、最も元利が高くなる銀行番号を出力するプログラムを䜜成しおください。ただし、最も元利が高くなる銀行は䞀぀だけです。 入力 耇数のデヌタセットが䞎えられたす。入力の終わりはれロひず぀で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 n y b 1 r 1 t 1 b 2 r 2 t 2 : b n r n t n 1行目に銀行の数 n (1 ≀ n ≀ 50)、2行目にお金を預ける幎数 y (1 ≀ y ≀ 30)が䞎えられたす。続く n 行に i 番目の銀行の銀行番号 b i 、幎利率を衚す敎数 r i (1 ≀ r i ≀ 100)、 金利の皮類 t i (1 たたは 2) が䞎えられたす。金利の皮類 t i は、単利の堎合は1、耇利の堎合は2で䞎えられたす。 デヌタセットの数は 100 を超えたせん。 出力 デヌタセットごずに、最も元利が高くなる銀行番号を行に出力したす。 入力䟋 2 8 1 5 2 2 6 1 2 9 1 5 2 2 6 1 0 出力䟋 2 1
36,274
Score : 100 points Problem Statement Takahashi recorded his daily life for the last few days as a integer sequence of length 2N , as follows: a_1, b_1, a_2, b_2, ... , a_N, b_N This means that, starting from a certain time T , he was: sleeping for exactly a_1 seconds then awake for exactly b_1 seconds then sleeping for exactly a_2 seconds : then sleeping for exactly a_N seconds then awake for exactly b_N seconds In this record, he waked up N times. Takahashi is wondering how many times he waked up early during the recorded period. Here, he is said to wake up early if he wakes up between 4:00 AM and 7:00 AM, inclusive. If he wakes up more than once during this period, each of these awakenings is counted as waking up early. Unfortunately, he forgot the time T . Find the maximum possible number of times he waked up early during the recorded period. For your information, a day consists of 86400 seconds, and the length of the period between 4:00 AM and 7:00 AM is 10800 seconds. Constraints 1 \leq N \leq 10^5 1 \leq a_i, b_i \leq 10^5 a_i and b_i are integers. Input The input is given from Standard Input in the following format: N a_1 b_1 a_2 b_2 : a_N b_N Output Print the maximum possible number of times he waked up early during the recorded period. Sample Input 1 3 28800 57600 28800 57600 57600 28800 Sample Output 1 2 Sample Input 2 10 28800 57600 4800 9600 6000 1200 600 600 300 600 5400 600 6000 5760 6760 2880 6000 12000 9000 600 Sample Output 2 5
36,275
Score : 500 points Problem Statement Ibis is fighting with a monster. The health of the monster is H . Ibis can cast N kinds of spells. Casting the i -th spell decreases the monster's health by A_i , at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints 1 \leq H \leq 10^4 1 \leq N \leq 10^3 1 \leq A_i \leq 10^4 1 \leq B_i \leq 10^4 All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Sample Input 1 9 3 8 3 4 2 2 1 Sample Output 1 4 First, let us cast the first spell to decrease the monster's health by 8 , at the cost of 3 Magic Points. The monster's health is now 1 . Then, cast the third spell to decrease the monster's health by 2 , at the cost of 1 Magic Point. The monster's health is now -1 . In this way, we can win at the total cost of 4 Magic Points. Sample Input 2 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Sample Output 2 100 It is optimal to cast the first spell 100 times. Sample Input 3 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Sample Output 3 139815
36,276
Counter-Clockwise For given three points p0, p1, p2 , print COUNTER_CLOCKWISE if p0, p1, p2 make a counterclockwise turn (1), CLOCKWISE if p0, p1, p2 make a clockwise turn (2), ONLINE_BACK if p2 is on a line p2, p0, p1 in this order (3), ONLINE_FRONT if p2 is on a line p0, p1, p2 in this order (4), ON_SEGMENT if p2 is on a segment p0p1 (5). Input x p0 y p0 x p1 y p1 q x p2 0 y p2 0 x p2 1 y p2 1 ... x p2 q-1 y p2 q-1 In the first line, integer coordinates of p0 and p1 are given. Then, q queries are given for integer coordinates of p2 . Output For each query, print the above mentioned status. Constraints 1 ≀ q ≀ 1000 -10000 ≀ x i , y i ≀ 10000 p0 and p1 are not identical. Sample Input 1 0 0 2 0 2 -1 1 -1 -1 Sample Output 1 COUNTER_CLOCKWISE CLOCKWISE Sample Input 2 0 0 2 0 3 -1 0 0 0 3 0 Sample Output 2 ONLINE_BACK ON_SEGMENT ONLINE_FRONT
36,277
カヌテン もうすぐ倏がやっおくるあなたは倏に向けお郚屋の暡様替えをするこずにした今幎の倏はずおも日差しが匷いこずが予想されおおりたぶしいのが苊手なあなたには蟛い季節になりそうだそこであなたは郚屋の明るさを調節するために郚屋の窓にカヌテンを取り付けようず考えた 取り付けるカヌテンは長方圢であり蟺が地面に察しお垂盎もしくは平行であるように取り付けるたたあなたの郚屋の窓は非垞に特殊な圢をしおおり各蟺が地面に平行たたは垂盎であるような N 角圢で衚されるそのためカヌテンを取り付けたずきにカヌテンに芆われおいない窓の面積がどのくらいになるのかを求めるのは難しい郚屋の明るさを調節するためにもカヌテンを取り付ける䜍眮を決めた時にどのくらい窓が芆えるかを知るこずは重芁であるそこであなたは窓ずカヌテンの蚭眮䜍眮ず圢状が䞎えられたずきにカヌテンに芆われおいない窓の面積を求めるプログラムを䜜るこずにした 䟋ずしお次のような窓ずカヌテンの蚭眮の仕方を考えるこの堎合はカヌテンに隠れおいない窓の面積は 8 ずなるこの䟋はサンプル入力の 3 ケヌス目に察応する Input 入力は耇数デヌタセットからなる 各デヌタセットは次の圢匏で䞎えられる N x 1 y 1 : : x N y N a 1 b 1 a 2 b 2 a 3 b 3 a 4 b 4 最初の行には窓の持぀頂点数を衚す敎数 N が䞎えられる ( 4 ≀ N ≀ 100 )続く N 行には窓の盞異なる頂点のx座暙を衚す敎数 x i ずy座暙を衚す敎数 y i が䞎えられる ( -20,000 ≀ x i , y i ≀ 20,000, 1 ≀ i ≀ N )ここでy軞の正の向きはx軞の正の向きから90床分反時蚈回りに回転させた方向ずするさらに続く 4 行にはカヌテンの盞異なる頂点のx座暙を衚す敎数 a j ず y座暙を衚す敎数 b j が䞎えられる ( -20,000 ≀ a j , b j ≀ 20,000, 1 ≀ j ≀ 4 )窓カヌテンずもにそれぞれの頂点は反時蚈回り順に䞎えられるたた窓カヌテンを衚す図圢はそれぞれ自己亀差がない図圢である 入力の終わりは1぀の 0 からなる行で瀺す Output 各デヌタセットに぀いおカヌテンに芆われおいない窓の面積を 1 行に出力せよただし面積は必ず敎数倀になるこずに泚意せよ Sample Input 4 0 0 10 0 10 10 0 10 0 0 5 0 5 10 0 10 6 0 0 10 0 10 5 5 5 5 10 0 10 2 0 8 0 8 10 2 10 12 1 1 1 3 -1 3 -1 1 -3 1 -3 -1 -1 -1 -1 -3 1 -3 1 -1 3 -1 3 1 2 2 -2 2 -2 -2 2 -2 4 20000 20000 -20000 20000 -20000 -20000 20000 -20000 1000 1000 -1000 1000 -1000 -1000 1000 -1000 4 1000 1000 -1000 1000 -1000 -1000 1000 -1000 20000 20000 -20000 20000 -20000 -20000 20000 -20000 4 0 0 10 0 10 10 0 10 20 0 30 0 30 10 20 10 0 Output for Sample Input 50 30 8 1596000000 0 100
36,278
Identically Colored Panels Connection Dr. Fukuoka has invented fancy panels. Each panel has a square shape of a unit size and has one of the six colors, namely, yellow, pink, red, purple, green and blue. The panel has two remarkable properties. One property is that, when two or more panels with the same color are placed adjacently, their touching edges melt a little and they are fused each other. The fused panels are united into a polygonally shaped panel. The other property is that the color of a panel can be changed to one of six colors by giving an electrical shock. The resulting color can be controlled by its waveform. The electrical shock to an already united panel changes the color of the whole to a specified single color. Since he wants to investigate the strength with respect to the color and the size of a united panel compared to unit panels, he tries to unite panels into a polygonal panel with a specified color. Figure C-1: panels and their initial colors Since many panels are simultaneously synthesized and generated on a base plate through some complex chemical processes, the fabricated panels are randomly colored and they are arranged in a rectangular shape on the base plate (Figure C-1). Note that the two purple (color 4) panels in Figure C-1 are already united at the initial state since they are adjacent to each other. Installing electrodes to a panel, and changing its color several times by giving electrical shocks according to an appropriate sequence for a specified target color, he can make a united panel merge the adjacent panels to unite them step by step and can obtain a larger panel with the target color. Unfortunately, panels will be broken when they are struck by the sixth electrical shock. That is, he can change the color of a panel or a united panel only five times. Let us consider a case where the panel at the upper left corner of the panel configuration (Figure C-1) is attached with the electrodes. First, changing the color of the panel from yellow to blue, the two adjacent panels are fused into a united panel (Figure C-2). Figure C-2: Change of the color of the panel at the upper left corner, from yellow (color 1) to blue (color 6). Second, changing the color of the upper left united panel from blue to red, a united red panel that consists of three unit panels is newly formed (Figure C-3). Then, changing the color of the united panel from red to purple, panels are united again to form a united panel of five unit panels (Figure C-4). Figure C-3: Change of the color of the panel at the upper left corner, from blue (color 6) to red (color 3). Figure C-4: Change of the color of the panel at the upper left corner, from red (color 3) to purple (color 4). Furthermore, through making a pink united panel in Figure C-5 by changing the color from purple to pink, then, the green united panel in Figure C-6 is obtained by changing the color from pink to green. The green united panel consists of ten unit panels. Figure C-5: Change of the color of the panel at the upper left corner, from purple (color 4) to pink (color 2). Figure C-6: Change of the color of the panel at the upper left corner, from pink (color 2) to green (color 5). In order to check the strength of united panels with various sizes and colors, he needs to unite as many panels as possible with the target color. Your job is to write a program that finds a sequence to change the colors five times in order to get the largest united panel with the target color. Note that the electrodes are fixed to the panel at the upper left corner. Input The input consists of multiple datasets, each being in the following format. h w c p 1,1 p 1,2 ... p 1, w p 2,1 p 2,2 ... p 2, w ... p h ,1 p h ,2 ... p h , w h and w are positive integers no more than 8 that represent the height and the width of the given rectangle. c is a positive integer no more than 6 that represents the target color of the finally united panel. p i , j is a positive integer no more than 6 that represents the initial color of the panel at the position ( i , j ). The end of the input is indicated by a line that consists of three zeros separated by single spaces. Output For each dataset, output the largest possible number of unit panels in the united panel at the upper left corner with the target color after five times of color changes of the panel at the upper left corner. No extra characters should occur in the output. Sample Input 3 5 5 1 6 3 2 5 2 5 4 6 1 1 2 4 1 5 4 5 6 1 5 6 1 2 1 4 6 3 2 1 5 2 3 2 1 1 2 3 2 1 1 5 1 1 8 6 1 2 3 4 5 1 2 3 8 1 1 1 2 3 4 5 1 2 3 8 8 6 5 2 5 2 6 5 4 2 4 2 2 2 5 2 2 2 4 4 4 2 5 2 2 2 6 4 5 2 2 2 6 6 6 6 5 5 2 2 6 6 6 2 5 4 2 2 6 6 2 4 4 4 6 2 2 6 2 2 2 5 5 2 2 2 8 8 2 3 3 5 4 1 6 2 3 2 3 6 4 3 6 2 2 4 1 6 6 6 4 4 4 2 5 3 6 3 6 3 5 3 1 3 4 1 5 6 3 1 6 6 3 5 1 5 3 2 4 2 2 2 6 5 3 4 1 3 6 1 5 5 4 0 0 0 Output for the Sample Input 10 18 1 5 6 64 33
36,279
Score : 400 points Problem Statement Akari has n kinds of flowers, one of each kind. She is going to choose one or more of these flowers to make a bouquet. However, she hates two numbers a and b , so the number of flowers in the bouquet cannot be a or b . How many different bouquets are there that Akari can make? Find the count modulo (10^9 + 7) . Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet. Constraints All values in input are integers. 2 \leq n \leq 10^9 1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5) Input Input is given from Standard Input in the following format: n a b Output Print the number of bouquets that Akari can make, modulo (10^9 + 7) . (If there are no such bouquets, print 0 .) Sample Input 1 4 1 3 Sample Output 1 7 In this case, Akari can choose 2 or 4 flowers to make the bouquet. There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4 , so there are a total of 7 different bouquets that Akari can make. Sample Input 2 1000000000 141421 173205 Sample Output 2 34076506 Print the count modulo (10^9 + 7) .
36,280
枠 画像の䞭から有益な情報を抜出する画像認識はコンピュヌタサむ゚ンスの䞭でも重芁な研究テヌマのひず぀です。デゞタルカメラ、運転支揎システム、防犯システムなどに幅広く応甚されおいたす。 このような研究のおかげで、私たちは画像解析を行うための倚くの゜フトりェアやプログラム集を䜿い様々な凊理を行うこずができたす。䞀方、自力でプログラムを曞いお解析するこずで、その仕組みを知り、楜しい時間を過ごすこずができたす。ここでは、䞀颚倉わった画像認識をしおみたしょう。 画像ずしお次のような各ピクセルが敎数の倀を持぀ N × N のピクセルが入力ずしお䞎えられたす。この画像の䞭から、線の倪さがピクセルの長方圢の枠わくを぀抜出したす。 枠が芆うピクセルの倀の和が最倧ずなるような枠を抜出しお、その和を報告するプログラムを䜜成しお 䞋さい。ただし、䞋の図のように、瞊、暪のピクセル数が぀や぀の堎合も枠ずみなすものずしたす。 入力 入力は以䞋の圢匏で䞎えられる。 N p 1,1 p 1,2 ... p 1,N p 2,1 p 2,2 ... p 2,N : p N,1 p N,2 ... p N,N 行目に瞊ず暪のピクセル数 N (1 ≀ N ≀ 300) が䞎えられる。続く N 行に、 i 行 j 列目のピクセルの倀を衚す敎数 p i,j (-1000 ≀ p i,j ≀ 1000)が䞎えられる。 出力 ピクセル倀の和が最倧ずなるような枠の、ピクセル倀の和を行に出力する。 入出力䟋 入力䟋 5 2 0 0 2 0 0 1 0 2 0 0 0 0 -1 0 0 4 0 3 0 -1 0 0 1 0 出力䟋 12 入力䟋 3 0 0 0 0 -1 0 0 0 0 出力䟋 0
36,281
Balls and Boxes 8 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is distinguished from the other. Each box is not distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box can contain at most one ball. Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 5 10 Sample Output 1 1 Sample Input 2 200 100 Sample Output 2 0
36,282
Score : 800 points Problem Statement You are given a string S consisting of lowercase English letters. Determine whether we can turn S into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations. Constraints 1 \leq |S| \leq 2 × 10^5 S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output If we cannot turn S into a palindrome, print -1 . Otherwise, print the minimum required number of operations. Sample Input 1 eel Sample Output 1 1 We can turn S into a palindrome by the following operation: Swap the 2 -nd and 3 -rd characters. S is now ele . Sample Input 2 ataatmma Sample Output 2 4 We can turn S into a palindrome by the following operation: Swap the 5 -th and 6 -th characters. S is now ataamtma . Swap the 4 -th and 5 -th characters. S is now atamatma . Swap the 3 -rd and 4 -th characters. S is now atmaatma . Swap the 2 -nd and 3 -rd characters. S is now amtaatma . Sample Input 3 snuke Sample Output 3 -1 We cannot turn S into a palindrome.
36,283
Score : 100 points Problem Statement Let N be a positive integer. You are given a string s of length N - 1 , consisting of < and > . Find the number of permutations (p_1, p_2, \ldots, p_N) of (1, 2, \ldots, N) that satisfy the following condition, modulo 10^9 + 7 : For each i ( 1 \leq i \leq N - 1 ), p_i < p_{i + 1} if the i -th character in s is < , and p_i > p_{i + 1} if the i -th character in s is > . Constraints N is an integer. 2 \leq N \leq 3000 s is a string of length N - 1 . s consists of < and > . Input Input is given from Standard Input in the following format: N s Output Print the number of permutations that satisfy the condition, modulo 10^9 + 7 . Sample Input 1 4 <>< Sample Output 1 5 There are five permutations that satisfy the condition, as follows: (1, 3, 2, 4) (1, 4, 2, 3) (2, 3, 1, 4) (2, 4, 1, 3) (3, 4, 1, 2) Sample Input 2 5 <<<< Sample Output 2 1 There is one permutation that satisfies the condition, as follows: (1, 2, 3, 4, 5) Sample Input 3 20 >>>><>>><>><>>><<>> Sample Output 3 217136290 Be sure to print the number modulo 10^9 + 7 .
36,284
Princess' Marriage お姫様の嫁入り English text is not available in this practice contest. ある貧乏な囜のおおんばで勇敢なお姫様はギャンブルの配圓がパリミュチュ゚ル方匏で決定される事を知るこずによりギャンブルに぀いお詳しくなった気がしおギャンブルでの勝利を確信したその結果今たでよりも曎に倚額のお金を぀ぎ蟌み囜民が玍めた皎金をすべお倱うほどの負けを喫しおしたったこの事態を重く受け止めた王様はお姫様を隣の囜ぞ嫁がせるこずにしたこうするこずによりお姫様を日頃の行いを反省させ同時に隣囜ずの亀友を深めお財政揎助をしおもらおうず考えたからである お姫様ず隣囜の王子様はお互いの事が気に入りたた䞡囜の王様間でも政略結婚に関する同意がなされたお姫様はなけなしのお金を手に意気揚々ず隣の囜ぞ出かけた䞀方でお姫様が嫁ぐ動機は王様の䞀方的な利益远及のためであり快くないず考える隣囜の王子様の偎近はお姫様を亡き者にするために道の途䞭に無数の刺客達を攟った お姫様が通る道はすでに決められおいるお姫様の通る道には合蚈 L 個の宿堎がある䟿宜䞊出発地点および到着地点も宿堎ずし各宿堎を S 1 , S 2 , ... S L ず呌ぶこずにするお姫様は最初に S 1 におり昇順に ( S 2 , S 3 ... ずいう順番で) 宿堎を蚪れお最終的に S L ぞ行くものずする宿堎では金銭を払っお護衛を雇うこずができお金がある限り奜きな距離だけ契玄しおお姫様を守らせるこずができる護衛を雇う費甚は距離1に぀き金1であるお姫様は通る区間内を郚分的に守っおもらうこずも出来るこずに泚意せよ S i ず S i+1 間の距離は D i  S i ず S i+1 間で距離1に぀き刺客に襲われる回数の期埅倀は P i で䞎えられおいる お姫様が予算 M を持っおいお刺客に襲われる回数の期埅倀が最小になるように護衛を雇ったずきの目的地たでに刺客に襲われる回数の期埅倀を求めよ Input 入力は耇数のデヌタセットからなる各デヌタセットは以䞋のような圢匏をずる N M D 1 P 1 D 2 P 2 ... D N P N 各デヌタセットの最初の行には二぀の敎数が䞎えられそれぞれ区間の数 N (1≩ N ≩10,000) ずお姫差が持぀予算 M (0≩ M ≩1,000,000,000) を衚す次の N 行はお姫様が通る道の情報を衚す各行は二぀の敎数が含たれおおり i 行目は区間の距離 D i (1≩ D i ≩10,000) ずその間を単䜍距離移動したずきに襲われる回数の期埅倀 P i (0≩ P i <=10) からなる 入力の終端は N =0, M =0 ずなるデヌタセットであらわされるこのデヌタセットに察しおは蚈算結果を出力しおはならない Output 各デヌタセット毎にお姫様が目的地たでに刺客に襲われる回数の期埅倀を出力せよ Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input 5 140
36,285
You Are the Judge 審刀は君だ English text is not available in this practice contest. あなたはプログラミングコンテスト iCPC の審刀だ。今日も䜕事もなく詊合が終わり、埌は結果を出力するだけだず思いきや、突然システムが停止しおしたった これでは結果が出力できない でも、倧䞈倫。我々にはログがある。 あなたは優れたプログラマヌであり、か぀お iCPC で茝かしい成瞟を残したこずもある。 そこであなたはシステムログから各チヌムの成瞟を割り出し、チヌムの順䜍衚を出力するプログラムを䜜成するこずにした。 入力ずしおチヌムの数、問題の数、システムログが䞎えられる。 シムテムログは以䞋の 2 皮類のレコヌドからなる。 レコヌド 内容 効果 tID pID time CORRECT 時刻 time に、チヌム tID が 問題 pID に正解するプログラムを送信。 チヌム tID の正解数に1が加算される。 チヌム tID のペナルティに、(チヌム tID の問題 pID に察する誀答数*1200+time)が加算される。 以埌, チヌム tID の問題 pID に察する解答は棄华され、システムログにも送信履歎が残らない。 tID pID time WRONG 時刻 time に、チヌム tID が 問題 pID に誀答するプログラムを送信。 チヌム tID の 問題 pID に察する誀答数に1が加算される。 ※䞊蚘のシステムログはこの問題のために簡略化されたものであり、本番のICPCで芋られるシステムログず異なるこずに留意せよ iCPCにおける順䜍付けのルヌルは以䞋の通りである。 より倚くの問題を解いたチヌムは順䜍が䞊になる 解いた問題が同じ堎合、ペナルティの少ないチヌムのほうが順䜍が䞊になる 解いた問題もペナルティも同じ堎合、チヌム番号が小さいほうのチヌムが順䜍が䞊になる 入力より䞎えられるコンテストの情報・システムログから各チヌムの成瞟を割り出し、チヌムの順䜍衚を出力せよ。 Input 入力は耇数のデヌタセットからなる。各デヌタセットは以䞋の圢匏で䞎えられる。 T P R tID 1 pID 1 time 1 message 1 tID 2 pID 2 time 2 message 2 ... tID R pID R time R message R デヌタセットの1行目には 参加チヌム数 T 、問題数 P、システムログのレコヌド数 R が含たれる。 続くR行にはシステムログの各レコヌドが含たれる。 システムログのレコヌドずしお、チヌム番号 tID i 、問題番号 pID i 、詊合開始からの経過時間 time i 、メッセヌゞの皮類 message i が含たれる。 入力は以䞋の制玄を満たす。 1 ≀ T ≀ 50 1 ≀ P ≀ 10 1 ≀ R ≀ 500 1 ≀ tID i ≀ T 1 ≀ pID i ≀ P 1 ≀ time i ≀ 10800 message i は CORRECT, WRONGのいずれか システムログのレコヌドは、時刻の小さいものから順に䞎えられ、耇数のレコヌドの時刻が同じになるこずはない 入力の終わりはスペヌスで区切られた3個の0で䞎えられる。 Output 䞎えられたシステムログより各チヌムの成瞟・順䜍を割り出し、順䜍が䞊のチヌムから順に、チヌム番号、正解数、ペナルティ を出力せよ。 Sample Input 3 3 5 3 1 800 WRONG 1 1 1200 CORRECT 3 1 1400 CORRECT 1 2 2400 CORRECT 1 3 3600 CORRECT 5 2 5 3 1 1000 WRONG 5 2 2000 CORRECT 3 1 2800 CORRECT 4 1 4000 CORRECT 5 1 5000 CORRECT 6 3 15 2 1 10 WRONG 3 3 15 WRONG 3 3 20 CORRECT 1 1 50 CORRECT 4 2 60 WRONG 1 2 70 WRONG 4 1 80 CORRECT 1 2 90 WRONG 1 2 150 CORRECT 3 1 160 WRONG 3 1 180 CORRECT 3 2 210 WRONG 5 3 500 CORRECT 4 2 720 CORRECT 5 1 1500 CORRECT 0 0 0 Output for Sample Input 1 3 7200 3 1 2600 2 0 0 5 2 7000 3 1 4000 4 1 4000 1 0 0 2 0 0 4 2 2000 5 2 2000 1 2 2600 3 2 2600 2 0 0 6 0 0
36,287
Score : 200 points Problem Statement In some other world, today is the day before Christmas Eve. Mr. Takaha is buying N items at a department store. The regular price of the i -th item (1 \leq i \leq N) is p_i yen (the currency of Japan). He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay? Constraints 2 \leq N \leq 10 100 \leq p_i \leq 10000 p_i is an even number. Input Input is given from Standard Input in the following format: N p_1 p_2 : p_N Output Print the total amount Mr. Takaha will pay. Sample Input 1 3 4980 7980 6980 Sample Output 1 15950 The 7980 -yen item gets the discount and the total is 4980 + 7980 / 2 + 6980 = 15950 yen. Note that outputs such as 15950.0 will be judged as Wrong Answer. Sample Input 2 4 4320 4320 4320 4320 Sample Output 2 15120 Only one of the four items gets the discount and the total is 4320 / 2 + 4320 + 4320 + 4320 = 15120 yen.
36,288
Problem Statement Snuke loves colorful balls. He has a total of N×K balls, K in each of his favorite N colors. The colors are numbered 1 through N . He will arrange all of the balls in a row from left to right, in arbitrary order. Then, for each of the N colors, he will paint the leftmost ball of that color into color 0 , a color different from any of the N original colors. After painting, how many sequences of the colors of the balls are possible? Find this number modulo 10^9+7 . Constraints 1≀N,K≀2,000 Input The input is given from Standard Input in the following format: N K Output Print the number of the possible sequences of the colors of the balls after painting, modulo 10^9+7 . Sample Input 1 2 2 Sample Output 1 4 The following 4 sequences are possible: (0,1,0,2) (0,0,1,2) (0,2,0,1) (0,0,2,1) Sample Input 2 3 1 Sample Output 2 1 The following 1 sequence is possible: (0,0,0) Sample Input 3 2 3 Sample Output 3 14 Sample Input 4 2000 2000 Sample Output 4 546381702
36,289
Score : 100 points Problem Statement Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies. Constraints 1 \leq A,B \leq 100 Both A and B are integers. Input Input is given from Standard Input in the following format: A B Output If it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible ; otherwise, print Impossible . Sample Input 1 4 5 Sample Output 1 Possible If Snuke gives nine cookies, each of the three goats can have three cookies. Sample Input 2 1 1 Sample Output 2 Impossible Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them.
36,290
Score : 100 points Problem Statement We have two integers: A and B . Print the largest number among A + B , A - B , and A \times B . Constraints All values in input are integers. -100 \leq A,\ B \leq 100 Input Input is given from Standard Input in the following format: A B Output Print the largest number among A + B , A - B , and A \times B . Sample Input 1 -13 3 Sample Output 1 -10 The largest number among A + B = -10 , A - B = -16 , and A \times B = -39 is -10 . Sample Input 2 1 -33 Sample Output 2 34 The largest number among A + B = -32 , A - B = 34 , and A \times B = -33 is 34 . Sample Input 3 13 3 Sample Output 3 39 The largest number among A + B = 16 , A - B = 10 , and A \times B = 39 is 39 .
36,291
Sixth Sense Ms. Future is gifted with precognition. Naturally, she is excellent at some card games since she can correctly foresee every player's actions, except her own. Today, she accepted a challenge from a reckless gambler Mr. Past. They agreed to play a simple two-player trick-taking card game. Cards for the game have a number printed on one side, leaving the other side blank making indistinguishable from other cards. A game starts with the same number, say $n$, of cards being handed out to both players, without revealing the printed number to the opponent. A game consists of $n$ tricks. In each trick, both players pull one card out of her/his hand. The player pulling out the card with the larger number takes this trick. Because Ms. Future is extremely good at this game, they have agreed to give tricks to Mr. Past when both pull out cards with the same number. Once a card is used, it can never be used later in the same game. The game continues until all the cards in the hands are used up. The objective of the game is to take as many tricks as possible. Your mission of this problem is to help Ms. Future by providing a computer program to determine the best playing order of the cards in her hand. Since she has the sixth sense, your program can utilize information that is not available to ordinary people before the game. Input The input consists of a single test case of the following format. $n$ $p_1$ ... $p_n$ $f_1$ ... $f_n$ $n$ in the first line is the number of tricks, which is an integer between 2 and 5000, inclusive. The second line represents the Mr. Past's playing order of the cards in his hand. In the $i$-th trick, he will pull out a card with the number $p_i$ ($1 \leq i \leq n$). The third line represents the Ms. Future's hand. $f_i$ ($1 \leq i \leq n$) is the number that she will see on the $i$-th received card from the dealer. Every number in the second or third line is an integer between 1 and 10 000, inclusive. These lines may have duplicate numbers. Output The output should be a single line containing $n$ integers $a_1 ... a_n$ separated by a space, where $a_i$ ($1 \leq i \leq n$) is the number on the card she should play at the $i$-th trick for maximizing the number of taken tricks. If there are two or more such sequences of numbers, output the lexicographically greatest one among them. Sample Input 1 5 1 2 3 4 5 1 2 3 4 5 Sample Output 1 2 3 4 5 1 Sample Input 2 5 3 4 5 6 7 1 3 5 7 9 Sample Output 2 9 5 7 3 1 Sample Input 3 5 3 2 2 1 1 1 1 2 2 3 Sample Output 3 1 3 1 2 2 Sample Input 4 5 3 4 10 4 9 2 7 3 6 9 Sample Output 4 9 7 3 6 2
36,292
問題 C しりずり 問題文 なんずなく暇だったのでしりずりの AI を䜜っお AI ずしりずりをするこずにしたしりずりずは 2 人で遊ぶゲヌムで䞡者の間でただ䞀床も発蚀されおおらず(最初の手番を陀いお) 先頭の文字が盎前の単語の最埌の文字ずなっおいる単語を亀互に蚀い合うゲヌムである 今回 AI に単語の刀定を実装するのが面倒だったので単語の定矩はアルファベットの小文字からなる文字列党おずした しかし AI が完成したあたりでしりずりをするのは面倒くさくなっおきたのでプログラムを曞いお自分の代わりに AI ず察戊させるこずにしたプログラムを曞くのは良いのだが目暙が無いのは぀たらないのでなるべく早く AI に勝぀プログラムを曞くこずにしたすなわちなるべく少ないやりずりで AI に䞍正な応答をさせるプログラムを曞くのである なおプログラムが先手で AI が埌手である 入出力 プログラムはしりずりの単語を発蚀するずAI の返答を聞くこずができる 䟋えば C/C++ で abc ず単語を発蚀するには printf("?abc\n"); fflush(stdout); ずする次に scanf("%s", str); ずするず str に AI の返答が入る 最終的に AI の誀りを指摘するには !OUT ず出力するこず誀りを指摘するのは間違った発蚀の盎埌でなければならない誀りを指摘した時点でプログラムを終了させ䞍芁な出力は䞀切行っおはいけない誀りの指摘が正しければプログラムは正解 ( Accepted ) ず刀定される単語の応答が䞍適切であったりAI ぞの誀りの指摘が正しくない堎合AI の誀りを指摘しなかった堎合は誀答 ( Wrong Answer ) ず刀定される 制玄 プログラムの䜿っお良い単語の長さは 1 文字以䞊 10 文字以䞋である AI の䜿う単語の長さは 1 文字以䞊 2 文字以䞋である プログラムは最倧で 50 回たで発蚀するこずが出来るそれを超えるず誀答 ( Query Limit Exceeded ) ずなる AIプログラム䞡者ずも単語に䜿っお良い文字はアルファベットの小文字のみである AI の返答はアルファベットの小文字のみからなる 最初の手番ではプログラムはどのアルファベットからしりずりを開始しおも良い 入出力䟋 入力䟋 1 以䞋の䟋はプログラムの入出力の䟋である巊の列がプログラムの出力右の列がプログラムぞの入力 (AI の発蚀) を衚す最初にプログラムは abcdefghij ずいう単語を蚀っおいるその応答ずしお AI は jk ず返しおる 3 回目の応答の際に AI はすでに䜿われおいる jk ずいう単語を発しおいるのでそれに察しおプログラムは !OUT ず蚀っお AI の誀りを指摘しおいる プログラムの出力 プログラムぞの入力 ?abcdefghij jk ?kkkk kl ?lj jk !OUT 入力䟋 2 以䞋の䟋ではAI が aaa ずいう単語に察しお bb ずしりずりにならない返答をしおいるため !OUT ず返しおいる プログラムの出力 プログラムぞの入力 ?aaa bb !OUT
36,293
Sum of Numbers Write a program which reads an integer and prints sum of its digits. Input The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000. The input ends with a line including single zero. Your program should not process for this terminal symbol. Output For each dataset, print the sum of digits in x . Sample Input 123 55 1000 0 Sample Output 6 10 1
36,294
避けるべし あなたはいた䞊䞋巊右に広倧に広がるマス目の原点に圓たる䜍眮 (0, 0) にいるマスの䜍眮は x 座暙ず y 座暙で衚され右に1マス動くこずが x 座暙が1぀増えるこずに察応し䞊に1マス動くこずが y 座暙が1぀増えるこずに察応するあなたはこれから目的地であるマス (x, y) を目指しお出発するずころだあなたは 1 歩で䞊䞋巊右斜めの 8 方向に隣接するマスに移動するこずができる さあ目的地に向かっお移動開始だずあなたは意気蟌んでいるずころかもしれないがちょっず埅っおほしい䞀぀だけ先に忠告しおおくこずがあるそれはこのマス目に朜む謎の人物回り蟌みのプロ・廻小宮の存圚だ廻小宮はあなたが 1 歩移動したのを確認するずあなたが進んだ方向のさらに 1 歩先のマスに瞬時に移動し邪魔をしおくるより正確に蚀えばあなたがマス (x s , y s ) から (x t , y t ) に移動するずき廻小宮は (x t + (x t - x s ), y t + (y t - y s )) に移動する明らかに異様な雰囲気を醞し出す廻小宮ダツの間合いに入り蟌むのは危険だ回り蟌たれた盎埌は仕方ないずしお次に移動する先のマスあるいはその 8 方向に隣接するマスのどれかに廻小宮がすでにいるずダツの間合いに入り蟌んでしたうこずになるのでこれはどうしおも避けたい 䞊蚘のように廻小宮の間合いを避け぀぀目的地に蟿り着くためには最小で䜕歩必芁だろうかあなたの仕事はこの最小歩数を求めるプログラムを曞くこずだただし廻小宮は初期状態ではどのマスにも存圚せず最初の 1 歩目以降から䞊蚘のルヌルに埓ったマスに珟れるものずする 最初のサンプルではあなたは (2, 0) を目指す䟋えば最初に右暪のマス (1, 0) に移動しおしたうず廻小宮が (2, 0) に回り蟌んでくるため次にそのマスぞず移動するこずができない䞀方最初に右斜め䞊の (1, 1) に移動するず廻小宮の䜍眮は (2, 2) ずなり (2, 0) が廻小宮の間合いではないため次の 1 歩で (2, 0) に移動するこずができる Input 入力は耇数のデヌタセットからなる 各デヌタセットは 2 ぀の敎数 x , y からなる 1 行で衚されるこれは目的地のマスが䜍眮 (x, y) であるこずを衚し |x|, |y| ≀ 10 9 を満たす 入力の終わりは EOF (ファむルの終端) で衚される 党デヌタセットの総数は 50 を超えない Output 条件を満たすように移動を繰り返すずきマス (0, 0) からマス (x, y) に移動するために必芁な最小歩数を 1 行に出力せよ Sample Input 2 0 2 2 1 -1 0 0 0 -5 173 207 Output for the Sample Input 2 4 1 0 6 379
36,295
勇者ビ倪郎(Bitaro the Brave) 勇者のビ倪郎は魔王ず察峙するこずずなった ビ倪郎は瞊$H$ 行暪$W$ 列のマス目䞊に宝石(Jewel)オヌブ(Orb)金塊(Ingot) を配眮し魔法を発動するこずによっお魔王に攻撃をしようずしおいる以䞋マス目のうち䞊から$i$ 行目($1 \leq i \leq H$)巊から$j$ 列目($1 \leq j \leq W$) のマスをマス($i, j$) ず衚す ビ倪郎は今それぞれのマスにこれら3 皮類のうち1 個を配眮した今から魔法を発動しようずしおいるがこの魔法の嚁力はマス目䞊の宝石オヌブ金塊の配眮によっお決たる具䜓的には次の条件を満たす敎数($i, j, k, l$) ($1 \leq i < k \leq H, 1 \leq j < l \leq W$) の組の個数が魔法の嚁力である 条件マス($i, j$) には宝石がマス($i, l$) にはオヌブがマス($k, j$) には金塊が眮かれおいる ビ倪郎はこの魔法の嚁力が気になっおいる マス目䞊の宝石オヌブ金塊の配眮が䞎えられたずきビ倪郎が発動する魔法の嚁力を求めるプログラムを䜜成せよ 入力 入力は以䞋の圢匏で暙準入力から䞎えられる $H$ $W$ $S_1$ : $S_H$ $S_i$ ($1 \leq i \leq H$) は長さ$W$ の文字列でその$j$ 文字目($1 \leq j \leq W$) がJ のずきはマス($i, j$) に宝石がO の ずきはマス($i, j$) にオヌブがI のずきはマス($i, j$) に金塊が眮かれおいるこずを衚す 出力 暙準出力に魔法の嚁力を衚す敎数を1 行で出力せよ 制玄 $2 \leq H \leq 3 000$ $2 \leq W \leq 3 000$ $S_i$ は長さ$W$ の文字列である($1 \leq i \leq H$) $S_i$ の各文字はJOI のいずれかである($1 \leq i \leq H$) 入出力䟋 入力䟋1 3 4 JOIJ JIOO IIII 出力䟋1 3 この入力䟋では($i, j, k, l$) = (1, 1, 3, 2), (2, 1, 3, 3), (2, 1, 3, 4) の3 個の組が条件を満たすので答えは3 である 入力䟋2 4 4 JJOO JJOO IIJO IIIJ 出力䟋2 17 情報オリンピック日本委員䌚䜜 『第18 回日本情報オリンピック(JOI 2018/2019) 本遞』
36,296
坪面積の蚈算 土地の面積を衚珟する「○○坪」ずいう単䜍を聞いたこずはないでしょうか 叀来、人の歊士が日に食べるお米を䜜る面積を蚀いたした。 a m× b mの土地がありたす。 a ず b を入力し、その土地の坪面積 S 坪を出力するプログラムを䜜成しおください。 1 坪 = 3.305785 [m 2 ] ずし、 a ず b は 100 以䞋の敎数ずしたす。 入力 a b ぀の空癜で区切られた a ず b が行に䞎えられる。 出力 坪面積 S を行に出力する。0.0001 以䞋の誀差が蚱される。 入力䟋1 15 25 出力䟋1 113.437508
36,297
Score : 200 points Problem Statement Given are integers a,b,c and d . If x and y are integers and a \leq x \leq b and c\leq y \leq d hold, what is the maximum possible value of x \times y ? Constraints -10^9 \leq a \leq b \leq 10^9 -10^9 \leq c \leq d \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: a b c d Output Print the answer. Sample Input 1 1 2 1 1 Sample Output 1 2 If x = 1 and y = 1 then x \times y = 1 . If x = 2 and y = 1 then x \times y = 2 . Therefore, the answer is 2 . Sample Input 2 3 5 -4 -2 Sample Output 2 -6 The answer can be negative. Sample Input 3 -1000000000 0 -1000000000 0 Sample Output 3 1000000000000000000
36,298
Problem F: Great Devil Sakanikia Problem 倧悪魔サカヌニャは今日も倩敵の猫に襲われおいた。 い぀もやられおいる蚳にはいかないので、秘密兵噚を賌入した。 この秘密兵噚は、巚倧な岩を生成するこずで猫の移動経路を塞ぎ、猫がこちらに近づけないようにするこずができる。 今、サカヌニャず䞀匹の猫がマス(0,0),( n −1,0),( n −1, m −1),(0, m −1)で囲たれた長方圢の閉区間内にいる。 マス(0,0)に猫、マス( n −1, m −1)にサカヌニャがいる。 猫は䞊䞋巊右の隣接したマスに移動するこずができるが、区間倖に出るこずはできない。 いく぀かのマスは、穎や障害物の圱響で䟵入するこずができない。 サカヌニャは、あるマスに1぀岩を生成するこずでそのマスに猫が䟵入できなくするこずができる。 ただし、マス(0,0)ずマス( n −1, m −1)に岩を生成するこずはできない。 マス(0,0)からマス( n −1, m −1)たでの移動経路を塞ぐために必芁な、生成する岩の数の最小倀を求めよ。 Input n m k x 1 y 1 ... x k y k 入力はすべお敎数で䞎えられる。 1行目にマスの倧きさを衚す぀の敎数 n ず m 、䟵入できないマスの数 k が空癜区切りで䞎えられる。 2行目から k 行に䟵入できないマスの座暙が䞎えられる。 Constraints 入力は以䞋の条件を満たす。 2 ≀ n , m ≀ 10 5 0 ≀ k ≀ min( n × m −2,10 5 ) 0 ≀ x i ≀ n − 1 0 ≀ y i ≀ m − 1 ( x i , y i ) ≠ ( x j , y j ) ( i ≠ j ) ( x i , y i ) ≠ (0,0) ≠ ( n −1, m −1) Output マス(0,0)からマス( n −1, m −1)たでの移動経路を塞ぐために必芁な、生成する岩の数の最小倀を1行に出力せよ。 Sample Input 1 3 5 2 0 2 2 2 Sample Output 1 1 Sample Input 2 5 5 3 0 2 2 2 4 1 Sample Output 2 2
36,299
Problem Statement You have a rectangular board with square cells arranged in $H$ rows and $W$ columns. The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right. The cell at the row $i$ and the column $j$ is denoted by $(i, j)$. Each cell on the board is colored in either Black or White. You will paint the board as follows: Choose a cell $(i, j)$ and a color $c$, each uniformly at random, where $1 \le i \le H$, $1 \le j \le W$, and $c \in \{{\rm Black}, {\rm White}\}$. Paint the cells $(i', j')$ with the color $c$ for any $1 \le i' \le i$ and $1 \le j' \le j$. Here's an example of the painting operation. You have a $3 \times 4$ board with the coloring depicted in the left side of the figure below. If your random choice is the cell $(2, 3)$ and the color Black, the board will become as shown in the right side of the figure. $6$ cells will be painted with Black as the result of this operation. Note that we count the cells "painted" even if the color is not actually changed by the operation, like the cell $(1, 2)$ in this example. Fig: An example of the painting operation Given the initial coloring of the board and the desired coloring, you are supposed to perform the painting operations repeatedly until the board turns into the desired coloring. Write a program to calculate the expected total number of painted cells in the sequence of operations. Input The input consists of several datasets. The number of datasets is at most $100$. The first line of each dataset contains two integers $H$ and $W$ ($1 \le H, W \le 5$), the numbers of rows and columns of the board respectively. Then given are two coloring configurations of the board, where the former is the initial coloring and the latter is the desired coloring. A coloring configuration is described in $H$ lines, each of which consists of $W$ characters. Each character is either B or W, denoting a Black cell or a White cell, respectively. There is one blank line between two configurations, and also after each dataset. You can assume that the resulting expected value for each dataset will not exceed $10^9$. The input is terminated by a line with two zeros, and your program should not process this as a dataset. Output For each dataset, your program should output the expected value in a line. The absolute error or the relative error in your answer must be less than $10^{-6}$. Sample Input 1 2 BB WW 2 1 B W B W 2 2 BW BW WW WW 3 4 BBBB BBBB BBBB WWWW WWWW WWWW 5 5 BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBWB BBBBB BWBBB BBBBB 0 0 Output for the Sample Input 6.0000000000 0.0000000000 12.8571428571 120.0000000000 23795493.8449918639
36,300
Problem H : Dungeon (II) あなたはずあるゲヌムの開発に携わっおいる。 そのゲヌムはランダムに生成されたダンゞョンをプレむダヌが探玢するずいうものである。 ゲヌムの仕様ずしお、プレむダヌに予めダンゞョンの危険床を提瀺し、生成されたダンゞョンを探玢するのか、それずも新しくダンゞョンを生成しなおすかを、遞択できるようにしたい。 このゲヌムで生成されるダンゞョンには n 個の郚屋が存圚しおおり、0から n-1 たでの番号が割り振られおいる。 郚屋ず郚屋は通路で結ばれおいる。郚屋ず郚屋を結ぶ通路は、合蚈で n-1 本存圚しおいる。 通路はどちらの方向ぞも進むこずができる。 たた、郚屋ず郚屋の間には距離が蚭定されおいる。 生成されたダンゞョンではいく぀かの通路を経由しお、ある郚屋から他のすべおの郚屋ぞ行くこずが可胜である。 そしお、プレむダヌがゲヌムを行う際に、぀の異なる郚屋がスタヌト地点ずゎヌル地点ずしお遞ばれる。 あなたはダンゞョンの評䟡を行うために、危険床の評䟡方法を決めるこずにした。 たず、ある郚屋から別の郚屋たでに移動する際の危険床を、郚屋間を最短で移動するために䜿う通路の䞭で、最もコスト高い通路の倀ずする。 そしお、ダンゞョンの危険床を、 i < j ずなる郚屋のペアの間を移動する際の危険床の総和ずするこずにした。 ランダムに生成されたダンゞョンのが入力ずしお䞎えられる。 たず、 i < j ずなるすべおの郚屋のペアに぀いお、移動する際の危険床を蚈算しお欲しい。 そしお、その総和を問題の答えずしお出力せよ。 Input 入力は以䞋のフォヌマットで䞎えられる。 n a 1 b 1 c 1 . . . a n-1 b n-1 c n-1 a i b i c i は 郚屋 a i ず b i を結ぶ通路の距離が c i であるこずを衚す。 入力は以䞋の制玄を満たす 2 ≀ n ≀ 200,000 0 ≀ a i , b i < n 0 ≀ c i ≀ 100,000 Output 答えの倀を1行に出力せよ Sample Input 1 4 0 1 3 1 2 5 1 3 2 Sample Output 1 23 Sample Input 2 6 0 2 5 2 1 1 2 3 10 3 5 4 3 4 2 Sample Output 2 111
36,301