E - 1111gal password

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

配点 : 300

問題文

整数 N が与えられるので、以下の条件を全て満たす整数 X の個数を 998244353 で割った余りを求めてください。

  • N 桁の正整数である。
  • X の各桁を上の位から順に X_1,X_2,\dots,X_N とする。このとき以下の条件を全て満たす。
    • 全ての整数 1 \le i \le N に対して、 1 \le X_i \le 9
    • 全ての整数 1 \le i \le N-1 に対して、 |X_i-X_{i+1}| \le 1

制約

  • N は整数
  • 2 \le N \le 10^6

入力

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

N

出力

答えを整数として出力せよ。


入力例 1

4

出力例 1

203

4 桁の整数として、例えば 1111,1234,7878,6545 が問題文中の条件を満たします。


入力例 2

2

出力例 2

25

入力例 3

1000000

出力例 3

248860093

998244353 で割った余りを求めることに注意してください。

Score : 300 points

Problem Statement

Given an integer N, find the number of integers X that satisfy all of the following conditions, modulo 998244353.

  • X is an N-digit positive integer.
  • Let X_1,X_2,\dots,X_N be the digits of X from top to bottom. They satisfy all of the following:
    • 1 \le X_i \le 9 for all integers 1 \le i \le N;
    • |X_i-X_{i+1}| \le 1 for all integers 1 \le i \le N-1.

Constraints

  • N is an integer.
  • 2 \le N \le 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

4

Sample Output 1

203

Some of the 4-digit integers satisfying the conditions are 1111,1234,7878,6545.


Sample Input 2

2

Sample Output 2

25

Sample Input 3

1000000

Sample Output 3

248860093

Be sure to find the count modulo 998244353.

F - abc285_brutmhyhiizp

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

配点 : 300

問題文

別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。

つまり、 ID は以下の順番で付けられています。

  • 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
  • ...

このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。

制約

  • S は AtCoder Big Contest に含まれる問題の ID として正しい

入力

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

S

出力

答えを整数として出力せよ。


入力例 1

AB

出力例 1

28

ID が AB である問題は、 AtCoder Big Contest の 28 問目です。


入力例 2

C

出力例 2

3

ID が C である問題は、 AtCoder Big Contest の 3 問目です。


入力例 3

BRUTMHYHIIZP

出力例 3

10000000000000000

ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。

Score : 300 points

Problem Statement

In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...

In other words, the IDs are given in the following order:

  • the strings of length 1 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 2 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 3 consisting of uppercase English letters, in lexicographical order;
  • ...

Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)

Constraints

  • S is a valid ID of a problem given in AtCoder Big Contest.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

AB

Sample Output 1

28

The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.


Sample Input 2

C

Sample Output 2

3

The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.


Sample Input 3

BRUTMHYHIIZP

Sample Output 3

10000000000000000

The problem whose ID is BRUTMHYHIIZP is the 10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.

G - Prefix K-th Max

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

配点 : 400

問題文

(1,2,\ldots,N) の順列 P=(P_1,P_2,\ldots,P_N)、および正整数 K が与えられます。

i=K,K+1,\ldots,N について、以下を求めてください。

  • P の先頭 i 項のうち、K 番目に大きい値

制約

  • 1 \leq K \leq N \leq 5 \times 10^5
  • (P_1,P_2,\ldots,P_N)(1,2,\ldots,N) の並び替えによって得られる
  • 入力はすべて整数

入力

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

N K
P_1 P_2 \ldots P_N

出力

i=K,K+1,\ldots,N についてこの順に、問題文中で問われている値を改行区切りで出力せよ。


入力例 1

3 2
1 2 3

出力例 1

1
2
  • P の先頭 2 項、すなわち (P_1,P_2)=(1,2) の中で K=2 番目に大きい値は 1 となります。
  • P の先頭 3 項、すなわち (P_1,P_2,P_3)=(1,2,3) の中で K=2 番目に大きい値は 2 となります。

入力例 2

11 5
3 7 2 5 11 6 1 9 8 10 4

出力例 2

2
3
3
5
6
7
7

Score : 400 points

Problem Statement

Given are a permutation P=(P_1,P_2,\ldots,P_N) of (1,2,\ldots,N) and a positive integer K.

For each i=K,K+1,\ldots,N, find the following.

  • The K-th greatest value among the first i terms of P.

Constraints

  • 1 \leq K \leq N \leq 5 \times 10^5
  • (P_1,P_2,\ldots,P_N) is a permutation of (1,2,\ldots,N).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
P_1 P_2 \ldots P_N

Output

For each i=K, K+1, \ldots, N, in this order, print the specified value in Problem Statement, separated by newlines.


Sample Input 1

3 2
1 2 3

Sample Output 1

1
2
  • The (K=) 2-nd greatest value among the first 2 terms of P, (P_1,P_2)=(1,2), is 1.
  • The (K=) 2-nd greatest value among the first 3 terms of P, (P_1,P_2,P_3)=(1,2,3), is 2.

Sample Input 2

11 5
3 7 2 5 11 6 1 9 8 10 4

Sample Output 2

2
3
3
5
6
7
7
H - K-colinear Line

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

配点 : 500

問題文

座標平面上の N 個の点が与えられます。 1\leq i\leq N について、i 番目の点の座標は (X_i, Y_i) です。

座標平面上の直線であって、N 個の点のうち K 個以上の点を通るものの個数を求めてください。
ただし、そのようなものが無数に存在する場合は Infinity を出力してください。

制約

  • 1 \leq K \leq N \leq 300
  • \lvert X_i \rvert, \lvert Y_i \rvert \leq 10^9
  • i\neq j ならば X_i\neq X_j または Y_i\neq Y_j
  • 入力はすべて整数

入力

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

N K
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

与えられた N 個の点のうち K 個以上の点を通る直線の数を出力せよ。ただし、そのようなものが無数に存在する場合は Infinity を出力せよ。


入力例 1

5 2
0 0
1 0
0 1
-1 0
0 -1

出力例 1

6

x=0, y=0, y=x\pm 1, y=-x\pm 16 本の直線が条件をみたします。
例えば、x=0 は、1, 3, 5 番目の 3 個の点を通ります。

よって、6 を出力します。


入力例 2

1 1
0 0

出力例 2

Infinity

原点を通る直線は無数に存在します。 よって、Infinity を出力します。

Score : 500 points

Problem Statement

You are given N points in the coordinate plane. For each 1\leq i\leq N, the i-th point is at the coordinates (X_i, Y_i).

Find the number of lines in the plane that pass K or more of the N points.
If there are infinitely many such lines, print Infinity.

Constraints

  • 1 \leq K \leq N \leq 300
  • \lvert X_i \rvert, \lvert Y_i \rvert \leq 10^9
  • X_i\neq X_j or Y_i\neq Y_j, if i\neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print the number of lines in the plane that pass K or more of the N points, or Infinity if there are infinitely many such lines.


Sample Input 1

5 2
0 0
1 0
0 1
-1 0
0 -1

Sample Output 1

6

The six lines x=0, y=0, y=x\pm 1, and y=-x\pm 1 satisfy the requirement.
For example, x=0 passes the first, third, and fifth points.

Thus, 6 should be printed.


Sample Input 2

1 1
0 0

Sample Output 2

Infinity

Infinitely many lines pass the origin.

Thus, Infinity should be printed.

I - Two Exams

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

配点 : 500

問題文

高橋王国にて、 1 から N までの番号のついた N 人の国民が競技プログラミングの試験に参加しました。
試験は 2 回からなり、人 i1 回目の試験で P_i 位、 2 回目の試験で Q_i 位となりました。
なお、どちらの試験においても、複数人が同じ順位になることはありませんでした。すなわち、順位を表す数列 P,Q はそれぞれ (1,2,...,N) の順列です。

高橋王国の大統領であるいろはちゃんは、この試験の結果に基づいて、 N 人の中から競技プログラミングの世界大会に出場する K 人の代表を決めることになりました。
代表を決めるにあたって、以下が成立していなければなりません。

  • x が代表であり、人 y が代表でないような人の組 (x,y) であって、 P_x > P_y かつ Q_x > Q_y であるようなものが存在してはならない。
    • 言い換えると、 2 回の試験の双方で人 y が人 x よりも小さい順位を取っているにも拘らず、人 x が代表で人 y が代表でないということがあってはならない。

いろはちゃんは、ひとまず上記の条件を満たす代表の選び方の数を知りたいので、この数を求めてください。
ただし、この数は非常に大きくなる場合もあるので、 998244353 で割った余りを出力してください。

制約

  • 入力は全て整数
  • 1 \le N \le 300
  • 1 \le K \le N
  • P,Q(1,2,...,N) の順列である。

入力

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

N K
P_1 P_2 \dots P_N
Q_1 Q_2 \dots Q_N

出力

答えを整数として出力せよ。


入力例 1

4 2
2 4 3 1
2 1 4 3

出力例 1

3
  • 1 と人 2 を代表にすることは問題ありません。
  • 1 と人 3 を代表にすると、双方の試験で人 4 が人 3 よりも小さい順位を取っているため、 (x,y)=(3,4) に対して問題文中の条件に違反します。
  • 1 と人 4 を代表にすることは問題ありません。
  • 2 と人 3 を代表にすると、 (x,y)=(3,1) に対して問題文中の条件に違反します。
  • 2 と人 4 を代表にすることは問題ありません。
  • 3 と人 4 を代表にすると、 (x,y)=(3,1) に対して問題文中の条件に違反します。

結局、求める答えは 3 通りです。


入力例 2

33 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

出力例 2

168558757

33 人から 16 人を選ぶ \binom{33}{16} = 1166803110 通りの全てにおいて、問題文中の条件を満たします。
よって、 1166803110998244353 で割った余りである 168558757 を出力することとなります。


入力例 3

15 7
4 9 7 5 6 13 2 11 3 1 12 14 15 10 8
4 14 9 12 7 15 1 2 8 11 3 5 13 6 10

出力例 3

23

Score : 500 points

Problem Statement

In the Kingdom of Takahashi, N citizens numbered 1 to N took an examination of competitive programming.
There were two tests, and Citizen i ranked P_i-th in the first test and Q_i-th in the second test.
There were no ties in either test. That is, each of the sequences P and Q is a permutation of (1, 2, ..., N).

Iroha, the president of the kingdom, is going to select K citizens for the national team at the coming world championship of competitive programming.
The members of the national team must be selected so that the following is satisfied.

  • There should not be a pair of citizens (x, y) where Citizen x is selected and Citizen y is not selected such that P_x > P_y and Q_x > Q_y.
    • In other words, if Citizen y got a rank smaller than that of Citizen x in both tests, it is not allowed to select Citizen x while not selecting Citizen y.

To begin with, Iroha wants to know the number of ways to select citizens for the national team that satisfy the condition above. Find it to help her.
Since this number can be enormous, print it modulo 998244353.

Constraints

  • All values in input are integers.
  • 1 \le N \le 300
  • 1 \le K \le N
  • Each of P and Q is a permutation of (1,2,...,N).

Input

Input is given from Standard Input in the following format:

N K
P_1 P_2 \dots P_N
Q_1 Q_2 \dots Q_N

Output

Print the answer as an integer.


Sample Input 1

4 2
2 4 3 1
2 1 4 3

Sample Output 1

3
  • It is fine to select Citizen 1 and Citizen 2 for the team.
  • If Citizen 1 and Citizen 3 are selected, Citizen 4 ranked higher than Citizen 3 did in both tests, so the pair (x,y)=(3,4) would violate the condition in the Problem Statement.
  • It is fine to select Citizen 1 and Citizen 4.
  • If Citizen 2 and Citizen 3 are selected, the pair (x,y)=(3,1) would violate the condition.
  • It is fine to select Citizen 2 and Citizen 4.
  • If Citizen 3 and Citizen 4 are selected, the pair (x,y)=(3,1) would violate the condition.

The final answer is 3.


Sample Input 2

33 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

Sample Output 2

168558757

All \binom{33}{16} = 1166803110 ways of selecting 16 from the 33 citizens satisfy the requirement.
Therefore, we should print 1166803110 modulo 998244353, that is, 168558757.


Sample Input 3

15 7
4 9 7 5 6 13 2 11 3 1 12 14 15 10 8
4 14 9 12 7 15 1 2 8 11 3 5 13 6 10

Sample Output 3

23