这是用户在 2024-6-25 20:11 为 https://atcoder.jp/contests/abc319/tasks_print 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
A - Legendary Players
A - 传奇球员

Time Limit: 2 sec / Memory Limit: 1024 MB
时间限制:2 秒 / 内存限制:1024 MB

配点 : 100100

問題文

AtCoder では、レーティング上位 1010 人のハンドルネームには金色の冠が、上位 11 人のハンドルネームには白金色の冠が表示されます。
在 AtCoder 中,评分最高的人的手柄 1010 会有一个金冠,而评分最高的人的手柄 11 会有一个白金皇冠。

このコンテストが開始した時点で、アルゴリズム部門での上位 1010 人に入っているプレイヤーのハンドルネームとレーティングは以下のようになっています。
比赛开始时,算法类顶级 1010 选手的姓名和评分如下:

tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481

上記のプレイヤーのハンドルネーム SS が与えられるので、その人のレーティングを出力してください。
将给出上述玩家的句柄 SS ,您可以打印他们的评分。

制約

  • SS はアルゴリズム部門でレーティング上位 1010 人に入っているプレイヤーのハンドルネームのいずれかと等しい。
    SS 等于算法部门评分最高的 1010 玩家的句柄之一。

入力

入力は以下の形式で標準入力から与えられる。 输入从标准输入给出,格式如下:

SS

出力

対応するプレイヤーのレーティングを 11 行で出力せよ。
在一行中 11 打印相应玩家的评分。


入力例 1

tourist

出力例 1

3858

このコンテストが開始した時点において、 tourist さんのアルゴリズム部門のレーティングは 38583858 です。
在本次比赛开始时, Mr./Ms. 的算法评分为 38583858


入力例 2

semiexp

出力例 2

3481

このコンテストが開始した時点において、 semiexp さんのアルゴリズム部門のレーティングは 34813481 です。
在本次比赛开始时, Mr./Ms. 的算法评分为 34813481

Score : 100100 points 成绩 : 100100 points

Problem Statement 问题陈述

In AtCoder, the top 1010 rated players' usernames are displayed with a gold crown, and the top-rated player's username is displayed with a platinum crown.
在 AtCoder 中,评分最高的 1010 玩家的用户名以金冠显示,排名靠前的玩家的用户名以白金冠显示。

At the start of this contest, the usernames and ratings of the top 1010 rated players in the algorithm category are as follows:
在本次比赛开始时,算法类别中评分最高的 1010 玩家的用户名和评分如下:

tourist 3858
ksun48 3679
Benq 3658
Um_nik 3648
apiad 3638
Stonefeang 3630
ecnerwala 3613
mnbvmar 3555
newbiedmy 3516
semiexp 3481

You are given the username SS of one of these players. Print that player's rating.
您将获得其中一位玩家的用户名 SS 。打印该玩家的评分。

Constraints 约束

  • SS is equal to one of the usernames of the top 1010 rated players in the algorithm category.
    SS 等于算法类别中评分最高的 1010 玩家的用户名之一。

Input 输入

The input is given from Standard Input in the following format:
输入从标准输入中给出,格式如下:

SS

Output 输出

Print the rating of the corresponding player in one line.
在一行中打印相应玩家的评级。


Sample Input 1 示例输入 1

tourist

Sample Output 1 示例输出 1

3858

At the start of this contest, the rating of tourist in the algorithm category is 38583858.
在本次比赛开始时,算法类别中 游客的评分为 38583858


Sample Input 2 示例输入 2

semiexp

Sample Output 2 示例输出 2

3481

At the start of this contest, the rating of semiexp in the algorithm category is 34813481.
在本次比赛开始时, semiexp 在算法类别中的评分为 34813481

B - Measure B - 测量

Time Limit: 2 sec / Memory Limit: 1024 MB
时间限制:2 秒 / 内存限制:1024 MB

配点 : 200200

問題文

正整数 NN が与えられるので、下記で定まる長さ (N+1)(N+1) の文字列 s0s1sNs_0s_1\ldots s_N を出力してください。
由于 NN 给出了一个正整数,请输出一个长度如下的字符串 (N+1)(N+1) s0s1sNs_0s_1\ldots s_N

i=0,1,2,,Ni = 0, 1, 2, \ldots, N について、  i=0,1,2,,Ni = 0, 1, 2, \ldots, N 对于每个 ,

  • 11 以上 99 以下の NN の約数 jj であって、iiN/jN/j の倍数であるものが存在するとき、そのような jj のうち最小のものに対応する数字を sis_i とする。(よって、この場合 sis_i12\ldots9 のいずれかである。)
    如果以下的除数 NNii 的倍数 N/jN/j ,则 sis_i 是与其中最小的除数相对应的数字 jjjj 99 11 (所以,在本例 sis_i 1 中,它要么是 9\ldots 2 、 、 或 。 )
  • そのような jj が存在しないとき、sis_i- とする。
    如果 jj 不存在这样的条件,则 sis_i-

制約

  • 1N10001 \leq N \leq 1000
  • 入力はすべて整数 所有输入均为整数

入力

入力は以下の形式で標準入力から与えられる。 输入从标准输入给出,格式如下:

NN

出力

答えを出力せよ。 打印出答案。


入力例 1

12

出力例 1

1-643-2-346-1

以下で、いくつかの ii について sis_i の決め方を説明します。
以下是一些决定 ii 方法 sis_i

  • i=0i = 0 について、11 以上 99 以下の NN の約数 jj であって iiN/jN/j の倍数であるものは、j=1,2,3,4,6j = 1, 2, 3, 4, 655 個です。そのうち最小のものは 11 であるので、s0=s_0 = 1 です。
    i=0i = 0 对于 ,的除数 NN jj1199 ii 倍数 N/jN/j j=1,2,3,4,6j = 1, 2, 3, 4, 6 55 。 其中最小的是 11 ,所以 s0=s_0 = 1 它是 。

  • i=4i = 4 について、11 以上 99 以下の NN の約数 jj であって iiN/jN/j の倍数であるものは、j=3,6j = 3, 622 個です。そのうち最小のものは 33 であるので、s4=s_4 = 3 です。
    i=4i = 4 对于 ,的除数 NN jj1199 ii 倍数 N/jN/j j=3,6j = 3, 6 22 。 其中最小的是 33 ,所以 s4=s_4 = 3 它是 。

  • i=11i = 11 について、11 以上 99 以下の NN の約数 jj であって iiN/jN/j の倍数であるものは存在しないので、s11=s_{11} = - です。
    i=11i = 11 对于 ,没有 s11=s_{11} = - NN11 99 于或等于 jjii 除数 的倍 N/jN/j 数。


入力例 2

7

出力例 2

17777771

入力例 3

1

出力例 3

11

Score : 200200 points 成绩 : 200200 points

Problem Statement 问题陈述

You are given a positive integer NN. Print a string of length (N+1)(N+1), s0s1sNs_0s_1\ldots s_N, defined as follows.
你得到一个正整数 NN 。打印长度 (N+1)(N+1) 为 、 s0s1sNs_0s_1\ldots s_N 的字符串,定义如下。

For each i=0,1,2,,Ni = 0, 1, 2, \ldots, N, 对于每个 i=0,1,2,,Ni = 0, 1, 2, \ldots, N

  • if there is a divisor jj of NN that is between 11 and 99, inclusive, and ii is a multiple of N/jN/j, then sis_i is the digit corresponding to the smallest such jj (sis_i will thus be one of 1, 2, ..., 9);
    如果有一个除数 jj NN11 于 和 99 之间,包括 ,并且是 iiN/jN/j 倍数,则 sis_i 是 对应于最小的 such jj 的数字( sis_i 因此将是 , 1 2 , ..., 之一); 9
  • if no such jj exists, then sis_i is -.
    如果不存在这样的 jj 条件,则 sis_i- .

Constraints 约束

  • 1N10001 \leq N \leq 1000
  • All input values are integers.
    所有输入值均为整数。

Input 输入

The input is given from Standard Input in the following format:
输入从标准输入中给出,格式如下:

NN

Output 输出

Print the answer. 打印答案。


Sample Input 1 示例输入 1

12

Sample Output 1 示例输出 1

1-643-2-346-1

We will explain how to determine sis_i for some ii.
我们将解释如何确定 sis_i 某些 ii .

  • For i=0i = 0, the divisors jj of NN between 11 and 99 such that ii is a multiple of N/jN/j are 1,2,3,4,61, 2, 3, 4, 6. The smallest of these is 11, so s0=s_0 = 1.
    对于 i=0i = 0 ,是 的 N/jN/j 倍数的 之间的 11 99 ii 除数 jj1,2,3,4,61, 2, 3, 4, 6NN 其中最小的是 11 ,所以 s0=s_0 = 1

  • For i=4i = 4, the divisors jj of NN between 11 and 99 such that ii is a multiple of N/jN/j are 3,63, 6. The smallest of these is 33, so s4=s_4 = 3.
    对于 i=4i = 4 ,是 的 N/jN/j 倍数的 之间的 11 99 ii 除数 jj3,63, 6NN 其中最小的是 33 ,所以 s4=s_4 = 3

  • For i=11i = 11, there are no divisors jj of NN between 11 and 99 such that ii is a multiple of N/jN/j, so s11=s_{11} = -.
    对于 i=11i = 11 ,没有 NN 之间的 11 除数 jj99iiN/jN/j 倍数,所以 s11=s_{11} = -


Sample Input 2 示例输入 2

7

Sample Output 2 示例输出 2

17777771

Sample Input 3 示例输入 3

1

Sample Output 3 示例输出 3

11
C - False Hope
C - 虚假的希望

Time Limit: 2 sec / Memory Limit: 1024 MB
时间限制:2 秒 / 内存限制:1024 MB

配点 : 300300

問題文

3×33\times3 のマス目に 11 から 99 までの数字が書き込まれており、上から ii 行目、左から jj 列目 (1i3,1j3)(1\leq i\leq3,1\leq j\leq3) に書き込まれている数字は ci,jc _ {i,j} です。
从到正方形的数字 99 写在正方形 11 中,从上到下 iijj 行和从左到右的列中写 (1i3,1j3)(1\leq i\leq3,1\leq j\leq3) 的数字是 ci,jc _ {i,j}3×33\times3

異なるマスに同じ数字が書き込まれている場合もありますが、同じ数字が縦・横・斜めに 33 つ連続して書き込まれていることはありません。 より厳密には、ci,jc _ {i,j} について次の条件のすべてが成り立っていることが保証されます。
相同的数字可以写在不同的方块上,但相同的数字不能连续地垂直、水平 33 或对角线书写。 更准确地说,以下所有条件都保证对 为真 ci,jc _ {i,j}

  • どの 1i31\leq i\leq3 についても、ci,1=ci,2=ci,3c _ {i,1}=c _ {i,2}=c _ {i,3} ではない
    1i31\leq i\leq3 对于其中任何一个,不是 ci,1=ci,2=ci,3c _ {i,1}=c _ {i,2}=c _ {i,3}
  • どの 1j31\leq j\leq3 についても、c1,j=c2,j=c3,jc _ {1,j}=c _ {2,j}=c _ {3,j} ではない
    1j31\leq j\leq3 对于其中任何一个,不是 c1,j=c2,j=c3,jc _ {1,j}=c _ {2,j}=c _ {3,j}
  • c1,1=c2,2=c3,3c _ {1,1}=c _ {2,2}=c _ {3,3} ではない  c1,1=c2,2=c3,3c _ {1,1}=c _ {2,2}=c _ {3,3}
  • c3,1=c2,2=c1,3c _ {3,1}=c _ {2,2}=c _ {1,3} ではない  c3,1=c2,2=c1,3c _ {3,1}=c _ {2,2}=c _ {1,3}

高橋くんは、それぞれのマスに書かれている数字をランダムな順番で知ります。 高橋くんは、縦・横・斜めの列のうちの 11 つでも次の条件を満たしたときがっかりします。
高桥君以随机顺序学习每个方格上写的数字。 当垂直、水平和对角线行中的任何一个 11 满足以下条件时,Takahashi 会感到失望:

  • はじめに知ったほうの 22 マスに書かれた数字が同じであり、最後に知ったマスに書かれた数字がそれと異なる。
    你学习的第一个 22 单元格上写的数字是相同的,而你知道的最后一个方格上的数字是不同的。

高橋くんががっかりせずにすべてのマスに書かれた数字を知る確率を求めてください。
找到高桥君不会失望的概率,并且会知道所有方格上写的数字。

制約

  • ci,j{1,2,3,4,5,6,7,8,9} (1i3,1j3)c _ {i,j}\in\lbrace1,2,3,4,5,6,7,8,9\rbrace\ (1\leq i\leq3,1\leq j\leq3)
  • ci,1=ci,2=ci,3c _ {i,1}=c _ {i,2}=c _ {i,3} ではない (1i3)(1\leq i\leq3)  ci,1=ci,2=ci,3c _ {i,1}=c _ {i,2}=c _ {i,3} (1i3)(1\leq i\leq3)
  • c1,j=c2,j=c3,jc _ {1,j}=c _ {2,j}=c _ {3,j} ではない (1j3)(1\leq j\leq3)  c1,j=c2,j=c3,jc _ {1,j}=c _ {2,j}=c _ {3,j} (1j3)(1\leq j\leq3)
  • c1,1=c2,2=c3,3c _ {1,1}=c _ {2,2}=c _ {3,3} ではない  c1,1=c2,2=c3,3c _ {1,1}=c _ {2,2}=c _ {3,3}
  • c1,3=c2,2=c3,1c _ {1,3}=c _ {2,2}=c _ {3,1} ではない  c1,3=c2,2=c3,1c _ {1,3}=c _ {2,2}=c _ {3,1}

入力

入力は以下の形式で標準入力から与えられる。 输入从标准输入给出,格式如下:

c1,1c _ {1,1} c1,2c _ {1,2} c1,3c _ {1,3}
c2,1c _ {2,1} c2,2c _ {2,2} c2,3c _ {2,3}
c3,1c _ {3,1} c3,2c _ {3,2} c3,3c _ {3,3}

出力

高橋くんががっかりせずにすべてのマスに書かれた数字を知る確率を 11 行で出力せよ。 真の値からの絶対誤差が 10810 ^ {-8} 以下であるとき、正答と判定される。
不要失望,并输出高桥君知道 11 写在一行所有方格上的数字的概率。 如果与真值的绝对误差 10810 ^ {-8} 小于或等于 ,则判断答案正确。


入力例 1

3 1 9
2 5 6
2 7 1

出力例 1

0.666666666666666666666666666667

例えば、高橋くんが c3,1=2,c2,1=2,c1,1=3c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3 の順に知った場合、高橋くんはがっかりしてしまいます。
例如,如果高桥君按照 c3,1=2,c2,1=2,c1,1=3c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3 的顺序学习,高桥君会感到失望。

対して、高橋くんが c1,1,c1,2,c1,3,c2,1,c2,2,c2,3,c3,1,c3,2,c3,3c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3} の順に数字を知った場合、がっかりすることなくすべての数字を知ることができます。
另一方面,如果高桥君知道 c1,1,c1,2,c1,3,c2,1,c2,2,c2,3,c3,1,c3,2,c3,3c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3} 的顺序数字,他就会知道所有的数字而不会失望。

高橋くんががっかりすることなくすべての数字を知ることができる確率は 23\dfrac 23 です。 絶対誤差が 10810 ^ {-8} 以下であれば正答と判定されるため、0.6666666570.6666666570.6666666760.666666676 のように出力しても正解になります。
高桥君能够知道所有数字而不会失望的概率是 23\dfrac 23 。 如果绝对误差 10810 ^ {-8} 小于或等于 ,则判断为正确答案,因此即使输出 0.6666666760.6666666760.6666666570.666666657 或 ,也是正确的。


入力例 2

7 7 6
8 6 8
7 7 6

出力例 2

0.004982363315696649029982363316

入力例 3

3 6 7
1 9 7
5 7 5

出力例 3

0.4

Score : 300300 points 成绩 : 300300 points

Problem Statement 问题陈述

There is a 3×33\times3 grid with numbers between 11 and 99, inclusive, written in each square. The square at the ii-th row from the top and jj-th column from the left (1i3,1j3)(1\leq i\leq3,1\leq j\leq3) contains the number ci,jc _ {i,j}.
每个方格中都有一个网 3×33\times3 格, 11 其中 和 99 之间有数字,包括 和。从顶部开始的第 ii -行和 jj 从左侧 (1i3,1j3)(1\leq i\leq3,1\leq j\leq3) 开始的第 - 列的正方形包含数字 ci,jc _ {i,j}

The same number may be written in different squares, but not in three consecutive cells vertically, horizontally, or diagonally. More precisely, it is guaranteed that ci,jc _ {i,j} satisfies all of the following conditions.

  • ci,1=ci,2=ci,3c _ {i,1}=c _ {i,2}=c _ {i,3} does not hold for any 1i31\leq i\leq3.
  • c1,j=c2,j=c3,jc _ {1,j}=c _ {2,j}=c _ {3,j} does not hold for any 1j31\leq j\leq3.
  • c1,1=c2,2=c3,3c _ {1,1}=c _ {2,2}=c _ {3,3} does not hold.
  • c3,1=c2,2=c1,3c _ {3,1}=c _ {2,2}=c _ {1,3} does not hold.

Takahashi will see the numbers written in each cell in random order. He will get disappointed when there is a line (vertical, horizontal, or diagonal) that satisfies the following condition.

  • The first two squares he sees contain the same number, but the last square contains a different number.

Find the probability that Takahashi sees the numbers in all the squares without getting disappointed.

Constraints

  • ci,j{1,2,3,4,5,6,7,8,9} (1i3,1j3)c _ {i,j}\in\lbrace1,2,3,4,5,6,7,8,9\rbrace\ (1\leq i\leq3,1\leq j\leq3)
  • ci,1=ci,2=ci,3c _ {i,1}=c _ {i,2}=c _ {i,3} does not hold for any 1i31\leq i\leq3.
  • c1,j=c2,j=c3,jc _ {1,j}=c _ {2,j}=c _ {3,j} does not hold for any 1j31\leq j\leq3.
  • c1,1=c2,2=c3,3c _ {1,1}=c _ {2,2}=c _ {3,3} does not hold.
  • c3,1=c2,2=c1,3c _ {3,1}=c _ {2,2}=c _ {1,3} does not hold.

Input

The input is given from Standard Input in the following format:

c1,1c _ {1,1} c1,2c _ {1,2} c1,3c _ {1,3}
c2,1c _ {2,1} c2,2c _ {2,2} c2,3c _ {2,3}
c3,1c _ {3,1} c3,2c _ {3,2} c3,3c _ {3,3}

Output

Print one line containing the probability that Takahashi sees the numbers in all the squares without getting disappointed. Your answer will be considered correct if the absolute error from the true value is at most 10810 ^ {-8}.


Sample Input 1

3 1 9
2 5 6
2 7 1

Sample Output 1

0.666666666666666666666666666667

For example, if Takahashi sees c3,1=2,c2,1=2,c1,1=3c _ {3,1}=2,c _ {2,1}=2,c _ {1,1}=3 in this order, he will get disappointed.

On the other hand, if Takahashi sees c1,1,c1,2,c1,3,c2,1,c2,2,c2,3,c3,1,c3,2,c3,3c _ {1,1},c _ {1,2},c _ {1,3},c _ {2,1},c _ {2,2},c _ {2,3},c _ {3,1},c _ {3,2},c _ {3,3} in this order, he will see all numbers without getting disappointed.

The probability that Takahashi sees all the numbers without getting disappointed is 23\dfrac 23. Your answer will be considered correct if the absolute error from the true value is at most 10810 ^ {-8}, so outputs such as 0.6666666570.666666657 and 0.6666666760.666666676 would also be accepted.


Sample Input 2

7 7 6
8 6 8
7 7 6

Sample Output 2

0.004982363315696649029982363316

Sample Input 3

3 6 7
1 9 7
5 7 5

Sample Output 3

0.4
D - Minimum Width

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400400

問題文

高橋くんは、NN 個の単語からなる文章をウィンドウに表示させようとしています。 すべての単語の縦幅は等しく、ii 番目 (1iN)(1\leq i\leq N) の単語の横幅は LiL _ i です。

文章は、横幅 11 の空白を単語の区切りとしてウィンドウに表示されます。 より厳密には、高橋くんが横幅 WW のウィンドウに文章を表示しているとき、次の条件が成り立っています。

  • 文章はいくつかの行に分かれている。
  • 11 番目の単語は一番上の行の先頭に表示されている。
  • ii 番目 (2iN)(2\leq i\leq N) の単語は、i1i-1 番目の単語の次に間隔を 11 だけ開けて表示されているか、i1i-1 番目の単語が含まれる行の下の行の先頭に表示されているかの一方である。それ以外の場所に表示されていることはない。
  • それぞれの行の横幅は WW を超えない。ここで、行の横幅とは最も左にある単語の左端から最も右にある単語の右端までの距離を指す。

高橋くんが文章をウィンドウに表示したとき、文章が MM 行に収まりました。 ウィンドウの横幅としてありえる最小の値を求めてください。

制約

  • 1MN2×1051\leq M\leq N\leq2\times10 ^ 5
  • 1Li109 (1iN)1\leq L _ i\leq10^9\ (1\leq i\leq N)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN MM
L1L _ 1 L2L _ 2 \ldots LNL _ N

出力

答えを 11 行で出力せよ。


入力例 1

13 3
9 5 2 7 1 8 8 2 1 5 2 3 6

出力例 1

26

ウィンドウの横幅が 2626 のとき、以下のようにして与えられた文章を 33 行に収めることができます。

ウィンドウの横幅が 2525 以下のときは与えられた文章を 33 行に収めることができないため、2626 を出力してください。

単語を複数の行にまたがって表示させたり、行の横幅がウィンドウの横幅を上回ったり、単語を並べ替えたりしてはいけないことに注意してください。


入力例 2

10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

出力例 2

10000000009

答えが 32bit32\operatorname{bit} 整数に収まらない場合があることに注意してください。


入力例 3

30 8
8 55 26 97 48 37 47 35 55 5 17 62 2 60 23 99 73 34 75 7 46 82 84 29 41 32 31 52 32 60

出力例 3

189

Score : 400400 points

Problem Statement

Takahashi is displaying a sentence with NN words in a window. All words have the same height, and the width of the ii-th word (1iN)(1\leq i\leq N) is LiL _ i.

The words are displayed in the window separated by a space of width 11. More precisely, when the sentence is displayed in a window of width WW, the following conditions are satisfied.

  • The sentence is divided into several lines.
  • The first word is displayed at the beginning of the top line.
  • The ii-th word (2iN)(2\leq i\leq N) is displayed either with a gap of 11 after the (i1)(i-1)-th word, or at the beginning of the line below the line containing the (i1)(i-1)-th word. It will not be displayed anywhere else.
  • The width of each line does not exceed WW. Here, the width of a line refers to the distance from the left end of the leftmost word to the right end of the rightmost word.

When Takahashi displayed the sentence in the window, the sentence fit into MM or fewer lines. Find the minimum possible width of the window.

Constraints

  • 1MN2×1051\leq M\leq N\leq2\times10 ^ 5
  • 1Li109 (1iN)1\leq L _ i\leq10^9\ (1\leq i\leq N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM
L1L _ 1 L2L _ 2 \ldots LNL _ N

Output

Print the answer in one line.


Sample Input 1

13 3
9 5 2 7 1 8 8 2 1 5 2 3 6

Sample Output 1

26

When the width of the window is 2626, you can fit the given sentence into three lines as follows.

You cannot fit the given sentence into three lines when the width of the window is 2525 or less, so print 2626.

Note that you should not display a word across multiple lines, let the width of a line exceed the width of the window, or rearrange the words.


Sample Input 2

10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 2

10000000009

Note that the answer may not fit into a 32bit32\operatorname{bit} integer.


Sample Input 3

30 8
8 55 26 97 48 37 47 35 55 5 17 62 2 60 23 99 73 34 75 7 46 82 84 29 41 32 31 52 32 60

Sample Output 3

189
E - Bus Stops

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 450450

問題文

高橋君ははじめ高橋君の家におり、これから青木君の家に遊びに行きます。

22 人の家の間には 11 から NN までの番号がつけられた NN 個のバス停があり、高橋君はそれらの間を下記の方法で移動できます。

  • 高橋君の家からバス停 11 まで XX だけの時間をかけて徒歩で移動できます。
  • i=1,2,,N1i = 1, 2, \ldots, N-1 について、バス停 ii からは PiP_i の倍数である時刻それぞれにバスが出発し、そのバスに乗ることで TiT_i だけの時間をかけてバス停 (i+1)(i+1) に移動できます。ここで、1Pi81 \leq P_i \leq 8 が制約として保証されます。
  • バス停 NN から青木君の家まで、YY だけの時間をかけて徒歩で移動できます。

i=1,2,,Qi = 1, 2, \ldots, Q に対して下記のクエリを処理してください。

高橋君が高橋君の家を時刻 qiq_i に出発するときの、高橋君が青木君の家に到着する時刻としてあり得る最も早いものを求めよ。

なお、バスの出発時刻ちょうどにそのバスが出発するバス停に到着した場合であっても、そのバスに乗ることができます。

制約

  • 2N1052 \leq N \leq 10^5
  • 1X,Y1091 \leq X, Y \leq 10^9
  • 1Pi81 \leq P_i \leq 8
  • 1Ti1091 \leq T_i \leq 10^9
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 0qi1090 \leq q_i \leq 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN XX YY
P1P_1 T1T_1
P2P_2 T2T_2
\vdots
PN1P_{N-1} TN1T_{N-1}
QQ
q1q_1
q2q_2
\vdots
qQq_Q

出力

QQ 行出力せよ。 i=1,2,,Qi = 1, 2, \ldots, Q について、ii 行目には ii 番目のクエリに対する答えを出力せよ。


入力例 1

4 2 3
5 4
6 6
3 1
7
13
0
710511029
136397527
763027379
644706927
447672230

出力例 1

34
22
710511052
136397548
763027402
644706946
447672250

11 番目のクエリについて、高橋君は下記の通りに移動を行って、時刻 3434 に青木君の家に到着することができます。

  • 時刻 1313 に高橋君の家を出発する。
  • 高橋君の家から徒歩で移動し、時刻 1515 にバス停 11 に到着する。
  • 時刻 1515 にバス停 11 を出発するバスに乗り、時刻 1919 にバス停 22 に到着する。
  • 時刻 2424 にバス停 22 を出発するバスに乗り、時刻 3030 にバス停 33 に到着する。
  • 時刻 3030 にバス停 33 を出発するバスに乗り、時刻 3131 にバス停 44 に到着する。
  • バス停 44 から徒歩で移動し、時刻 3434 に青木君の家に到着する。

22 番目のクエリについて、高橋君は下記の通りに移動を行って、時刻 2222 に青木君の家に到着することができます。

  • 時刻 00 に高橋君の家を出発する。
  • 高橋君の家から徒歩で移動し、時刻 22 にバス停 11 に到着する。
  • 時刻 55 にバス停 11 を出発するバスに乗り、時刻 99 にバス停 22 に到着する。
  • 時刻 1212 にバス停 22 を出発するバスに乗り、時刻 1818 にバス停 33 に到着する。
  • 時刻 1818 にバス停 33 を出発するバスに乗り、時刻 1919 にバス停 44 に到着する。
  • バス停 44 から徒歩で移動し、時刻 2222 に青木君の家に到着する。

Score : 450450 points

Problem Statement

Takahashi is initially at his house and is about to visit Aoki's house.

There are NN bus stops numbered 11 to NN between the two houses, and Takahashi can move between them in the following ways:

  • He can walk from his house to bus stop 11 in XX units of time.
  • For each i=1,2,,N1i = 1, 2, \ldots, N-1, a bus departs from bus stop ii at each time that is a multiple of PiP_i, and by taking this bus, he can get to bus stop (i+1)(i+1) in TiT_i units of time. Here, the constraints guarantee that 1Pi81 \leq P_i \leq 8.
  • Takahashi can walk from bus stop NN to Aoki's house in YY units of time.

For each i=1,2,,Qi = 1, 2, \ldots, Q, process the following query.

Find the earliest time that Takahashi can arrive at Aoki's house when he leaves his house at time qiq_i.

Note that if he arrives at a bus stop exactly at the departure time of a bus, he can take that bus.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1X,Y1091 \leq X, Y \leq 10^9
  • 1Pi81 \leq P_i \leq 8
  • 1Ti1091 \leq T_i \leq 10^9
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 0qi1090 \leq q_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN XX YY
P1P_1 T1T_1
P2P_2 T2T_2
\vdots
PN1P_{N-1} TN1T_{N-1}
QQ
q1q_1
q2q_2
\vdots
qQq_Q

Output

Print QQ lines. For each i=1,2,,Qi = 1, 2, \ldots, Q, the ii-th line should contain the answer to the ii-th query.


Sample Input 1

4 2 3
5 4
6 6
3 1
7
13
0
710511029
136397527
763027379
644706927
447672230

Sample Output 1

34
22
710511052
136397548
763027402
644706946
447672250

For the first query, Takahashi can move as follows to arrive at Aoki's house at time 3434.

  • Leave his house at time 1313.
  • Walk from his house and arrive at bus stop 11 at time 1515.
  • Take the bus departing from bus stop 11 at time 1515 and arrive at bus stop 22 at time 1919.
  • Take the bus departing from bus stop 22 at time 2424 and arrive at bus stop 33 at time 3030.
  • Take the bus departing from bus stop 33 at time 3030 and arrive at bus stop 44 at time 3131.
  • Walk from bus stop 44 and arrive at Aoki's house at time 3434.

For the second query, Takahashi can move as follows and arrive at Aoki's house at time 2222.

  • Leave his house at time 00.
  • Walk from his house and arrive at bus stop 11 at time 22.
  • Take the bus departing from bus stop 11 at time 55 and arrive at bus stop 22 at time 99.
  • Take the bus departing from bus stop 22 at time 1212 and arrive at bus stop 33 at time 1818.
  • Take the bus departing from bus stop 33 at time 1818 and arrive at bus stop 44 at time 1919.
  • Walk from bus stop 44 and arrive at Aoki's house at time 2222.
F - Fighter Takahashi

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 550550

問題文

NN 頂点の木があります。 11 番目の頂点が根であり、ii 番目 (2iN)(2\leq i\leq N) の頂点の親は pi (1pi<i)p _ i\ (1\leq p _ i\lt i) です。

根でない頂点には、のどちらか一方が配置されています。 高橋くんは、すべての敵を倒したいです。 はじめ、高橋くんの強さは 11 で、頂点 11 にいます。 i=2,,Ni=2,\ldots,N について、ii 番目の頂点の情報は整数の組 (ti,si,gi)(t _ i,s _ i,g _ i) を用いて次のように表されます。

  • ti=1t _ i=1 ならば ii 番目の頂点には敵がいます。この頂点に高橋くんが初めて訪れたとき、高橋くんの強さが sis _ i 未満だった場合高橋くんは敵に倒されて敗北し、高橋くんは他の頂点に移動できなくなります。そうでなかった場合、高橋くんは敵を倒し、強さが gig _ i 上昇します。
  • ti=2t _ i=2 ならば ii 番目の頂点には薬があります。この頂点に高橋くんが初めて訪れたとき、高橋くんは薬を飲み、強さが gig _ i 倍になります。(薬がある頂点では、si=0s _ i=0 です。)

薬がある頂点はたかだか 1010 個です。

高橋くんは、隣接する頂点に移動することができます。 高橋くんがすべての敵を倒すことができるか判定してください。

制約

  • 2N5002\leq N\leq 500
  • 1pi<i (2iN)1\leq p _ i\lt i\ (2\leq i\leq N)
  • ti{1,2} (2iN)t _ i\in\lbrace1,2\rbrace\ (2\leq i\leq N)
  • ti=1    1si109 (2iN)t _ i=1\implies1\leq s _ i\leq 10 ^ 9\ (2\leq i\leq N)
  • ti=2    si=0 (2iN)t _ i=2\implies s _ i=0\ (2\leq i\leq N)
  • 1gi109 (2iN)1\leq g _ i\leq 10 ^ 9\ (2\leq i\leq N)
  • ti=2t _ i=2 である頂点は 1010 個以下
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN
p2p _ 2 t2t _ 2 s2s _ 2 g2g _ 2
p3p _ 3 t3t _ 3 s3s _ 3 g3g _ 3
\vdots
pNp _ N tNt _ N sNs _ N gNg _ N

出力

答え(Yes または No)を 11 行で出力せよ。


入力例 1

8
1 2 0 3
2 1 3 3
1 2 0 4
4 1 2 2
1 2 0 5
6 1 5 5
5 1 140 1

出力例 1

Yes

はじめ、木は以下のようになっています。

高橋くんは、頂点 11 から 2,3,2,1,6,7,6,1,4,5,82,3,2,1,6,7,6,1,4,5,8 の順に移動することで、すべての敵を倒すことができます。 このとき、高橋くんがいる頂点と高橋くんの強さは以下の図のように変化します(図では、すでに訪れたことのある頂点への移動は省略しています)。

例えば、頂点 11 から 4,5,84,5,8 の順に移動すると、頂点 88 に訪れた時点での強さが s8=140s _ 8=140 より小さいので高橋くんは敗北してしまい、すべての敵を倒すことができません。


入力例 2

12
1 1 166 619
1 1 17 592
2 1 222 983
2 1 729 338
5 1 747 62
3 1 452 815
3 2 0 1
4 2 0 40
4 1 306 520
6 1 317 591
1 1 507 946

出力例 2

No

入力例 3

12
1 1 1 791
2 2 0 410
2 1 724 790
2 1 828 599
5 2 0 13
3 1 550 803
1 1 802 506
5 1 261 587
6 1 663 329
8 1 11 955
9 1 148 917

出力例 3

Yes

入力例 4

12
1 2 0 1000000000
2 2 0 1000000000
3 2 0 1000000000
4 2 0 1000000000
5 2 0 1000000000
6 2 0 1000000000
7 2 0 1000000000
8 2 0 1000000000
9 2 0 1000000000
10 2 0 1000000000
11 1 1 1

出力例 4

Yes

Score : 550550 points

Problem Statement

There is a tree with NN vertices. The 11-st vertex is the root, and the parent of the ii-th vertex (2iN)(2\leq i\leq N) is pi (1pi<i)p _ i\ (1\leq p _ i\lt i).

Each non-root vertex has an enemy or a medicine on it. Takahashi wants to defeat all the enemies. Initially, his strength is 11, and he is at vertex 11. For i=2,,Ni=2,\ldots,N, the information of the ii-th vertex is represented by a triple of integers (ti,si,gi)(t _ i,s _ i,g _ i) as follows.

  • If ti=1t _ i=1, there is an enemy at the ii-th vertex. When Takahashi visits this vertex for the first time, if his strength is less than sis _ i, Takahashi is defeated by the enemy and loses, after which he cannot move to other vertices. Otherwise, he defeats the enemy, and his strength increases by gig _ i.
  • If ti=2t _ i=2, there is a medicine at the ii-th vertex. When Takahashi visits this vertex for the first time, he takes the medicine, and his strength is multiplied by gig _ i. (For a vertex with a medicine, si=0s _ i=0.)

There are at most 1010 vertices with a medicine.

Takahashi can repeatedly move to an adjacent vertex. Determine if he can defeat all the enemies.

Constraints

  • 2N5002\leq N\leq 500
  • 1pi<i (2iN)1\leq p _ i\lt i\ (2\leq i\leq N)
  • ti{1,2} (2iN)t _ i\in\lbrace1,2\rbrace\ (2\leq i\leq N)
  • ti=1    1si109 (2iN)t _ i=1\implies1\leq s _ i\leq 10 ^ 9\ (2\leq i\leq N)
  • ti=2    si=0 (2iN)t _ i=2\implies s _ i=0\ (2\leq i\leq N)
  • 1gi109 (2iN)1\leq g _ i\leq 10 ^ 9\ (2\leq i\leq N)
  • There are at most 1010 vertices with ti=2t _ i=2.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN
p2p _ 2 t2t _ 2 s2s _ 2 g2g _ 2
p3p _ 3 t3t _ 3 s3s _ 3 g3g _ 3
\vdots
pNp _ N tNt _ N sNs _ N gNg _ N

Output

Print the answer (Yes or No) in one line.


Sample Input 1

8
1 2 0 3
2 1 3 3
1 2 0 4
4 1 2 2
1 2 0 5
6 1 5 5
5 1 140 1

Sample Output 1

Yes

Initially, the tree looks like this:

Takahashi can defeat all the enemies by moving from vertex 11 to 2,3,2,1,6,7,6,1,4,5,82,3,2,1,6,7,6,1,4,5,8 in this order. Here, his position and strength change as shown in the following figure (movements to vertices that have already been visited are omitted).

On the other hand, if he moves from vertex 11 to 4,5,84,5,8 in this order, for example, his strength when visiting vertex 88 will be less than s8=140s _ 8=140, so he will lose without defeating all the enemies.


Sample Input 2

12
1 1 166 619
1 1 17 592
2 1 222 983
2 1 729 338
5 1 747 62
3 1 452 815
3 2 0 1
4 2 0 40
4 1 306 520
6 1 317 591
1 1 507 946

Sample Output 2

No

Sample Input 3

12
1 1 1 791
2 2 0 410
2 1 724 790
2 1 828 599
5 2 0 13
3 1 550 803
1 1 802 506
5 1 261 587
6 1 663 329
8 1 11 955
9 1 148 917

Sample Output 3

Yes

Sample Input 4

12
1 2 0 1000000000
2 2 0 1000000000
3 2 0 1000000000
4 2 0 1000000000
5 2 0 1000000000
6 2 0 1000000000
7 2 0 1000000000
8 2 0 1000000000
9 2 0 1000000000
10 2 0 1000000000
11 1 1 1

Sample Output 4

Yes
G - Counting Shortest Paths

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 575575

問題文

NN 頂点の無向完全グラフ GG に対して下記の操作を行います。

i=1,2,,Mi = 1, 2, \ldots, M について、頂点 uiu_i と 頂点 viv_i を結ぶ無向辺を削除する。

その後の GG において、頂点 11 から頂点 NN へのパスが存在するかどうかを判定し、 存在する場合は頂点 11 から 頂点 NN への最短パスの個数を 998244353998244353 で割った余りを求めてください。

ここで、頂点 11 から 頂点 NN への最短パスとは、頂点 11 から頂点 NN へのパスであって含む辺の本数が最小であるものです。

制約

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 0Mmin{2×105,N(N1)/2}0 \leq M \leq \min\lbrace 2 \times 10^5, N(N-1)/2 \rbrace
  • 1ui,viN1 \leq u_i, v_i \leq N
  • uiviu_i \neq v_i
  • ij    {ui,vi}{uj,vj}i \neq j \implies \lbrace u_i, v_i \rbrace \neq \lbrace u_j, v_j \rbrace
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN MM
u1u_1 v1v_1
u2u_2 v2v_2
\vdots
uMu_M vMv_M

出力

操作後の GG において、頂点 11 から頂点 NN へのパスが存在しない場合は -1 を出力し、 存在する場合は頂点 11 から頂点 NN への最短パスの個数を 998244353998244353 で割った余りを出力せよ。


入力例 1

6 7
4 3
1 3
2 4
1 6
4 6
5 1
6 2

出力例 1

3

操作後の GG における頂点 11 から頂点 NN への最短パスは、33 本の辺を含む下記の 33 個のパスです。

  • 頂点 11 \rightarrow 頂点 22 \rightarrow 頂点 33 \rightarrow 頂点 66
  • 頂点 11 \rightarrow 頂点 22 \rightarrow 頂点 55 \rightarrow 頂点 66
  • 頂点 11 \rightarrow 頂点 44 \rightarrow 頂点 55 \rightarrow 頂点 66

入力例 2

4 6
1 2
1 3
1 4
2 3
2 4
3 4

出力例 2

-1

操作後の GG には辺が 11 本もありません。 頂点 11 から頂点 NN へのパスが存在しないため -1 を出力します。

Score : 575575 points

Problem Statement

We will perform the following operation on a complete undirected graph GG with NN vertices.

For each i=1,2,,Mi = 1, 2, \ldots, M, delete the undirected edge connecting vertices uiu_i and viv_i.

Determine if there is a path from vertex 11 to vertex NN in GG after the operation. If there is, find the number, modulo 998244353998244353, of shortest paths from vertex 11 to vertex NN.

Here, a shortest path from vertex 11 to vertex NN is a path from vertex 11 to vertex NN that contains the minimum number of edges.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 0Mmin{2×105,N(N1)/2}0 \leq M \leq \min\lbrace 2 \times 10^5, N(N-1)/2 \rbrace
  • 1ui,viN1 \leq u_i, v_i \leq N
  • uiviu_i \neq v_i
  • ij    {ui,vi}{uj,vj}i \neq j \implies \lbrace u_i, v_i \rbrace \neq \lbrace u_j, v_j \rbrace
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM
u1u_1 v1v_1
u2u_2 v2v_2
\vdots
uMu_M vMv_M

Output

If there is no path from vertex 11 to vertex NN in GG after the operation, print -1. If there is, print the number, modulo 998244353998244353, of shortest paths from vertex 11 to vertex NN.


Sample Input 1

6 7
4 3
1 3
2 4
1 6
4 6
5 1
6 2

Sample Output 1

3

In GG after the operation, the shortest paths from vertex 11 to vertex NN are the following three, each containing three edges.

  • vertex 11 \rightarrow vertex 22 \rightarrow vertex 33 \rightarrow vertex 66
  • vertex 11 \rightarrow vertex 22 \rightarrow vertex 55 \rightarrow vertex 66
  • vertex 11 \rightarrow vertex 44 \rightarrow vertex 55 \rightarrow vertex 66

Sample Input 2

4 6
1 2
1 3
1 4
2 3
2 4
3 4

Sample Output 2

-1

GG has no edges after the operation. There is no path from vertex 11 to vertex NN, so print -1.