実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
高橋君が 100 階建てのビルにいます。
高橋君は 2 階分までの上り、または、3 階分までの下りであれば移動には階段を使い、そうでないときエレベーターを使います。
高橋君が X 階から Y 階への移動に使うのは階段ですか?
制約
- 1 \leq X,Y \leq 100
- X \neq Y
- 入力は全ては整数である
入力
入力は以下の形式で標準入力から与えられる。
X Y
出力
移動に使うのが階段ならば Yes、エレベーターならば No を出力せよ。
入力例 1
1 4
出力例 1
No
1 階から 4 階への移動は 3 階分の上りなのでエレベーターを使います。
入力例 2
99 96
出力例 2
Yes
99 階から 96 階への移動は 3 階分の下りなので階段を使います。
入力例 3
100 1
出力例 3
No
Score : 100 points
Problem Statement
Takahashi is in a building with 100 floors.
He uses the stairs for moving up two floors or less or moving down three floors or less, and uses the elevator otherwise.
Does he use the stairs to move from floor X to floor Y?
Constraints
- 1 \leq X,Y \leq 100
- X \neq Y
- All input values are integers.
Input
The input is given from Standard Input in the following format:
X Y
Output
If Takahashi uses the stairs for the move, print Yes; if he uses the elevator, print No.
Sample Input 1
1 4
Sample Output 1
No
The move from floor 1 to floor 4 involves going up three floors, so Takahashi uses the elevator.
Sample Input 2
99 96
Sample Output 2
Yes
The move from floor 99 to floor 96 involves going down three floors, so Takahashi uses the stairs.
Sample Input 3
100 1
Sample Output 3
No
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
AtCoder 村には N 本の橋があり、i 本目( i は 1 以上 N 以下の整数)の橋の高さは H_i です。
ここで、AtCoder 村にある N 本の橋のうち、どの相異なる 2 本の橋も高さが異なります。
AtCoder 村で最も高い橋は何本目の橋か出力してください。
制約
- 1\leq N \leq 100
- 1\leq H_i \leq 10^9
- H_i はすべて異なる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N H_1 H_2 \ldots H_N
出力
AtCoder 村で最も高い橋は何本目の橋かを、整数で出力せよ。
入力例 1
3 50 80 70
出力例 1
2
AtCoder 村には 3 本の橋があります。
1,2,3 本目の橋の高さはそれぞれ, 50,80,70 であり、
最も高い橋は 2 本目の橋です。
よって、2 を出力します。
入力例 2
1 1000000000
出力例 2
1
AtCoder 村に橋が 1 本しか存在しないため、2 本目以降の橋は存在せず、最も高い橋は 1 本目の橋となります。
入力例 3
10 22 75 26 45 72 81 47 29 97 2
出力例 3
9
AtCoder 村には 10 本の橋があり、それらのうち最も高い橋は 9 番目の橋(高さは 97 )です。
Score : 100 points
Problem Statement
There are N bridges in AtCoder Village. The height of the bridge numbered i is H_i (i is an integer between 1 and N).
Every two different bridges in the village have different heights.
Print the number representing the highest bridge in the village.
Constraints
- 1\leq N \leq 100
- 1\leq H_i \leq 10^9
- All H_i are different.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N H_1 H_2 \ldots H_N
Output
Print the integer representing the highest bridge in AtCoder village.
Sample Input 1
3 50 80 70
Sample Output 1
2
The village has three bridges.
The first, second, and third bridges have heights of 50, 80, and 70, respectively,
so the second bridge is the highest.
Thus, 2 should be printed.
Sample Input 2
1 1000000000
Sample Output 2
1
The village has only one bridge, so the first bridge is the highest.
Sample Input 3
10 22 75 26 45 72 81 47 29 97 2
Sample Output 3
9
The village has ten bridges, and the ninth bridge (with a height of 97) is the highest.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
横書きの文章が与えられます。縦書きに直してください。空白を
*で埋めてください。
N 個の、英小文字からなる文字列 S_1,S_2,\dots,S_N が与えられます。これらの文字列の長さの最大値を M とします。
以下の条件を満たす M 個の文字列 T_1,T_2,\dots,T_M を出力してください。
- 各 T_i は英小文字および
*からなる - 各 T_i の末尾は
*でない - 各 1 \leq i \leq N について、次が成り立つ
- 各 1 \leq j \leq |S_i| について、T_j の N-i+1 文字目が存在し、T_1,T_2,\dots,T_{|S_i|} それぞれの N-i+1 文字目をこの順に連結したものは S_i と一致する
- 各 |S_i| + 1 \leq j \leq M について、T_j の N-i+1 文字目は存在しないか、
*である
ただし、|S_i| で文字列 S_i の長さを表します。
制約
- N は 1 以上 100 以下の整数
- S_i は長さ 1 以上 100 以下の英小文字からなる文字列
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
答えを以下の形式で出力せよ。
T_1 T_2 \vdots T_M
入力例 1
3 abc de fghi
出力例 1
fda geb h*c i
T_3 の 2 文字目を * とすることで、 c が正しい位置に来ます。
T_4 の 2,3 文字目を * とした場合、T_4 の末尾が * となり、条件を満たしません。
入力例 2
3 atcoder beginner contest
出力例 2
cba oet ngc tio end sne ter *r
Score : 200 points
Problem Statement
You are given a horizontally written text. Convert it to vertical writing, filling spaces with
*.
You are given N strings S_1, S_2, \dots, S_N consisting of lowercase English letters. Let M be the maximum length of these strings.
Print M strings T_1, T_2, \dots, T_M that satisfy the following conditions:
- Each T_i consists of lowercase English letters and
*. - Each T_i does not end with
*. - For each 1 \leq i \leq N, the following holds:
- For each 1 \leq j \leq |S_i|, the (N-i+1)-th character of T_j exists, and the concatenation of the (N-i+1)-th characters of T_1, T_2, \dots, T_{|S_i|} in this order equals S_i.
- For each |S_i| + 1 \leq j \leq M, the (N-i+1)-th character of T_j either does not exist or is
*.
Here, |S_i| denotes the length of the string S_i.
Constraints
- N is an integer between 1 and 100, inclusive.
- Each S_i is a string of lowercase English letters with length between 1 and 100, inclusive.
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the answer in the following format:
T_1 T_2 \vdots T_M
Sample Input 1
3 abc de fghi
Sample Output 1
fda geb h*c i
Placing * as the 2nd character of T_3 puts the c in the correct position.
On the other hand, placing * as the 2nd and 3rd characters of T_4 would make T_4 end with *, which violates the condition.
Sample Input 2
3 atcoder beginner contest
Sample Output 2
cba oet ngc tio end sne ter *r
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
英小文字からなる文字列 S,T が与えられるので、 T が S の(連続する)部分文字列かどうか判定してください。
なお、文字列 X に以下の操作を 0 回以上施して文字列 Y が得られる時、またその時に限り Y は X の(連続する)部分文字列であると言います。
- 以下の 2 つの操作から 1 つを選択して、その操作を行う。
- X の先頭の 1 文字を削除する。
- X の末尾の 1 文字を削除する。
例えば tag は voltage の(連続する)部分文字列ですが、 ace は atcoder の(連続する)部分文字列ではありません。
制約
- S,T は英小文字からなる
- 1 \le |S|,|T| \le 100 ( |X| は文字列 X の長さ )
入力
入力は以下の形式で標準入力から与えられる。
S T
出力
T が S の(連続する)部分文字列なら Yes 、そうでないなら No と出力せよ。
入力例 1
voltage tag
出力例 1
Yes
tag は voltage の(連続する)部分文字列です。
入力例 2
atcoder ace
出力例 2
No
ace は atcoder の(連続する)部分文字列ではありません。
入力例 3
gorilla gorillagorillagorilla
出力例 3
No
入力例 4
toyotasystems toyotasystems
出力例 4
Yes
S=T である場合もあります。
Score : 200 points
Problem Statement
You are given strings S and T consisting of lowercase English letters. Determine whether T is a (contiguous) substring of S.
A string Y is said to be a (contiguous) substring of X if and only if Y can be obtained by performing the operation below on X zero or more times.
- Do one of the following.
- Delete the first character in X.
- Delete the last character in X.
For instance, tag is a (contiguous) substring of voltage, while ace is not a (contiguous) substring of atcoder.
Constraints
- S and T consist of lowercase English letters.
- 1 \le |S|,|T| \le 100 (|X| denotes the length of a string X.)
Input
The input is given from Standard Input in the following format:
S T
Output
If T is a (contiguous) substring of S, print Yes; otherwise, print No.
Sample Input 1
voltage tag
Sample Output 1
Yes
tag is a (contiguous) substring of voltage.
Sample Input 2
atcoder ace
Sample Output 2
No
ace is not a (contiguous) substring of atcoder.
Sample Input 3
gorilla gorillagorillagorilla
Sample Output 3
No
Sample Input 4
toyotasystems toyotasystems
Sample Output 4
Yes
It is possible that S=T.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
N 個の整数の組 (L_1,R_1),(L_2,R_2),\ldots,(L_N,R_N) が与えられます。
以下の条件を満たす長さ N の整数列 X=(X_1,X_2,\ldots,X_N) が存在するか判定し、存在するならば一つ出力してください。
- 各 i=1,2,\ldots,N に対して L_i\leq X_i\leq R_i
- \displaystyle \sum_{i=1}^N X_i=0
制約
- 1\leq N\leq 2\times 10^5
- -10^9\leq L_i\leq R_i\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L_1 R_1 L_2 R_2 \vdots L_N R_N
出力
存在しない場合は No を出力せよ。存在する場合は条件を満たす整数列 X を以下の形式で出力せよ。
Yes X_1 X_2 \ldots X_N
答えが複数存在する場合、どれを出力しても正解とみなされる。
入力例 1
3 3 5 -4 1 -2 3
出力例 1
Yes 4 -3 -1
数列 X=(4,-3,-1) は問題の条件をすべて満たします。ほかにも (3,-3,0) や (5,-4,-1) などが条件を満たします。
入力例 2
3 1 2 1 2 1 2
出力例 2
No
条件を満たす整数列 X は存在しません。
入力例 3
6 -87 12 -60 -54 2 38 -76 6 87 96 -17 38
出力例 3
Yes -66 -57 31 -6 89 9
Score : 350 points
Problem Statement
You are given N pairs of integers (L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N).
Determine whether there exists a sequence of N integers X = (X_1, X_2, \ldots, X_N) that satisfies the following conditions, and print one such sequence if it exists.
- L_i \leq X_i \leq R_i for each i = 1, 2, \ldots, N.
- \displaystyle \sum_{i=1}^N X_i = 0.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq L_i \leq R_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L_1 R_1 L_2 R_2 \vdots L_N R_N
Output
If no solution exists, print No. Otherwise, print an integer sequence X that satisfies the conditions in the following format:
Yes X_1 X_2 \ldots X_N
If multiple solutions exist, any of them will be considered correct.
Sample Input 1
3 3 5 -4 1 -2 3
Sample Output 1
Yes 4 -3 -1
The sequence X = (4, -3, -1) satisfies all the conditions. Other valid sequences include (3, -3, 0) and (5, -4, -1).
Sample Input 2
3 1 2 1 2 1 2
Sample Output 2
No
No sequence X satisfies the conditions.
Sample Input 3
6 -87 12 -60 -54 2 38 -76 6 87 96 -17 38
Sample Output 3
Yes -66 -57 31 -6 89 9
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
N 棟のビルが等間隔に一列に並んでいます。手前から i 番目のビルの高さは H_i です。
あなたは次の条件をともに満たすようにいくつかのビルを選んで電飾で飾ろうとしています。
- 選んだビルたちは高さが等しい
- 選んだビルたちは等間隔に並んでいる
最大でいくつのビルを選ぶことができますか? なお、ちょうど 1 つのビルを選んだときは条件を満たすとみなします。
制約
- 1 \leq N \leq 3000
- 1 \leq H_i \leq 3000
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N H_1 \ldots H_N
出力
答えを出力せよ。
入力例 1
8 5 7 5 7 7 5 7 7
出力例 1
3
手前から 2,5,8 番目のビルを選ぶと条件を満たします。
入力例 2
10 100 200 300 400 500 600 700 800 900 1000
出力例 2
1
1つのビルを選んだときは条件を満たすとみなします。
入力例 3
32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
出力例 3
3
Score : 350 points
Problem Statement
There are N buildings arranged in a line at equal intervals. The height of the i-th building from the front is H_i.
You want to decorate some of these buildings with illuminations so that both of the following conditions are satisfied:
- The chosen buildings all have the same height.
- The chosen buildings are arranged at equal intervals.
What is the maximum number of buildings you can choose? If you choose exactly one building, it is considered to satisfy the conditions.
Constraints
- 1 \leq N \leq 3000
- 1 \leq H_i \leq 3000
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N H_1 \ldots H_N
Output
Print the answer.
Sample Input 1
8 5 7 5 7 7 5 7 7
Sample Output 1
3
Choosing the 2nd, 5th, and 8th buildings from the front satisfies the conditions.
Sample Input 2
10 100 200 300 400 500 600 700 800 900 1000
Sample Output 2
1
Choosing just one building is considered to satisfy the conditions.
Sample Input 3
32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 350 点
問題文
正整数 N に対して、N を N 個つなげた整数を V_N とします。
より厳密には、N を文字列とみなしたものを N 個連結し、
それを再度整数とみなしたものを V_N とします。
例えば、V_3=333, V_{10}=10101010101010101010 です。
V_N を 998244353 で割った余りを求めてください。
制約
- 1\leq N\leq 10^{18}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
V_N を 998244353 で割った余りを出力せよ。
入力例 1
5
出力例 1
55555
V_5=55555 を 998244353 で割った余りは 55555 です。
入力例 2
9
出力例 2
1755646
V_9=999999999 を 998244353 で割った余りは 1755646 です。
入力例 3
10000000000
出力例 3
468086693
入力が 32 bit 整数型に収まらない可能性があることに注意してください。
Score : 350 points
Problem Statement
For a positive integer N, let V_N be the integer formed by concatenating N exactly N times.
More precisely, consider N as a string, concatenate N copies of it, and treat the result as an integer to get V_N.
For example, V_3=333 and V_{10}=10101010101010101010.
Find the remainder when V_N is divided by 998244353.
Constraints
- 1 \leq N \leq 10^{18}
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the remainder when V_N is divided by 998244353.
Sample Input 1
5
Sample Output 1
55555
The remainder when V_5=55555 is divided by 998244353 is 55555.
Sample Input 2
9
Sample Output 2
1755646
The remainder when V_9=999999999 is divided by 998244353 is 1755646.
Sample Input 3
10000000000
Sample Output 3
468086693
Note that the input may not fit into a 32-bit integer type.
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 475 点
問題文
長さ N の数列 A=(A_1,\ldots,A_N) が与えられます。
\displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^{N}\left\lfloor\frac{\max(A_i,A_j)}{\min(A_i,A_j)}\right\rfloor を求めてください。
ただし、\lfloor x \rfloor は x 以下の最大の整数を表します。例えば、\lfloor 3.14 \rfloor=3、\lfloor 2 \rfloor=2 です。
制約
- 2 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^6
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N
出力
答えを出力せよ。
入力例 1
3 3 1 4
出力例 1
8
求める値は
\left\lfloor\frac{\max(3,1)}{\min(3,1)}\right\rfloor + \left\lfloor\frac{\max(3,4)}{\min(3,4)}\right\rfloor + \left\lfloor\frac{\max(1,4)}{\min(1,4)}\right\rfloor\\ =\left\lfloor\frac{3}{1}\right\rfloor + \left\lfloor\frac{4}{3}\right\rfloor + \left\lfloor\frac{4}{1}\right\rfloor\\ =3+1+4\\ =8
となります。
入力例 2
6 2 7 1 8 2 8
出力例 2
53
入力例 3
12 3 31 314 3141 31415 314159 2 27 271 2718 27182 271828
出力例 3
592622
Score : 475 points
Problem Statement
You are given a sequence A=(A_1,\ldots,A_N) of length N.
Find \displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^{N}\left\lfloor\frac{\max(A_i,A_j)}{\min(A_i,A_j)}\right\rfloor.
Here, \lfloor x \rfloor represents the greatest integer not greater than x. For example, \lfloor 3.14 \rfloor=3 and \lfloor 2 \rfloor=2.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 \ldots A_N
Output
Print the answer.
Sample Input 1
3 3 1 4
Sample Output 1
8
The sought value is
\left\lfloor\frac{\max(3,1)}{\min(3,1)}\right\rfloor + \left\lfloor\frac{\max(3,4)}{\min(3,4)}\right\rfloor + \left\lfloor\frac{\max(1,4)}{\min(1,4)}\right\rfloor\\ =\left\lfloor\frac{3}{1}\right\rfloor + \left\lfloor\frac{4}{3}\right\rfloor + \left\lfloor\frac{4}{1}\right\rfloor\\ =3+1+4\\ =8.
Sample Input 2
6 2 7 1 8 2 8
Sample Output 2
53
Sample Input 3
12 3 31 314 3141 31415 314159 2 27 271 2718 27182 271828
Sample Output 3
592622
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
N 頂点の木 T が与えられます。各頂点には 0 から N-1 までの番号がついており、 i 番目 (1\le i\le N-1) の辺は頂点 u_i と頂点 v_i を双方向に繋いでいます。(頂点番号は 0-indexed で辺番号が 1-indexed であることに注意してください。)
0 以上 N 未満の整数の組 (i,j) に対し f(i,j) を以下のように定めます:
- 木 T の頂点 i から頂点 j までのパスに 含まれない 頂点のうち番号が最も小さい頂点の頂点番号。
- ただし、頂点 i から頂点 j までのパスに頂点 0 から頂点 N-1 まで全ての頂点が含まれる場合 f(i,j)=N とする。
木 T の頂点 i から頂点 j までのパスに頂点 i,j も含まれることに注意してください。
\displaystyle \sum_{0\le i \le j < N} f(i,j) の値を求めてください。
制約
- 2\le N\le 2\times 10^5
- 0\le u_i < v_i < N
- 入力で与えられるグラフは木
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}
出力
\displaystyle \sum_{0\le i \le j < N} f(i,j) の値を出力せよ。
入力例 1
2 0 1
出力例 1
3
f(0,0)=1,f(0,1)=2,f(1,1)=0 です。したがって、 1+2+0=3 を出力してください。
入力例 2
5 0 1 0 2 2 3 2 4
出力例 2
16
入力例 3
7 1 4 2 6 0 5 0 3 2 5 1 5
出力例 3
16
Score : 525 points
Problem Statement
You are given a tree T with N vertices. The vertices are numbered from 0 to N-1, and the i-th edge (1\le i\le N-1) bidirectionally connects vertices u_i and v_i. (Note that vertex numbers are 0-indexed and edge numbers are 1-indexed.)
For a pair of integers (i,j) where 0 \leq i,j < N, define f(i,j) as follows:
- The vertex number of the vertex with the smallest number among the vertices not included in the path from vertex i to vertex j in tree T.
- Here, if the path from vertex i to vertex j includes all vertices from vertex 0 to vertex N-1, let f(i,j)=N.
Note that the path from vertex i to vertex j in tree T includes vertices i and j.
Find the value of \displaystyle \sum_{0\le i \le j < N} f(i,j).
Constraints
- 2\le N\le 2\times 10^5
- 0\le u_i < v_i < N
- The graph given in the input is a tree.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
u_1 v_1
u_2 v_2
\vdots
u_{N-1} v_{N-1}
Output
Output the value of \displaystyle \sum_{0\le i \le j < N} f(i,j).
Sample Input 1
2 0 1
Sample Output 1
3
We have f(0,0)=1,f(0,1)=2,f(1,1)=0. Thus, output 1+2+0=3.
Sample Input 2
5 0 1 0 2 2 3 2 4
Sample Output 2
16
Sample Input 3
7 1 4 2 6 0 5 0 3 2 5 1 5
Sample Output 3
16