A - 11/22 String

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 150

問題文

この問題における 11/22 文字列の定義は C 問題および E 問題と同じです。

文字列 T が以下の条件を全て満たすとき、T11/22 文字列 と呼びます。

  • |T| は奇数である。ここで、|T|T の長さを表す。
  • 1 文字目から \frac{|T|+1}{2} - 1 文字目までが 1 である。
  • \frac{|T|+1}{2} 文字目が / である。
  • \frac{|T|+1}{2} + 1 文字目から |T| 文字目までが 2 である。

例えば 11/22, 111/222, / は 11/22 文字列ですが、1122, 1/22, 11/2222, 22/11, //2/2/211 はそうではありません。

1, 2, / からなる長さ N の文字列 S が与えられます。S が 11/22 文字列であるか判定してください。

制約

  • 1 \leq N \leq 100
  • S1, 2, / からなる長さ N の文字列

入力

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

N
S

出力

S が 11/22 文字列であれば Yes を、そうでなければ No を出力せよ。


入力例 1

5
11/22

出力例 1

Yes

11/22 は問題文の 11/22 文字列の条件を満たします。


入力例 2

1
/

出力例 2

Yes

/ は問題文の 11/22 文字列の条件を満たします。


入力例 3

4
1/22

出力例 3

No

1/22 は問題文の 11/22 文字列の条件を満たしません。


入力例 4

5
22/11

出力例 4

No

Score : 150 points

Problem Statement

The definition of an 11/22 string in this problem is the same as in Problems C and E.

A string T is called an 11/22 string when it satisfies all of the following conditions:

  • |T| is odd. Here, |T| denotes the length of T.
  • The 1-st through (\frac{|T|+1}{2} - 1)-th characters are all 1.
  • The (\frac{|T|+1}{2})-th character is /.
  • The (\frac{|T|+1}{2} + 1)-th through |T|-th characters are all 2.

For example, 11/22, 111/222, and / are 11/22 strings, but 1122, 1/22, 11/2222, 22/11, and //2/2/211 are not.

Given a string S of length N consisting of 1, 2, and /, determine whether S is an 11/22 string.

Constraints

  • 1 \leq N \leq 100
  • S is a string of length N consisting of 1, 2, and /.

Input

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

N
S

Output

If S is an 11/22 string, print Yes; otherwise, print No.


Sample Input 1

5
11/22

Sample Output 1

Yes

11/22 satisfies the conditions for an 11/22 string in the problem statement.


Sample Input 2

1
/

Sample Output 2

Yes

/ satisfies the conditions for an 11/22 string.


Sample Input 3

4
1/22

Sample Output 3

No

1/22 does not satisfy the conditions for an 11/22 string.


Sample Input 4

5
22/11

Sample Output 4

No
B - New Generation ABC

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

AtCoder Beginner Contest は、今回で 214 回目の開催となりました。

今までの AtCoder Beginner Contest において、出題される問題数は次のように変化しました。

  • 1 回目から 125 回目までは 4
  • 126 回目から 211 回目までは 6
  • 212 回目から 214 回目までは 8

N 回目の AtCoder Beginner Contest において出題された問題数を求めてください。

制約

  • 1 \leq N \leq 214
  • 入力は全て整数である。

入力

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

N

出力

答えを出力せよ。


入力例 1

214

出力例 1

8

入力例 2

1

出力例 2

4

入力例 3

126

出力例 3

6

Score : 100 points

Problem Statement

This is the 214-th AtCoder Beginner Contest (ABC).

The ABCs so far have had the following number of problems.

  • The 1-st through 125-th ABCs had 4 problems each.
  • The 126-th through 211-th ABCs had 6 problems each.
  • The 212-th through 214-th ABCs have 8 problems each.

Find the number of problems in the N-th ABC.

Constraints

  • 1 \leq N \leq 214
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

214

Sample Output 1

8

Sample Input 2

1

Sample Output 2

4

Sample Input 3

126

Sample Output 3

6
C - Ranking with Ties

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

1 から N までの番号が付けられた N 人の人がとあるコンテストに参加し、人 i\ (1\leq i\leq N)得点P_i でした。

このコンテストでは、以下の手順によって N 人それぞれの 順位 が定まります。

  1. 変数 r を用意し、r=1 と初期化する。最初、N 人の順位はすべて未確定である。
  2. N 人全員の順位が確定するまで以下の操作を繰り返す。
    • 順位が未確定である人の中での得点の最大値を x とし、得点が x である人の数を k とおく。得点が x である k 人すべての順位を r 位と確定させたのち、rk を足す。

N 人それぞれの順位を出力してください。

制約

  • 1\leq N \leq 100
  • 1\leq P_i\leq 100
  • 入力は全て整数

入力

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

N
P_1 P_2 \dots P_N

出力

N 行出力せよ。 i\ (1\leq i \leq N) 行目には、人 i の順位を整数として出力せよ。


入力例 1

4
3 12 9 9

出力例 1

4
1
2
2

以下のようにして N\ (=4) 人それぞれの順位が定まります。

  1. 変数 r を用意し、r=1 と初期化する。最初、4 人の順位はすべて未確定である。
  2. 現時点で順位が未確定なのは人 1,2,3,4 であり、その中での得点の最大値は P_2\ (=12) である。よって、人 2 の順位を r\ (=1) 位と確定させたのち、r1 を足して r=2 とする。
  3. 現時点で順位が未確定なのは人 1,3,4 であり、その中での得点の最大値は P_3=P_4\ (=9) である。よって、人 3,4 の順位を r\ (=2) 位と確定させたのち、r2 を足して r=4 とする。
  4. 現時点で順位が未確定なのは人 1 であり、その中での得点の最大値は P_1\ (=3) である。よって、人 1 の順位を r\ (=4) 位と確定させたのち、r1 を足して r=5 とする。
  5. 4 人全員の順位が確定したため、手順を終了する。

入力例 2

3
3 9 6

出力例 2

3
1
2

入力例 3

4
100 100 100 100

出力例 3

1
1
1
1

入力例 4

8
87 87 87 88 41 38 41 38

出力例 4

2
2
2
1
5
7
5
7

Score : 200 points

Problem Statement

N people labeled from 1 to N participated in a certain contest. The score of person i (1 \leq i \leq N) was P_i.

In this contest, the rank of each of the N people is determined by the following procedure:

  1. Prepare a variable r, and initialize r = 1. Initially, the ranks of the N people are all undetermined.
  2. Repeat the following operation until the ranks of all N people are determined:
    • Let x be the maximum score among the people whose ranks are currently undetermined, and let k be the number of people whose score is x. Determine the rank of those k people with score x to be r, and then add k to r.

Print the rank of each of the N people.

Constraints

  • 1\leq N \leq 100
  • 1\leq P_i \leq 100
  • All input values are integers.

Input

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

N
P_1 P_2 \dots P_N

Output

Print N lines. The i-th line (1 \leq i \leq N) should contain the rank of person i as an integer.


Sample Input 1

4
3 12 9 9

Sample Output 1

4
1
2
2

The ranks of the N\ (=4) people are determined as follows:

  1. Prepare a variable r and initialize r=1. At first, the ranks of all 4 people are undetermined.
  2. Currently, persons 1, 2, 3, 4 have undetermined ranks. The maximum score among them is P_2\ (=12). Therefore, determine the rank of person 2 to be r\ (=1), and then add 1 to r, making r=2.
  3. Currently, persons 1, 3, 4 have undetermined ranks. The maximum score among them is P_3=P_4\ (=9). Therefore, determine the ranks of persons 3 and 4 to be r\ (=2), and then add 2 to r, making r=4.
  4. Currently, person 1 has an undetermined rank. The maximum score among them is P_1\ (=3). Therefore, determine the rank of person 1 to be r\ (=4), and then add 1 to r, making r=5.
  5. The ranks of all 4 people are now determined, so the process ends.

Sample Input 2

3
3 9 6

Sample Output 2

3
1
2

Sample Input 3

4
100 100 100 100

Sample Output 3

1
1
1
1

Sample Input 4

8
87 87 87 88 41 38 41 38

Sample Output 4

2
2
2
1
5
7
5
7
D - Broken Rounding

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

非負整数 X に対し、 i=0,1,\dots,K-1 の順に次の操作を行ったとき、操作を全て終えた時点での X を求めてください。

  • X10^i の位以下を四捨五入する。
    • 厳密には、 X を「 |Y-X| が最小となる 10^{i+1} の倍数のうち最大のもの」である Y に置き換える。
    • 具体例を挙げる。
      • 27310^1 の位以下を四捨五入すれば 300 となる。
      • 99910^2 の位以下を四捨五入すれば 1000 となる。
      • 10010^9 の位以下を四捨五入すれば 0 となる。
      • 101510^0 の位以下を四捨五入すれば 1020 となる。

制約

  • X,K は整数
  • 0 \le X < 10^{15}
  • 1 \le K \le 15

入力

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

X K

出力

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


入力例 1

2048 2

出力例 1

2100

操作の過程で、 X2048 \rightarrow 2050 \rightarrow 2100 と変化します。


入力例 2

1 15

出力例 2

0

入力例 3

999 3

出力例 3

1000

入力例 4

314159265358979 12

出力例 4

314000000000000

X32bit 整数型に収まらない可能性があります。

Score : 200 points

Problem Statement

Given a non-negative integer X, perform the following operation for i=1,2,\dots,K in this order and find the resulting X.

  • Round X off to the nearest 10^i.
    • Formally, replace X with Y that is "the largest multiple of 10^i that minimizes |Y-X|."
    • Here are some examples:
      • Rounding 273 off to the nearest 10^2 yields 300.
      • Rounding 999 off to the nearest 10^3 yields 1000.
      • Rounding 100 off to the nearest 10^{10} yields 0.
      • Rounding 1015 off to the nearest 10^1 yields 1020.

Constraints

  • X and K are integers.
  • 0 \le X < 10^{15}
  • 1 \le K \le 15

Input

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

X K

Output

Print the answer as an integer.


Sample Input 1

2048 2

Sample Output 1

2100

X changes as 2048 \rightarrow 2050 \rightarrow 2100 by the operations.


Sample Input 2

1 15

Sample Output 2

0

Sample Input 3

999 3

Sample Output 3

1000

Sample Input 4

314159265358979 12

Sample Output 4

314000000000000

X may not fit into a 32-bit integer type.

E - Humidifier 3

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350

問題文

AtCoder社のオフィスは HW 列のマス目で表されます。上から i 行目、左から j 列目のマスを (i, j) と表します。

各マスの状態は文字 S_{i,j} で表され、 S_{i,j}# のときそのマスは壁、. のときそのマスは床、H のときそのマスは加湿器が置かれた床です。

あるマスは、ある加湿器から壁を通らず上下左右に D 回以下の移動で辿り着ける場合加湿されます。ここで、加湿器が置かれた床のマスは必ず加湿されていることに注意してください。

加湿されている床のマスの個数を求めてください。

制約

  • 1 \leq H \leq 1000
  • 1 \leq W \leq 1000
  • 0 \leq D \leq H\times W
  • S_{i,j}# または . または H である (1 \leq i \leq H, 1 \leq j \leq W)
  • 入力される数値は全て整数

入力

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

H W D
S_{1,1}S_{1,2}\cdotsS_{1,W}
S_{2,1}S_{2,2}\cdotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\cdotsS_{H,W}

出力

答えを出力せよ。


入力例 1

3 4 1
H...
#..H
.#.#

出力例 1

5

マス (1,1),(1,2),(1,4),(2,3),(2,4)5 つのマスが加湿されています。


入力例 2

5 6 2
##...H
H.....
..H.#.
.HH...
.###..

出力例 2

21

入力例 3

1 6 3
...#..

出力例 3

0

加湿されるマスが存在しない場合もあります。

Score : 350 points

Problem Statement

The AtCoder company office is represented as a grid of H rows and W columns. Let (i, j) denote the cell at the i-th row from the top and j-th column from the left.

The state of each cell is represented by a character S_{i,j}. If S_{i,j} is #, that cell has a wall; if S_{i,j} is ., that cell is a floor; if S_{i,j} is H, that cell has a humidifier placed on a floor cell.

A certain cell is considered humidified if it can be reached from at least one humidifier cell by at most D moves up, down, left, or right without passing through a wall. Note that any cell with a humidifier is always humidified.

Find the number of humidified floor cells.

Constraints

  • 1 \leq H \leq 1000
  • 1 \leq W \leq 1000
  • 0 \leq D \leq H\times W
  • S_{i,j} is #, ., or H. (1 \leq i \leq H, 1 \leq j \leq W)
  • All input numbers are integers.

Input

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

H W D
S_{1,1}S_{1,2}\cdotsS_{1,W}
S_{2,1}S_{2,2}\cdotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\cdotsS_{H,W}

Output

Print the answer.


Sample Input 1

3 4 1
H...
#..H
.#.#

Sample Output 1

5

Five cells (1,1), (1,2), (1,4), (2,3), (2,4) are humidified.


Sample Input 2

5 6 2
##...H
H.....
..H.#.
.HH...
.###..

Sample Output 2

21

Sample Input 3

1 6 3
...#..

Sample Output 3

0

It is possible that no cells are humidified.