実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
円周率の小数第 100 位までの値は
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
です。
1 以上 100 以下の整数 N が与えられます。
円周率を小数第 N 位まで出力してください。
より厳密には、円周率を小数第 N+1 位で切り捨て、末尾の 0 を取り除かずに出力してください。
制約
- 1\leq N\leq 100
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
円周率を小数第 N 位まで 1 行で出力せよ。
入力例 1
2
出力例 1
3.14
円周率を小数第 2+1 位で切り捨てると値は 3.14 になります。
よって、3.14 を出力してください。
入力例 2
32
出力例 2
3.14159265358979323846264338327950
末尾の 0 は取り除かずに出力してください。
入力例 3
100
出力例 3
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Score : 100 points
Problem Statement
The number pi to the 100-th decimal place is
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679.
You are given an integer N between 1 and 100, inclusive.
Print the value of pi to the N-th decimal place.
More precisely, truncate the value of pi to N decimal places and print the result without removing the trailing 0s.
Constraints
- 1\leq N\leq 100
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the value of pi to the N-th decimal place in a single line.
Sample Input 1
2
Sample Output 1
3.14
Truncating the value of pi to 2 decimal places results in 3.14. Thus, you should print 3.14.
Sample Input 2
32
Sample Output 2
3.14159265358979323846264338327950
Do not remove the trailing 0s.
Sample Input 3
100
Sample Output 3
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
英小文字と . のみからなる文字列 S が与えられます。
S を . で分割したときの末尾の文字列を出力してください。
すなわち、. を含まない S の接尾辞のうち最長のものを出力してください。
制約
- S は英小文字と
.からなる、長さ 2 以上 100 以下の文字列 - S には
.が 1 つ以上含まれる - S の末尾は
.ではない
入力
入力は以下の形式で標準入力から与えられる。
S
出力
答えを出力せよ。
入力例 1
atcoder.jp
出力例 1
jp
atcoder.jp の、 . を含まない最長の接尾辞は jp です。
入力例 2
translate.google.com
出力例 2
com
S に . が複数含まれることもあります。
入力例 3
.z
出力例 3
z
S が . から始まることもあります。
入力例 4
..........txt
出力例 4
txt
S 中で . が連続することもあります。
Score: 100 points
Problem Statement
You are given a string S consisting of lowercase English letters and the character ..
Print the last substring when S is split by .s.
In other words, print the longest suffix of S that does not contain ..
Constraints
- S is a string of length between 2 and 100, inclusive, consisting of lowercase English letters and
.. - S contains at least one
.. - S does not end with
..
Input
The input is given from Standard Input in the following format:
S
Output
Print the answer.
Sample Input 1
atcoder.jp
Sample Output 1
jp
The longest suffix of atcoder.jp that does not contain . is jp.
Sample Input 2
translate.google.com
Sample Output 2
com
S may contain multiple .s.
Sample Input 3
.z
Sample Output 3
z
S may start with ..
Sample Input 4
..........txt
Sample Output 4
txt
S may contain consecutive .s.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S と T が与えられます。
以下の条件を満たす 1 \leq c \leq w < |S| となる整数の組 c と w が存在するか判定してください。ただし、 |S| は文字列 S の長さを表します。ここで、w は |S| 未満である必要があることに注意してください。
- S を先頭から順に w 文字毎に区切ったとき、長さが c 以上の文字列の c 文字目を順番に連結した文字列が T と一致する
制約
- S と T は英小文字からなる文字列
- 1 \leq |T| \leq |S| \leq 100
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
条件を満たすような 1 \leq c \leq w < |S| となる整数の組 c と w が存在する場合は Yes を、存在しない場合は No を出力せよ。
入力例 1
atcoder toe
出力例 1
Yes
S を 2 文字毎に区切ると以下のようになります。
at co de r
区切った後、 2 文字以上の文字列の 2 文字目を取り出し連結させたときの文字列は、 toe となり T と一致します。よって、 Yes を出力します。
入力例 2
beginner r
出力例 2
No
w=|S| であることはないため、条件を満たすような 1 \leq c \leq w < |S| となる整数の組 c と w は存在しません。よって、 No を出力します。
入力例 3
verticalreading agh
出力例 3
No
Score : 200 points
Problem Statement
You are given two strings S and T consisting of lowercase English letters.
Determine if there exists a pair of integers c and w such that 1 \leq c \leq w < |S| and the following condition is satisfied. Here, |S| denotes the length of the string S. Note that w must be less than |S|.
- If S is split at every w characters from the beginning, the concatenation of the c-th characters of the substrings of length at least c in order equals T.
Constraints
- S and T are strings consisting of lowercase English letters.
- 1 \leq |T| \leq |S| \leq 100
Input
The input is given from Standard Input in the following format:
S T
Output
Print Yes if there exists a pair of integers c and w such that 1 \leq c \leq w < |S| and the condition is satisfied, and No otherwise.
Sample Input 1
atcoder toe
Sample Output 1
Yes
If S is split at every two characters, it looks like this:
at co de r
Then, the concatenation of the 2nd characters of the substrings of length at least 2 is toe, which equals T. Thus, print Yes.
Sample Input 2
beginner r
Sample Output 2
No
w=|S| is not allowed, and no pair of integers 1 \leq c \leq w < |S| satisfies the condition. Thus, print No.
Sample Input 3
verticalreading agh
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
縦 H マス \times 横 W マスのマス目があり、各マスに 1 つずつ英小文字が書き込まれています。 上から i 行目かつ左から j 列目のマスを (i,j) で表します。
マス目に書き込まれている英小文字は H 個の長さ W の文字列 S_1,S_2,\ldots, S_H によって与えられ、 S_i の j 文字目が、(i, j) に書き込まれた英小文字を表します。
マス目の中に、s, n, u, k, e が
この順に(縦・横・ななめのいずれかの方向に) 連続して並んでいる
場所がただ 1 つ存在します。
そのような場所を見つけ、そのマスの位置を出力の形式に従って出力してください。
ただし、s, n, u, k, e が
この順に(縦・横・ななめのいずれかの方向に) 連続して並んでいる場所とは、
5 つのマスの組 (A_1,A_2,A_3,A_4,A_5) であって、次をすべてみたすものをさします。
- A_1,A_2,A_3,A_4,A_5 に書き込まれた英小文字はそれぞれ
s,n,u,k,eである。 - 1\leq i\leq 4 について、A_i と A_{i+1} は頂点または辺を共有している。
- A_1,A_2,A_3,A_4,A_5 の中心はこの順に一直線上に等間隔で並んでいる。
制約
- 5\leq H\leq 100
- 5\leq W\leq 100
- H,W は整数
- S_i は英小文字のみからなる長さ W の文字列
- 与えられるマス目の中に条件をみたす場所がただ 1 つ存在する
入力
入力は以下の形式で標準入力から与えられる。
H W S_1 S_2 \vdots S_H
出力
次の形式にしたがって、5 行出力せよ。
条件をみたす場所のうち s, n, u, k, e が書かれたマスがそれぞれ (R_1,C_1), (R_2,C_2)\ldots,(R_5,C_5) であるとき、
i 行目には R_i と C_i をこの順に空白区切りで出力せよ。
すなわち、以下のように出力せよ。
R_1 C_1 R_2 C_2 \vdots R_5 C_5
以下の入力例も参考にせよ。
入力例 1
6 6 vgxgpu amkxks zhkbpp hykink esnuke zplvfj
出力例 1
5 2 5 3 5 4 5 5 5 6
この時、(A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6)) とすると、
それぞれのマスに書き込まれた英小文字は s, n, u, k, e であり、
1\leq i\leq 4 について、A_i と A_{i+1} は辺を共有しており、
各マスの中心は一直線上に存在するため、条件をみたしています。

入力例 2
5 5 ezzzz zkzzz ezuzs zzznz zzzzs
出力例 2
5 5 4 4 3 3 2 2 1 1
(A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1)) が条件をみたしています。
例えば、(A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1)) は、1,2 つめの条件をみたしていますが、
マスの中心が一直線上に存在しないため、3 つめの条件をみたしていません。
入力例 3
10 10 kseeusenuk usesenesnn kskekeeses nesnusnkkn snenuuenke kukknkeuss neunnennue sknuessuku nksneekknk neeeuknenk
出力例 3
9 3 8 3 7 3 6 3 5 3
Score : 250 points
Problem Statement
There is a grid with H horizontal rows and W vertical columns. Each cell has a lowercase English letter written on it. We denote by (i, j) the cell at the i-th row from the top and j-th column from the left.
The letters written on the grid are represented by H strings S_1,S_2,\ldots, S_H, each of length W. The j-th letter of S_i represents the letter written on (i, j).
There is a unique set of
contiguous cells (going vertically, horizontally, or diagonally) in the grid
with s, n, u, k, and e written on them in this order.
Find the positions of such cells and print them in the format specified in the Output section.
A tuple of five cells (A_1,A_2,A_3,A_4,A_5) is said to form
a set of contiguous cells (going vertically, horizontally, or diagonally) with s, n, u, k, and e written on them in this order
if and only if all of the following conditions are satisfied.
- A_1,A_2,A_3,A_4 and A_5 have letters
s,n,u,k, andewritten on them, respectively. - For all 1\leq i\leq 4, cells A_i and A_{i+1} share a corner or a side.
- The centers of A_1,A_2,A_3,A_4, and A_5 are on a common line at regular intervals.
Constraints
- 5\leq H\leq 100
- 5\leq W\leq 100
- H and W are integers.
- S_i is a string of length W consisting of lowercase English letters.
- The given grid has a unique conforming set of cells.
Input
The input is given from Standard Input in the following format:
H W S_1 S_2 \vdots S_H
Output
Print five lines in the following format.
Let (R_1,C_1), (R_2,C_2)\ldots,(R_5,C_5) be the cells in the sought set with s, n, u, k, and e written on them, respectively.
The i-th line should contain R_i and C_i in this order, separated by a space.
In other words, print them in the following format:
R_1 C_1 R_2 C_2 \vdots R_5 C_5
See also Sample Inputs and Outputs below.
Sample Input 1
6 6 vgxgpu amkxks zhkbpp hykink esnuke zplvfj
Sample Output 1
5 2 5 3 5 4 5 5 5 6
Tuple (A_1,A_2,A_3,A_4,A_5)=((5,2),(5,3),(5,4),(5,5),(5,6)) satisfies the conditions.
Indeed, the letters written on them are s, n, u, k, and e;
for all 1\leq i\leq 4, cells A_i and A_{i+1} share a side;
and the centers of the cells are on a common line.

Sample Input 2
5 5 ezzzz zkzzz ezuzs zzznz zzzzs
Sample Output 2
5 5 4 4 3 3 2 2 1 1
Tuple (A_1,A_2,A_3,A_4,A_5)=((5,5),(4,4),(3,3),(2,2),(1,1)) satisfies the conditions.
However, for example, (A_1,A_2,A_3,A_4,A_5)=((3,5),(4,4),(3,3),(2,2),(3,1)) violates the third condition because the centers of the cells are not on a common line, although it satisfies the first and second conditions.
Sample Input 3
10 10 kseeusenuk usesenesnn kskekeeses nesnusnkkn snenuuenke kukknkeuss neunnennue sknuessuku nksneekknk neeeuknenk
Sample Output 3
9 3 8 3 7 3 6 3 5 3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君は数直線上の座標 0 の位置にいます。
これから高橋君は N 回のジャンプを行います。i \, (1 \leq i \leq N) 回目のジャンプでは、正の方向に a_i または b_i 移動します。
N 回のジャンプの後に座標 X の位置にいるようにすることはできますか?
制約
- 1 \leq N \leq 100
- 1 \leq a_i \lt b_i \leq 100 \, (1 \leq i \leq N)
- 1 \leq X \leq 10000
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N X a_1 b_1 \vdots a_N b_N
出力
N 回のジャンプの後に座標 X の位置にいるようにすることができるならば Yes と、そうでないなら No と出力せよ。
入力例 1
2 10 3 6 4 5
出力例 1
Yes
1 回目のジャンプでは b_1 (= 6) 移動し、2 回目のジャンプでは a_2 (= 4) 移動することで、座標 X (= 10) の位置にいるようにすることができます。
入力例 2
2 10 10 100 10 100
出力例 2
No
1 回目のジャンプの後に座標 X (= 10) の位置にいるようにすることはできますが、全てのジャンプの後に座標 X (= 10) の位置にいるようにすることはできません。
入力例 3
4 12 1 8 5 7 3 4 2 6
出力例 3
Yes
Score : 300 points
Problem Statement
Takahashi is standing at the coordinate 0 on a number line.
He will now perform N jumps. In the i-th jump (1 \leq i \leq N), he moves a_i or b_i in the positive direction.
Is it possible for him to be at the coordinate X after N jumps?
Constraints
- 1 \leq N \leq 100
- 1 \leq a_i \lt b_i \leq 100 \, (1 \leq i \leq N)
- 1 \leq X \leq 10000
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X a_1 b_1 \vdots a_N b_N
Output
If it is possible for Takahashi to be at the coordinate X after N jumps, print Yes; otherwise, print No.
Sample Input 1
2 10 3 6 4 5
Sample Output 1
Yes
By moving b_1 (= 6) in the first jump and a_2 (= 4) in the second jump, he can be at the coordinate X (= 10).
Sample Input 2
2 10 10 100 10 100
Sample Output 2
No
He can be at the coordinate X (= 10) after the first jump, but not after all jumps.
Sample Input 3
4 12 1 8 5 7 3 4 2 6
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
高橋君は医者のすぬけ君から N 種類の薬を処方されました。i 種類目の薬は(処方された日を含めて) a_i 日間、毎日 b_i 錠ずつ飲む必要があります。また、高橋君はこれ以外の薬を飲む必要がありません。
薬を処方された日を 1 日目とします。1 日目以降で、初めて高橋君がその日に飲む必要がある薬が K 錠以下になるのは何日目かを求めてください。
制約
- 1 \leq N \leq 3 \times 10^5
- 0 \leq K \leq 10^9
- 1 \leq a_i,b_i \leq 10^9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N K a_1 b_1 \vdots a_N b_N
出力
1 日目以降で、初めて高橋君がその日に飲む必要がある薬が K 錠以下になるのが X 日目の時、 X を出力せよ。
入力例 1
4 8 6 3 2 5 1 9 4 2
出力例 1
3
1 日目には、高橋君は 1,2,3,4 種類目の薬をそれぞれ 3,5,9,2 錠飲む必要があります。よってこの日は 19 錠飲む必要があり、K(=8) 錠以下ではありません。
2 日目には、高橋君は 1,2,4 種類目の薬をそれぞれ 3,5,2 錠飲む必要があります。よってこの日は 10 錠飲む必要があり、K(=8) 錠以下ではありません。
3 日目には、高橋君は 1,4 種類目の薬をそれぞれ 3,2 錠飲む必要があります。よってこの日は 5 錠飲む必要があり、初めて K(=8) 錠以下になります。
以上より、3 が答えです。
入力例 2
4 100 6 3 2 5 1 9 4 2
出力例 2
1
入力例 3
15 158260522 877914575 2436426 24979445 61648772 623690081 33933447 476190629 62703497 211047202 71407775 628894325 31963982 822804784 50968417 430302156 82631932 161735902 80895728 923078537 7723857 189330739 10286918 802329211 4539679 303238506 17063340 492686568 73361868 125660016 50287940
出力例 3
492686569
Score : 350 points
Problem Statement
Snuke the doctor prescribed N kinds of medicine for Takahashi. For the next a_i days (including the day of the prescription), he has to take b_i pills of the i-th medicine. He does not have to take any other medicine.
Let the day of the prescription be day 1. On or after day 1, when is the first day on which he has to take K pills or less?
Constraints
- 1 \leq N \leq 3 \times 10^5
- 0 \leq K \leq 10^9
- 1 \leq a_i,b_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N K a_1 b_1 \vdots a_N b_N
Output
If Takahashi has to take K pills or less on day X for the first time on or after day 1, print X.
Sample Input 1
4 8 6 3 2 5 1 9 4 2
Sample Output 1
3
On day 1, he has to take 3,5,9, and 2 pills of the 1-st, 2-nd, 3-rd, and 4-th medicine, respectively. In total, he has to take 19 pills on this day, which is not K(=8) pills or less.
On day 2, he has to take 3,5, and 2 pills of the 1-st, 2-nd, and 4-th medicine, respectively. In total, he has to take 10 pills on this day, which is not K(=8) pills or less.
On day 3, he has to take 3 and 2 pills of the 1-st and 4-th medicine, respectively. In total, he has to take 5 pills on this day, which is K(=8) pills or less for the first time.
Thus, the answer is 3.
Sample Input 2
4 100 6 3 2 5 1 9 4 2
Sample Output 2
1
Sample Input 3
15 158260522 877914575 2436426 24979445 61648772 623690081 33933447 476190629 62703497 211047202 71407775 628894325 31963982 822804784 50968417 430302156 82631932 161735902 80895728 923078537 7723857 189330739 10286918 802329211 4539679 303238506 17063340 492686568 73361868 125660016 50287940
Sample Output 3
492686569
実行時間制限: 3 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
H 行 W 列のグリッドがあります。上から i 行目、左から j 列目にあるマスをマス (i, j) で表します。
N 個のマス (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) は壁になっています。
はじめ、高橋君はマス (r_\mathrm{s}, c_\mathrm{s}) にいます。
高橋君に Q 個の指示が与えられます。
i = 1, 2, \ldots, Q について、i 番目の指示は文字 d_i と正整数 l_i の組で表されます。d_i は L 、R 、U 、D のいずれかの文字であり、それぞれ左、右、上、下の方向を表します。
i 番目の指示に対して高橋君は下記の行動を l_i 回繰り返します。
現在いるマスに対して、d_i が表す向きに壁のないマスが隣接しているなら、そのマスに移動する。 そのようなマスが存在しない場合は、何もしない。
i = 1, 2, \ldots, Q について、i 番目までの指示を実行した直後に高橋君がいるマスを出力してください。
制約
- 2 \leq H, W \leq 10^9
- 1 \leq r_\mathrm{s} \leq H
- 1 \leq c_\mathrm{s} \leq W
- 0 \leq N \leq 2 \times 10^5
- 1 \leq r_i \leq H
- 1 \leq c_i \leq W
- i \neq j \Rightarrow (r_i, c_i) \neq (r_j, c_j)
- すべての i = 1, 2, \ldots, Nについて、(r_\mathrm{s}, c_\mathrm{s}) \neq (r_i, c_i)
- 1 \leq Q \leq 2 \times 10^5
- d_i は
L、R、U、Dのいずれかの文字 - 1 \leq l_i \leq 10^9
- d_i 以外の入力値は整数
入力
入力は以下の形式で標準入力から与えられる。
H W r_\mathrm{s} c_\mathrm{s}
N
r_1 c_1
r_2 c_2
\vdots
r_N c_N
Q
d_1 l_1
d_2 l_2
\vdots
d_Q l_Q
出力
Q 行出力せよ。 下記の形式にしたがい、i = 1, 2, \ldots, Q について、i 番目までの指示を実行した直後に高橋君がいるマス (R_i, C_i) を i 行目に出力せよ。
R_1 C_1 R_2 C_2 \vdots R_Q C_Q
入力例 1
5 5 4 4 3 5 3 2 2 1 4 4 L 2 U 3 L 2 R 4
出力例 1
4 2 3 2 3 1 3 5
与えられるグリッドと高橋君の初期位置は下記の通りです。
ここで、# は壁のマスを、T は高橋君がいるマスを表し、. がその他のマスを表します。
...#. .#... ..... ...T. ..#..
1 つ目の指示に対して高橋君は、左に 2 マス移動し、高橋君の位置は下記の通り、マス (4, 2) になります。
...#. .#... ..... .T... ..#..
2 つ目の指示に対して高橋君は、上に 1 マスに移動した後、次の移動先が壁であるために「何もしない」を 2 回行います。その結果、高橋君の位置は下記の通り、マス (3, 2) になります。
...#. .#... .T... ..... ..#..
3 つ目の指示に対して高橋君は、左に 1 マス移動した後、次の移動先となるマスが存在しないために「何もしない」を 1 回行います。その結果、高橋君の位置は下記の通り、マス (3, 1) になります。
...#. .#... T.... ..... ..#..
4 つ目の指示に対して高橋君は、右に 4 マス移動し、高橋君の位置は下記の通り、マス (3, 5) になります。
...#. .#... ....T ..... ..#..
入力例 2
6 6 6 3 7 3 1 4 3 2 6 3 4 5 5 1 1 3 2 10 D 3 U 3 L 2 D 2 U 3 D 3 U 3 R 3 L 3 D 1
出力例 2
6 3 5 3 5 1 6 1 4 1 6 1 4 1 4 2 4 1 5 1
Score : 400 points
Problem Statement
There is a grid with H horizontal rows and W vertical columns. (i, j) denotes the square at the i-th row from the top and j-th column from the left.
N squares, (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N), have walls.
Takahashi is initially at square (r_\mathrm{s}, c_\mathrm{s}).
Q instructions are given to Takahashi.
For i = 1, 2, \ldots, Q, the i-th instruction is represented by a pair of a character d_i and a positive integer l_i. d_i is one of L, R, U, and D, representing the directions of left, right, up, and down, respectively.
Given the i-th direction, Takahashi repeats the following action l_i times:
If a square without a wall is adjacent to the current square in the direction represented by d_i, move to that square; otherwise, do nothing.
For i = 1, 2, \ldots, Q, print the square where Takahashi will be after he follows the first i instructions.
Constraints
- 2 \leq H, W \leq 10^9
- 1 \leq r_\mathrm{s} \leq H
- 1 \leq c_\mathrm{s} \leq W
- 0 \leq N \leq 2 \times 10^5
- 1 \leq r_i \leq H
- 1 \leq c_i \leq W
- i \neq j \Rightarrow (r_i, c_i) \neq (r_j, c_j)
- (r_\mathrm{s}, c_\mathrm{s}) \neq (r_i, c_i) for all i = 1, 2, \ldots, N.
- 1 \leq Q \leq 2 \times 10^5
- d_i is one of the characters
L,R,U, andD. - 1 \leq l_i \leq 10^9
- All values in the input other than d_i are integers.
Input
The input is given from Standard Input in the following format:
H W r_\mathrm{s} c_\mathrm{s}
N
r_1 c_1
r_2 c_2
\vdots
r_N c_N
Q
d_1 l_1
d_2 l_2
\vdots
d_Q l_Q
Output
Print Q lines. For i = 1, 2, \ldots, Q, the i-th line should contain the square (R_i, C_i) where Takahashi will be after he follows the first i instructions, in the following format:
R_1 C_1 R_2 C_2 \vdots R_Q C_Q
Sample Input 1
5 5 4 4 3 5 3 2 2 1 4 4 L 2 U 3 L 2 R 4
Sample Output 1
4 2 3 2 3 1 3 5
The given grid and the initial position of Takahashi are as follows, where # denotes a square with a wall, T a square where Takahashi is, and . the other squares:
...#. .#... ..... ...T. ..#..
Given the 1-st instruction, Takahashi moves 2 squares to the left, ending up in square (4, 2) as follows:
...#. .#... ..... .T... ..#..
Given the 2-nd instruction, Takahashi first moves 1 square upward, then he "does nothing" twice because the adjacent square in his direction has a wall. As a result, he ends up in square (3, 2) as follows:
...#. .#... .T... ..... ..#..
Given the 3-rd instruction, Takahashi first moves 1 square to the left, then he "does nothing" once because there is no square in his direction. As a result, he ends up in square (3, 1) as follows:
...#. .#... T.... ..... ..#..
Given the 4-th instruction, Takahashi moves 4 squares to the right, ending up in square (3, 5) as follows:
...#. .#... ....T ..... ..#..
Sample Input 2
6 6 6 3 7 3 1 4 3 2 6 3 4 5 5 1 1 3 2 10 D 3 U 3 L 2 D 2 U 3 D 3 U 3 R 3 L 3 D 1
Sample Output 2
6 3 5 3 5 1 6 1 4 1 6 1 4 1 4 2 4 1 5 1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
整数の組 (a, b, c) であって以下の条件を満たすものの個数を 998244353 で割ったあまりを求めてください。
- 1 \leq a,b,c \leq N
- a,b,c は相異なる。
- a を b で割ったあまりは c に等しい。
制約
- 3 \leq N \leq 10^{12}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを 1 行で出力せよ。
入力例 1
7
出力例 1
12
条件を満たす整数の組 (a,b,c) は以下の 12 通り存在します。
- (3,2,1)
- (4,3,1)
- (5,2,1)
- (5,3,2)
- (5,4,1)
- (6,4,2)
- (6,5,1)
- (7,2,1)
- (7,3,1)
- (7,4,3)
- (7,5,2)
- (7,6,1)
入力例 2
441
出力例 2
94700
入力例 3
411111111114
出力例 3
462474062
Score : 475 points
Problem Statement
Find the number, modulo 998244353, of integer tuples (a, b, c) that satisfy the following conditions.
- 1 \leq a,b,c \leq N
- a,b,c are pairwise distinct.
- The remainder when a is divided by b is equal to c.
Constraints
- 3 \leq N \leq 10^{12}
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Output the answer in one line.
Sample Input 1
7
Sample Output 1
12
There are 12 integer tuples (a,b,c) that satisfy the conditions:
- (3,2,1)
- (4,3,1)
- (5,2,1)
- (5,3,2)
- (5,4,1)
- (6,4,2)
- (6,5,1)
- (7,2,1)
- (7,3,1)
- (7,4,3)
- (7,5,2)
- (7,6,1)
Sample Input 2
441
Sample Output 2
94700
Sample Input 3
411111111114
Sample Output 3
462474062
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
1 から N までの番号がつけられた N 個の足場が一列に並んでいます。足場 i(1 \leq i \leq N) の高さは H_i です。
高橋君は足場に乗って移動する遊びをすることにしました。 最初、高橋君は整数 i(1 \leq i \leq N) を自由に選び、足場 i に乗ります。
高橋君はある時点で足場 i に乗っている時、以下の条件を満たす整数 j(1 \leq j \leq N) を選び足場 j に移動することができます。
- H_j \leq H_i - D かつ 1 \leq |i-j| \leq R
高橋君は移動を行えなくなるまで移動を繰り返すとき、移動できる回数の最大値を求めてください。
制約
- 1 \leq N \leq 5 \times 10^5
- 1 \leq D,R \leq N
- H は (1,2,\ldots,N) の順列
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N D R H_1 H_2 \ldots H_N
出力
答えを出力せよ。
入力例 1
5 2 1 5 3 1 4 2
出力例 1
2
高橋君は初めに足場 1 に乗り、以下のように足場を移動することができます。
- 1 回目の移動: H_2 \leq H_1 -D かつ |2-1| \leq R であるため足場 2 に移動することができる。足場 1 から足場 2 に移動する。
- 2 回目の移動: H_3 \leq H_2 -D かつ |3-2| \leq R であるため足場 3 に移動することができる。足場 2 から足場 3 に移動する。
- 足場 3 の高さは 1 であるため、これ以上移動できない。
以上のように 2 回移動することができます。また、どのように移動する足場を選んでも 3 回以上移動することはできません。よって、2 を出力します。
入力例 2
13 3 2 13 7 10 1 9 5 4 11 12 2 8 6 3
出力例 2
3
Score : 500 points
Problem Statement
There are N scaffolds numbered from 1 to N arranged in a line. The height of scaffold i(1 \leq i \leq N) is H_i.
Takahashi decides to play a game of moving on the scaffolds. Initially, he freely chooses an integer i(1 \leq i \leq N) and gets on scaffold i.
When he is on scaffold i at some point, he can choose an integer j(1 \leq j \leq N) satisfying the following condition and move to scaffold j:
- H_j \leq H_i - D and 1 \leq |i-j| \leq R.
Find the maximum number of moves he can make when he repeats moving until he can no longer move.
Constraints
- 1 \leq N \leq 5 \times 10^5
- 1 \leq D,R \leq N
- H is a permutation of (1,2,\ldots,N).
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N D R H_1 H_2 \ldots H_N
Output
Output the answer.
Sample Input 1
5 2 1 5 3 1 4 2
Sample Output 1
2
Takahashi initially gets on scaffold 1 and can move between the scaffolds as follows:
- First move: Since H_2 \leq H_1 -D and |2-1| \leq R, he can move to scaffold 2. Move from scaffold 1 to scaffold 2.
- Second move: Since H_3 \leq H_2 -D and |3-2| \leq R, he can move to scaffold 3. Move from scaffold 2 to scaffold 3.
- Since the height of scaffold 3 is 1, he can no longer move.
As shown above, he can move 2 times. Also, no matter how he chooses the scaffolds to move to, he cannot move 3 or more times. Therefore, output 2.
Sample Input 2
13 3 2 13 7 10 1 9 5 4 11 12 2 8 6 3
Sample Output 2
3