A - Signed Difficulty

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 100

問題文

実数 X.Y が与えられます。ただし Y はちょうど 1 桁です。

  • 0 \leq Y \leq 2 ならば、X-
  • 3 \leq Y \leq 6 ならば、X
  • 7 \leq Y \leq 9 ならば、X+

と出力してください。

制約

  • 1 \leq X \leq 15
  • 0 \leq Y \leq 9
  • XY は整数

入力

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

X.Y

出力

答えを出力せよ。


入力例 1

15.8

出力例 1

15+

15 + のような出力は不正解とみなされます。
X+ の間や、X- の間には空白を入れずに出力してください。


入力例 2

1.0

出力例 2

1-

1.001 などの値が入力として与えられることはありません。


入力例 3

12.5

出力例 3

12

Score : 100 points

Problem Statement

You are given a real number X.Y, where Y is a single digit.

Print the following: (quotes for clarity)

  • X-, if 0 \leq Y \leq 2;
  • X, if 3 \leq Y \leq 6;
  • X+, if 7 \leq Y \leq 9.

Constraints

  • 1 \leq X \leq 15
  • 0 \leq Y \leq 9
  • X and Y are integers.

Input

Input is given from Standard Input in the following format:

X.Y

Output

Print the answer.


Sample Input 1

15.8

Sample Output 1

15+

Here, printing 15 + will not be accepted: do not print a space between X and +, or between X and -.


Sample Input 2

1.0

Sample Output 2

1-

You will not get inputs such as 1.00 and 1.


Sample Input 3

12.5

Sample Output 3

12
B - Same Name

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 200

問題文

N 人の人がいます。i \, (1 \leq i \leq N) 人目の人の姓は S_i、名は T_i です。

同姓同名であるような人の組が存在するか、すなわち 1 \leq i \lt j \leq N かつ S_i=S_j かつ T_i=T_j を満たすような整数対 (i,j) が存在するか判定してください。

制約

  • 2 \leq N \leq 1000
  • N は整数
  • S_i,T_i は英小文字のみからなる長さ 1 以上 10 以下の文字列

入力

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

N
S_1 T_1
S_2 T_2
\hspace{0.6cm}\vdots
S_N T_N

出力

同姓同名であるような人の組が存在するなら Yes を、存在しないなら No を出力せよ。


入力例 1

3
tanaka taro
sato hanako
tanaka taro

出力例 1

Yes

1 人目の人と 3 人目の人が同姓同名です。


入力例 2

3
saito ichiro
saito jiro
saito saburo

出力例 2

No

同姓同名であるような人の組は存在しません。


入力例 3

4
sypdgidop bkseq
bajsqz hh
ozjekw mcybmtt
qfeysvw dbo

出力例 3

No

Score : 200 points

Problem Statement

There are N people. The family name and given name of the i-th person (1 \leq i \leq N) are S_i and T_i, respectively.

Determine whether there is a pair of people with the same family and given names. In other words, determine whether there is a pair of integers (i,j) such that 1 \leq i \lt j \leq N, S_i=S_j, and T_i=T_j.

Constraints

  • 2 \leq N \leq 1000
  • N is an integer.
  • Each of S_i and T_i is a string of length between 1 and 10 (inclusive) consisting of English lowercase letters.

Input

Input is given from Standard Input in the following format:

N
S_1 T_1
S_2 T_2
\hspace{0.6cm}\vdots
S_N T_N

Output

If there is a pair of people with the same family and given names, print Yes; otherwise, print No.


Sample Input 1

3
tanaka taro
sato hanako
tanaka taro

Sample Output 1

Yes

The first and third persons have the same family and given names.


Sample Input 2

3
saito ichiro
saito jiro
saito saburo

Sample Output 2

No

No two persons have the same family and given names.


Sample Input 3

4
sypdgidop bkseq
bajsqz hh
ozjekw mcybmtt
qfeysvw dbo

Sample Output 3

No
C - Many Balls

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 300

問題文

空の箱があります。
髙橋君は以下の 2 種類の魔法を好きな順番で好きな回数使えます。

  • 魔法 A :箱の中にボールを 1 つ増やす
  • 魔法 B :箱の中のボールの数を 2 倍にする

合計 \mathbf{120} 回以内の魔法で、箱の中のボールの数をちょうど N 個にする方法を 1 つ教えてください。
なお、与えられた制約のもとで条件を満たす方法が必ず存在することが示せます。

魔法以外の方法でボールの数を変化させることはできません。

制約

  • 1 \leq N \leq 10^{18}
  • 入力は全て整数

入力

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

N

出力

A , B のみからなる文字列 S を出力せよ。
Si 文字目が A ならば、髙橋君が i 回目に使う魔法が魔法 A であることを表し、B ならば魔法 B であることを表す。

S の長さは \mathbf{120} 以下でなければならない。


入力例 1

5

出力例 1

AABA

ボールの数は、0 \xrightarrow{A} 1\xrightarrow{A} 2 \xrightarrow{B}4\xrightarrow{A} 5 と変化します。
AAAAA などの答えも正解になります。


入力例 2

14

出力例 2

BBABBAAAB

ボールの数は、0 \xrightarrow{B} 0 \xrightarrow{B} 0 \xrightarrow{A}1 \xrightarrow{B} 2 \xrightarrow{B} 4 \xrightarrow{A}5 \xrightarrow{A}6 \xrightarrow{A} 7 \xrightarrow{B}14 と変化します。
S の長さを最小化する必要はありません。

Score : 300 points

Problem Statement

We have an empty box.
Takahashi can cast the following two spells any number of times in any order.

  • Spell A: puts one new ball into the box.
  • Spell B: doubles the number of balls in the box.

Tell us a way to have exactly N balls in the box with at most \mathbf{120} casts of spells.
It can be proved that there always exists such a way under the Constraints given.

There is no way other than spells to alter the number of balls in the box.

Constraints

  • 1 \leq N \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print a string S consisting of A and B. The i-th character of S should represent the spell for the i-th cast.

S must have at most \mathbf{120} characters.


Sample Input 1

5

Sample Output 1

AABA

This changes the number of balls as follows: 0 \xrightarrow{A} 1\xrightarrow{A} 2 \xrightarrow{B}4\xrightarrow{A} 5.
There are also other acceptable outputs, such as AAAAA.


Sample Input 2

14

Sample Output 2

BBABBAAAB

This changes the number of balls as follows: 0 \xrightarrow{B} 0 \xrightarrow{B} 0 \xrightarrow{A}1 \xrightarrow{B} 2 \xrightarrow{B} 4 \xrightarrow{A}5 \xrightarrow{A}6 \xrightarrow{A} 7 \xrightarrow{B}14.
It is not required to minimize the length of S.

D - Pair of Balls

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 400

問題文

2N 個のボールがあります。各ボールには 1 以上 N 以下の整数によって表される色が塗られており、各色で塗られたボールはちょうど 2 個ずつ存在します。

これらのボールが、底が地面と平行になるように置かれた M 本の筒に入れられています。はじめ、i \ (1 \leq i \leq M) 本目の筒には k_i 個のボールが入っており、上から j \ (1 \leq j \leq k_i) 番目のボールの色は a_{i, j} です。

あなたの目標は、以下の操作を繰り返すことで M 本の筒全てを空にすることです。

  • 異なる 2 本の空でない筒を選び、それぞれの筒の一番上にあるボールを取り出して捨てる。ここで、取り出して捨てた 2 つのボールは同じ色で塗られている必要がある。

目標が達成可能かを判定してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 2 \leq M \leq 2 \times 10^5
  • 1 \leq k_i\ (1 \leq i \leq M)
  • 1 \leq a_{i,j} \leq N\ (1 \leq i \leq M,1 \leq j \leq k_i)
  • \sum_{i=1}^{M} k_i = 2N
  • 全ての x\ (1 \leq x \leq N) について、1 \leq i \leq M かつ 1 \leq j \leq k_i かつ a_{i,j}=x なる整数の組 (i,j) はちょうど 2 つ存在する
  • 入力は全て整数

入力

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

N M
k_1
a_{1,1} a_{1,2} \ldots a_{1,k_1}
k_2
a_{2,1} a_{2,2} \ldots a_{2,k_2}
\hspace{2.1cm}\vdots
k_M
a_{M,1} a_{M,2} \ldots a_{M,k_M}

出力

目標が達成可能なら Yes を、達成不可能なら No を出力せよ。


入力例 1

2 2
2
1 2
2
1 2

出力例 1

Yes

以下のように操作を行えばよいです。

  1. 1 つ目の筒と 2 つ目の筒を選び、それぞれの筒の一番上にあるボールを取り出して捨てる。捨てられるボールの色は共に 1 であり等しいので、この操作は有効である。
  2. 1 つ目の筒と 2 つ目の筒を選び、それぞれの筒の一番上にあるボールを取り出して捨てる。捨てられるボールの色は共に 2 であり等しいので、この操作は有効である。

入力例 2

2 2
2
1 2
2
2 1

出力例 2

No

そもそも一度も操作を行うことができないため、目標を達成する、すなわち M 本の筒全てを空にすることは不可能です。

Score : 400 points

Problem Statement

We have 2N balls. Each ball has a color represented by an integer between 1 and N (inclusive). For each of the N colors, there are exactly two balls of that color.

These balls are contained in M cylinders placed perpendicularly to the floor. Initially, the i-th cylinder (1 \leq i \leq M) contains k_i balls, the j-th of which from the top (1 \leq j \leq k_i) has the color a_{i, j}.

Your objective is to empty all M cylinders by repeating the following operation.

  • Choose two different non-empty cylinders and remove the topmost ball from each of them. Here, the two balls removed must be of the same color.

Determine whether the objective is achievable.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 2 \leq M \leq 2 \times 10^5
  • 1 \leq k_i\ (1 \leq i \leq M)
  • 1 \leq a_{i,j} \leq N\ (1 \leq i \leq M,1 \leq j \leq k_i)
  • \sum_{i=1}^{M} k_i = 2N
  • For every x\ (1 \leq x \leq N), there exists exactly two pairs of integers (i,j) such that 1 \leq i \leq M, 1 \leq j \leq k_i, and a_{i,j}=x.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
k_1
a_{1,1} a_{1,2} \ldots a_{1,k_1}
k_2
a_{2,1} a_{2,2} \ldots a_{2,k_2}
\hspace{2.1cm}\vdots
k_M
a_{M,1} a_{M,2} \ldots a_{M,k_M}

Output

If the objective is achievable, print Yes; otherwise, print No.


Sample Input 1

2 2
2
1 2
2
1 2

Sample Output 1

Yes

The objective can be achieved as follows.

  1. Choose the first and second cylinders to remove the topmost ball from each of them, which is allowed since the removed balls have the same color: 1.
  2. Choose the first and second cylinders to remove the topmost ball from each of them, which is allowed since the removed balls have the same color: 2.

Sample Input 2

2 2
2
1 2
2
2 1

Sample Output 2

No

No operation can be done at all, which means it is impossible to achieve the objective of emptying the M cylinders.

E - Amusement Park

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 500

問題文

髙橋君は遊園地に遊びに行きました。
この遊園地には N 個のアトラクションがあり、i 個目のアトラクションの「楽しさ」の初期値は A_i です。

髙橋君が i 個目のアトラクションに乗ると、以下の現象が順番に起きます。

  • 髙橋君の「満足度」に、i 個目のアトラクションの現在の「楽しさ」が加算される。
  • i 個目のアトラクションの「楽しさ」が、1 減少する。

髙橋君の「満足度」の初期値は 0 です。髙橋君はアトラクションに合計 K 回まで乗ることができます。
最終的な髙橋君の「満足度」の最大値はいくつですか?

なお、髙橋君の「満足度」はアトラクションに乗ること以外で変化しません。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq K \leq 2 \times 10^9
  • 1 \leq A_i \leq 2 \times 10^9
  • 入力は全て整数

入力

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

N K
A_1 A_2 \dots A_N

出力

最終的な髙橋君の「満足度」の最大値を出力せよ。


入力例 1

3 5
100 50 102

出力例 1

502

1 個目のアトラクションに 2 回、3 個目のアトラクションに 3 回乗ります。
最終的な「満足度」は、(100+99)+(102+101+100)=502 です。
「満足度」を 503 以上にする方法はないので、502 が答えになります。


入力例 2

2 2021
2 3

出力例 2

9

アトラクションに乗る合計回数は、K 回より少なくても構いません。

Score : 500 points

Problem Statement

Takahashi has come to an amusement park.
The park has N attractions. The fun of the i-th attraction is initially a_i.

When Takahashi rides the i-th attraction, the following sequence of events happens.

  • Takahashi's satisfaction increases by the current fun of the i-th attraction.
  • Then, the fun of the i-th attraction decreases by 1.

Takahashi's satisfaction is initially 0. He can ride the attractions at most K times in total in any order.
What is the maximum possible value of satisfaction Takahashi can end up with?

Other than riding the attractions, nothing affects Takahashi's satisfaction.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq K \leq 2 \times 10^9
  • 1 \leq A_i \leq 2 \times 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the maximum possible value of satisfaction that Takahashi can end up with.


Sample Input 1

3 5
100 50 102

Sample Output 1

502

Takahashi should ride the first attraction twice and the third attraction three times.
He will end up with the satisfaction of (100+99)+(102+101+100)=502.
There is no way to get the satisfaction of 503 or more, so the answer is 502.


Sample Input 2

2 2021
2 3

Sample Output 2

9

Takahashi may choose to ride the attractions fewer than K times in total.

F - Max Sum Counting

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 500

問題文

長さ N の数列 A = (A_1, \dots, A_N), B = (B_1, \dots, B_N) が与えられます。\{1,2,\ldots,N\} の空でない部分集合 S であって、以下の条件を満たすものの個数を数えてください。

  • \max_{i \in S} A_i \geq \sum_{i \in S} B_i

なお、答えは非常に大きくなることがあるため、998244353 で割ったあまりを出力してください。

制約

  • 1 \leq N \leq 5000
  • 1 \leq A_i,B_i \leq 5000
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

出力

問題文中の条件を満たす S の個数を 998244353 で割ったあまりを出力せよ。


入力例 1

2
3 1
1 2

出力例 1

2

\{1,2,\ldots,N\} の空でない部分集合としてあり得るものは、\{1\}, \{2\}, \{1,2\}3 通りです。

  • S=\{1\} のとき \max_{i \in S} A_i=3, \sum_{i \in S} B_i=1
  • S=\{2\} のとき \max_{i \in S} A_i=1, \sum_{i \in S} B_i=2
  • S=\{1,2\} のとき \max_{i \in S} A_i=3, \sum_{i \in S} B_i=3

であるため、問題文中の条件、即ち \max_{i \in S} A_i \geq \sum_{i \in S} B_i を満たす S\{1\}\{1,2\}2 通りです。


入力例 2

2
1 1
2 2

出力例 2

0

条件を満たす S が存在しない場合もあります。


入力例 3

20
1937 3980 2689 1208 3640 1979 581 2271 4229 3948 3708 1522 4161 4661 3797 96 3388 3395 2920 2247
4485 2580 174 1156 3770 3396 3558 3500 3494 479 269 3383 1230 1711 3545 3919 134 475 3796 1017

出力例 3

476

Score : 500 points

Problem Statement

Given are sequences of N integers each: A = (A_1, \dots, A_N) and B = (B_1, \dots, B_N). Find the number of non-empty subsets S of \{1,2,\ldots,N\} that satisfy the following condition:

  • \max_{i \in S} A_i \geq \sum_{i \in S} B_i.

Since the count can be enormous, print it modulo 998244353.

Constraints

  • 1 \leq N \leq 5000
  • 1 \leq A_i,B_i \leq 5000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

Output

Print the number of subsets S that satisfy the condition in the Problem Statement, modulo 998244353.


Sample Input 1

2
3 1
1 2

Sample Output 1

2

\{1,2,\ldots,N\} has three subsets: \{1\}, \{2\}, and \{1,2\}.

  • For S=\{1\}, we have \max_{i \in S} A_i=3 and \sum_{i \in S} B_i=1.
  • For S=\{2\}, we have \max_{i \in S} A_i=1 and \sum_{i \in S} B_i=2.
  • For S=\{1,2\}, we have \max_{i \in S} A_i=3 and \sum_{i \in S} B_i=3.

Thus, the condition \max_{i \in S} A_i \geq \sum_{i \in S} B_i is satisfied by two subsets: \{1\} and \{1,2\}.


Sample Input 2

2
1 1
2 2

Sample Output 2

0

There may be no subsets that satisfy the condition.


Sample Input 3

20
1937 3980 2689 1208 3640 1979 581 2271 4229 3948 3708 1522 4161 4661 3797 96 3388 3395 2920 2247
4485 2580 174 1156 3770 3396 3558 3500 3494 479 269 3383 1230 1711 3545 3919 134 475 3796 1017

Sample Output 3

476
G - 01Sequence

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 600

問題文

01 のみからなる長さ N の数列 A=(A_1,A_2,\dots,A_N) であって、以下の条件を満たすものを考えます。

すべての i=1,2,\dots,M について、A_{L_i}, A_{L_i+1},\dots ,A_{R_i}1X_i 個以上含まれる

条件を満たす数列 A のうち、含まれる 1 の数が最も少ない例を 1 つ出力してください。

なお、制約のもとで条件を満たす数列 A は必ず存在します。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq \min(2 \times 10^5, \frac{N(N+1)}{2} )
  • 1 \leq L_i \leq R_i \leq N
  • 1 \leq X_i \leq R_i-L_i+1
  • i \neq j ならば (L_i,R_i) \neq (L_j,R_j)
  • 入力は全て整数

入力

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

N M
L_1 R_1 X_1
L_2 R_2 X_2
\vdots
L_M R_M X_M

出力

01 のみからなる数列 A を空白区切りで出力せよ。

A_1 A_2 \dots A_N

数列 A は上記の条件を全て満たさなければならない。


入力例 1

6 3
1 4 3
2 2 1
4 6 2

出力例 1

0 1 1 1 0 1 

1 1 0 1 1 0 などの答えも正解です。
0 1 1 1 1 1 などの答えは含まれる 1 の数が最小化されていないので、不正解です。


入力例 2

8 2
2 6 1
3 5 3

出力例 2

0 0 1 1 1 0 0 0 

Score : 600 points

Problem Statement

Consider a sequence of length N consisting of 0s and 1s, A=(A_1,A_2,\dots,A_N), that satisfies the following condition.

For every i=1,2,\dots,M, there are at least X_i occurrences of 1 among A_{L_i}, A_{L_i+1}, \dots, A_{R_i}.

Print one such sequence with the fewest number of occurrences of 1s.

There always exists a sequence that satisfies the condition under the Constraints.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq \min(2 \times 10^5, \frac{N(N+1)}{2} )
  • 1 \leq L_i \leq R_i \leq N
  • 1 \leq X_i \leq R_i-L_i+1
  • (L_i,R_i) \neq (L_j,R_j) if i \neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1 X_1
L_2 R_2 X_2
\vdots
L_M R_M X_M

Output

Print a sequence A consisting of 0s and 1s, with spaces in between.

A_1 A_2 \dots A_N

It must satisfy all the requirements above.


Sample Input 1

6 3
1 4 3
2 2 1
4 6 2

Sample Output 1

0 1 1 1 0 1 

Another acceptable output is 1 1 0 1 1 0.
On the other hand, 0 1 1 1 1 1, which has more than the fewest number of 1s, is unacceptable.


Sample Input 2

8 2
2 6 1
3 5 3

Sample Output 2

0 0 1 1 1 0 0 0 
H - Random Robots

実行時間制限: 2 sec / メモリ制限: 1024 MB

Score : 600 points

Problem Statement

There are K robots on a number line. The i-th robot (1 \leq i \leq K) is initially at the coordinate x_i.

The following procedure is going to take place exactly N times.

  • Each robot chooses to move or not with probability \frac{1}{2} each. The robots that move will simultaneously go the distance of 1 in the positive direction, and the other robots will remain still.

Here, all probabilistic decisions are independent.

Find the probability that no two robots meet, that is, there are never two or more robots at the same coordinate at the same time throughout the procedures, modulo 998244353 (see Notes).

Notes

It can be proved that the probability in question is always a rational number. Additionally, under the Constraints in this problem, when that value is represented as \frac{P}{Q} using two coprime integers P and Q, it can be proved that there uniquely exists an integer R such that R \times Q \equiv P\pmod{998244353} and 0 \leq R \lt 998244353. Find this R.

Constraints

  • 2 \leq K \leq 10
  • 1 \leq N \leq 1000
  • 0 \leq x_1 \lt x_2 \lt \cdots \lt x_K \leq 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

K N
x_1 x_2 \ldots x_K

Output

Print the answer.


Sample Input 1

2 2
1 2

Sample Output 1

374341633

The probability in question is \frac{5}{8}.

We have 374341633 \times 8 \equiv 5\pmod{998244353}, so you should print 374341633.


Sample Input 2

2 2
10 100

Sample Output 2

1

The probability in question may be 1.


Sample Input 3

10 832
73 160 221 340 447 574 720 742 782 970

Sample Output 3

553220346

配点 : 600

問題文

数直線上に K 個のロボットが置かれています。i \, (1 \leq i \leq K) 番目のロボットははじめ、座標 x_i に存在します。

これから以下の操作をちょうど N 回行います。

  • K 個のロボットそれぞれについて、「進む」か「止まる」かを確率 \frac{1}{2} で決める。「進む」と決めたロボットたちは同時に正の方向に 1 進み、「止まる」と決めたロボットたちはその場から動かない。

ただし、すべての確率的な決定は独立であるとします。

一連の操作の中で、複数のロボットが出会う、すなわち 2 個以上のロボットが同時に同じ座標に存在する、という事象が一度も起こらない確率を\mod 998244353 で求めてください(注記参照)。

注記

求める確率は必ず有理数となることが証明できます。またこの問題の制約下では、その値を互いに素な 2 つの整数 P, Q を用いて \frac{P}{Q} と表したとき、R \times Q \equiv P\pmod{998244353} かつ 0 \leq R \lt 998244353 を満たす整数 R がただ一つ存在することが証明できます。この R を求めてください。

制約

  • 2 \leq K \leq 10
  • 1 \leq N \leq 1000
  • 0 \leq x_1 \lt x_2 \lt \cdots \lt x_K \leq 1000
  • 入力は全て整数

入力

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

K N
x_1 x_2 \ldots x_K

出力

答えを出力せよ。


入力例 1

2 2
1 2

出力例 1

374341633

求める確率は \frac{5}{8} です。

374341633 \times 8 \equiv 5\pmod{998244353} ですので、374341633 を出力します。


入力例 2

2 2
10 100

出力例 2

1

求める確率が 1 であることもあります。


入力例 3

10 832
73 160 221 340 447 574 720 742 782 970

出力例 3

553220346