E - Even Digits

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

非負整数 n が次の条件を満たすとき、n良い整数 と呼びます。

  • n10 進法で表したときに、偶数の数字 (0, 2, 4, 6, 8) のみが登場する。

例えば 068 および 2024 は良い整数です。

整数 N が与えられます。良い整数のうち小さい方から N 番目の整数を求めてください。

制約

  • 1 \leq N \leq 10^{12}
  • N は整数

入力

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

N

出力

小さい方から N 番目の良い整数を出力せよ。


入力例 1

8

出力例 1

24

良い整数を小さい方から順に並べると 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots となります。
小さい方から 8 番目の良い整数は 24 なので、これを出力します。


入力例 2

133

出力例 2

2024

入力例 3

31415926535

出力例 3

2006628868244228

Score: 300 points

Problem Statement

A non-negative integer n is called a good integer when it satisfies the following condition:

  • All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).

For example, 0, 68, and 2024 are good integers.

You are given an integer N. Find the N-th smallest good integer.

Constraints

  • 1 \leq N \leq 10^{12}
  • N is an integer.

Input

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

N

Output

Print the N-th smallest good integer.


Sample Input 1

8

Sample Output 1

24

The good integers in ascending order are 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots.
The eighth smallest is 24, which should be printed.


Sample Input 2

133

Sample Output 2

2024

Sample Input 3

31415926535

Sample Output 3

2006628868244228
F - World Tour Finals

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 250

問題文

N 人のプレイヤーが参加するプログラミングコンテスト World Tour Finals が行われており、競技時間の半分が過ぎました。 このコンテストでは M 問の問題が出題されており、問題 i の点数 A_i500 以上 2500 以下の 100 の倍数です。

i = 1, \ldots, N について、プレイヤー i がどの問題を既に解いたかを表す文字列 S_i が与えられます。 S_io, x からなる長さ M の文字列で、S_ij 文字目が o のときプレイヤー i は問題 j を既に解いており、x のときまだ解いていません。 ただし、どのプレイヤーもまだ全ての問題を解いてはいません。

プレイヤー i の総合得点は、解いた問題の点数の合計に、ボーナス点 i 点を加えた点数として計算されます。
さて、各 i = 1, \ldots, N について以下の質問に答えてください。

  • プレイヤー i がまだ解いていない問題を少なくとも何問解くことで、プレイヤー i の総合得点が他のプレイヤー全員の現在の総合得点を上回ることができますか?

なお、問題文中の条件と制約から、プレイヤー i が全ての問題を解くことで、他のプレイヤー全員の現在の総合得点を上回ることができることが証明できます。 このことから、答えは常に定義されることに注意してください。

制約

  • 2\leq N\leq 100
  • 1\leq M\leq 100
  • 500\leq A_i\leq 2500
  • A_i100 の倍数
  • S_io, x からなる長さ M の文字列
  • S_i には x が一個以上含まれる
  • 入力される数値は全て整数

入力

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

N M
A_1 A_2 \ldots A_M
S_1
S_2
\vdots
S_N

出力

N 行出力せよ。 i 行目にはプレイヤー i に関する質問の答えを出力せよ。


入力例 1

3 4
1000 500 700 2000
xxxo
ooxx
oxox

出力例 1

0
1
1

競技時間の半分の経過時の各プレイヤーの総合得点は、プレイヤー 12001 点、プレイヤー 21502 点、プレイヤー 31703 点です。

プレイヤー 11 問も解かずとも、他のプレイヤー全員の総合得点を上回っています。

プレイヤー 2 は、例えば問題 4 を解けば総合得点が 3502 点となり、他のプレイヤー全員の総合得点を上回ります。

プレイヤー 3 も、例えば問題 4 を解けば総合得点が 3703 点となり、他のプレイヤー全員の総合得点を上回ります。


入力例 2

5 5
1000 1500 2000 2000 2500
xxxxx
oxxxx
xxxxx
oxxxx
oxxxx

出力例 2

1
1
1
1
0

入力例 3

7 8
500 500 500 500 500 500 500 500
xxxxxxxx
oxxxxxxx
ooxxxxxx
oooxxxxx
ooooxxxx
oooooxxx
ooooooxx

出力例 3

7
6
5
4
3
2
0

Score : 250 points

Problem Statement

The programming contest World Tour Finals is underway, where N players are participating, and half of the competition time has passed. There are M problems in this contest, and the score A_i of problem i is a multiple of 100 between 500 and 2500, inclusive.

For each i = 1, \ldots, N, you are given a string S_i that indicates which problems player i has already solved. S_i is a string of length M consisting of o and x, where the j-th character of S_i is o if player i has already solved problem j, and x if they have not yet solved it. Here, none of the players have solved all the problems yet.

The total score of player i is calculated as the sum of the scores of the problems they have solved, plus a bonus score of i points.
For each i = 1, \ldots, N, answer the following question.

  • At least how many of the problems that player i has not yet solved must player i solve to exceed all other players' current total scores?

Note that under the conditions in this statement and the constraints, it can be proved that player i can exceed all other players' current total scores by solving all the problems, so the answer is always defined.

Constraints

  • 2\leq N\leq 100
  • 1\leq M\leq 100
  • 500\leq A_i\leq 2500
  • A_i is a multiple of 100.
  • S_i is a string of length M consisting of o and x.
  • S_i contains at least one x.
  • All numeric values in the input are integers.

Input

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

N M
A_1 A_2 \ldots A_M
S_1
S_2
\vdots
S_N

Output

Print N lines. The i-th line should contain the answer to the question for player i.


Sample Input 1

3 4
1000 500 700 2000
xxxo
ooxx
oxox

Sample Output 1

0
1
1

The players' total scores at the halfway point of the competition time are 2001 points for player 1, 1502 points for player 2, and 1703 points for player 3.

Player 1 is already ahead of all other players' total scores without solving any more problems.

Player 2 can, for example, solve problem 4 to have a total score of 3502 points, which would exceed all other players' total scores.

Player 3 can also, for example, solve problem 4 to have a total score of 3703 points, which would exceed all other players' total scores.


Sample Input 2

5 5
1000 1500 2000 2000 2500
xxxxx
oxxxx
xxxxx
oxxxx
oxxxx

Sample Output 2

1
1
1
1
0

Sample Input 3

7 8
500 500 500 500 500 500 500 500
xxxxxxxx
oxxxxxxx
ooxxxxxx
oooxxxxx
ooooxxxx
oooooxxx
ooooooxx

Sample Output 3

7
6
5
4
3
2
0
G - Count Interval

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

長さ N の数列 A=(A_1,A_2,\ldots,A_N) と、整数 K が与えられます。

A の連続部分列のうち、要素の和が K になるものはいくつありますか?
すなわち、以下の条件を全て満たす整数の組 (l,r) はいくつありますか?

  • 1\leq l\leq r\leq N
  • \displaystyle\sum_{i=l}^{r}A_i = K

制約

  • 1\leq N \leq 2\times 10^5
  • |A_i| \leq 10^9
  • |K| \leq 10^{15}
  • 入力に含まれる値は全て整数である

入力

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

N K
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

6 5
8 -3 5 7 0 -4

出力例 1

3

(l,r)=(1,2),(3,3),(2,6)3 組が条件を満たします。


入力例 2

2 -1000000000000000
1000000000 -1000000000

出力例 2

0

条件を満たす (l,r) の組が 1 つも存在しないこともあります。

Score : 400 points

Problem Statement

Given is a sequence of length N: A=(A_1,A_2,\ldots,A_N), and an integer K.

How many of the contiguous subsequences of A have the sum of K?
In other words, how many pairs of integers (l,r) satisfy all of the conditions below?

  • 1\leq l\leq r\leq N
  • \displaystyle\sum_{i=l}^{r}A_i = K

Constraints

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

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

6 5
8 -3 5 7 0 -4

Sample Output 1

3

(l,r)=(1,2),(3,3),(2,6) are the three pairs that satisfy the conditions.


Sample Input 2

2 -1000000000000000
1000000000 -1000000000

Sample Output 2

0

There may be no pair that satisfies the conditions.

H - Integer Sequence Fair

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

整数列を一堂に集めてその優劣を定める、整数列品評会が行われます。 品評会では、1 以上 K 以下の整数からなる長さ N の整数列すべてが審査対象となり、 審査対象の数列それぞれに対して 1 以上 M 以下の整数の点数をつけます。

「審査対象の数列それぞれに対して 1 以上 M 以下の整数の点数をつける方法」が何通りあるかを 998244353 で割ったあまりを出力してください。

ただし、2 つの方法が異なるとは「審査対象となるある数列 A = (A_1, A_2, \ldots, A_N) が存在して、 A に対してつける点数が 2 つの方法で異なる」ことを言います。

制約

  • 1 \leq N, K, M \leq 10^{18}
  • N, K, M は整数

入力

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

N K M

出力

「審査対象の数列それぞれに対して 1 以上 M 以下の整数の点数をつける方法」が何通りあるかを 998244353 で割ったあまりを出力せよ。


入力例 1

2 2 2

出力例 1

16

審査対象となる数列は、(1, 1), (1, 2), (2, 1), (2, 2)4 つです。「審査対象の数列それぞれに対して 1 以上 2 以下の整数の点数をつける方法」は、以下の 16 通りあります。

  • (1, 1)1 点、(1, 2)1 点、(2, 1)1 点、(2, 2)1 点をつける方法
  • (1, 1)1 点、(1, 2)1 点、(2, 1)1 点、(2, 2)2 点をつける方法
  • (1, 1)1 点、(1, 2)1 点、(2, 1)2 点、(2, 2)1 点をつける方法
  • (1, 1)1 点、(1, 2)1 点、(2, 1)2 点、(2, 2)2 点をつける方法
  • \cdots
  • (1, 1)2 点、(1, 2)2 点、(2, 1)2 点、(2, 2)2 点をつける方法

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


入力例 2

3 14 15926535

出力例 2

109718301

998244353 で割ったあまりを出力することに注意してください。

Score : 500 points

Problem Statement

Integer Sequence Exhibition is taking place, where integer sequences are gathered in one place and evaluated. Here, every integer sequence of length N consisting of integers between 1 and K (inclusive) is evaluated and given an integer score between 1 and M (inclusive).

Print the number, modulo 998244353, of ways to give each of the evaluated sequences a score between 1 and M.

Here, two ways are said to be different when there is an evaluated sequence A = (A_1, A_2, \ldots, A_N) that is given different scores by the two ways.

Constraints

  • 1 \leq N, K, M \leq 10^{18}
  • N, K, and M are integers.

Input

Input is given from Standard Input in the following format:

N K M

Output

Print the number, modulo 998244353, of ways to give each of the evaluated sequences a score between 1 and M.


Sample Input 1

2 2 2

Sample Output 1

16

Four sequences are evaluated: (1, 1), (1, 2), (2, 1), and (2, 2). There are 16 ways to give each of these sequences a score between 1 and 2, as follows.

  • Give 1 to (1, 1), 1 to (1, 2), 1 to (2, 1), and 1 to (2, 2)
  • Give 1 to (1, 1), 1 to (1, 2), 1 to (2, 1), and 2 to (2, 2)
  • Give 1 to (1, 1), 1 to (1, 2), 2 to (2, 1), and 1 to (2, 2)
  • Give 1 to (1, 1), 1 to (1, 2), 2 to (2, 1), and 2 to (2, 2)
  • \cdots
  • Give 2 to (1, 1), 2 to (1, 2), 2 to (2, 1), and 2 to (2, 2)

Thus, we print 16.


Sample Input 2

3 14 15926535

Sample Output 2

109718301

Be sure to print the count modulo 998244353.

I - Permutation Distance

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

(1,2,\ldots,N) の順列 P=(P _ 1,P _ 2,\ldots,P _ N) が与えられます。

すべての i\ (1\leq i\leq N) に対して、以下の値を求めてください。

  • D _ i=\displaystyle\min_{j\neq i}\left\lparen\left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert\right\rparen
順列とは (1,2,\ldots,N) の順列とは、(1,2,\ldots,N) を並べ替えて得られる数列のことをいいます。 つまり、長さ N の数列 Ai\ (1\leq i\leq N) がその中にちょうど 1 回だけ現れるとき、かつそのときに限り(1,2,\ldots,N) の順列です。

制約

  • 2 \leq N \leq 2\times10^5
  • 1 \leq P _ i \leq N\ (1\leq i\leq N)
  • i\neq j\implies P _ i\neq P _ j
  • 入力はすべて整数

入力

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

N
P _ 1 P _ 2 \ldots P _ N

出力

D _ i\ (1\leq i\leq N)i の昇順に空白区切りで出力せよ。


入力例 1

4
3 2 4 1

出力例 1

2 2 3 3 

たとえば、i=1 について

  • j=2 のとき、\left\lvert P _ i-P _ j\right\rvert=1,\left\lvert i-j\right\rvert=1 です。
  • j=3 のとき、\left\lvert P _ i-P _ j\right\rvert=1,\left\lvert i-j\right\rvert=2 です。
  • j=4 のとき、\left\lvert P _ i-P _ j\right\rvert=2,\left\lvert i-j\right\rvert=3 です。

よって、j=2 のとき \left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert=2 で最小となるので、D _ 1=2 です。


入力例 2

7
1 2 3 4 5 6 7

出力例 2

2 2 2 2 2 2 2 

入力例 3

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

出力例 3

3 3 3 5 3 4 3 3 4 2 2 4 4 4 4 7 

Score : 500 points

Problem Statement

You are given a permutation P=(P _ 1,P _ 2,\ldots,P _ N) of (1,2,\ldots,N).

Find the following value for all i\ (1\leq i\leq N):

  • D _ i=\displaystyle\min_{j\neq i}\left\lparen\left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert\right\rparen.
What is a permutation? A permutation of (1,2,\ldots,N) is a sequence that is obtained by rearranging (1,2,\ldots,N). In other words, a sequence A of length N is a permutation of (1,2,\ldots,N) if and only if each i\ (1\leq i\leq N) occurs in A exactly once.

Constraints

  • 2 \leq N \leq 2\times10^5
  • 1 \leq P _ i \leq N\ (1\leq i\leq N)
  • i\neq j\implies P _ i\neq P _ j
  • All values in the input are integers.

Input

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

N
P _ 1 P _ 2 \ldots P _ N

Output

Print D _ i\ (1\leq i\leq N) in ascending order of i, separated by spaces.


Sample Input 1

4
3 2 4 1

Sample Output 1

2 2 3 3 

For example, for i=1,

  • if j=2, we have \left\lvert P _ i-P _ j\right\rvert=1 and \left\lvert i-j\right\rvert=1;
  • if j=3, we have \left\lvert P _ i-P _ j\right\rvert=1 and \left\lvert i-j\right\rvert=2;
  • if j=4, we have \left\lvert P _ i-P _ j\right\rvert=2 and \left\lvert i-j\right\rvert=3.

Thus, the value is minimum when j=2, where \left\lvert P _ i-P _ j\right\rvert+\left\lvert i-j\right\rvert=2, so D _ 1=2.


Sample Input 2

7
1 2 3 4 5 6 7

Sample Output 2

2 2 2 2 2 2 2 

Sample Input 3

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

Sample Output 3

3 3 3 5 3 4 3 3 4 2 2 4 4 4 4 7