A - Slot

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

あなたはスロットマシーンで遊んでいます。

スロットを回した結果は 3 文字の英大文字 C_1,C_2,C_3 で表され、これらが全て同じ文字であるとき当たりです。

当たりかどうか判定してください。

制約

  • C_i は英大文字

入力

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

C_1 C_2 C_3

出力

当たりなら Won を、当たりでないなら Lost を出力せよ。


入力例 1

SSS

出力例 1

Won

全て同じ文字なので当たりです。


入力例 2

WVW

出力例 2

Lost

当たりではありません。

Score : 100 points

Problem Statement

You are playing the slots.

The result of a spin is represented by three uppercase English letters C_1, C_2, and C_3. It is considered a win when all of them are the same letter.

Determine whether it is a win.

Constraints

  • C_i is an uppercase English letter.

Input

Input is given from Standard Input in the following format:

C_1 C_2 C_3

Output

If the result is a win, print Won; otherwise, print Lost.


Sample Input 1

SSS

Sample Output 1

Won

All of them are the same letter, so it is a win.


Sample Input 2

WVW

Sample Output 2

Lost

It is not a win.

B - Alcoholic

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

高橋君はお酒を N 杯飲みました。

i 番目に飲んだお酒は、量が V_i ml、アルコール度数が P_i % です。

高橋君はアルコールの摂取量が X ml を超えると酔っ払います。

高橋君が酔っ払ったのは何杯目のお酒を飲んでいるときですか。ただし、N 杯全てのお酒を飲んだあとでも酔っ払っていない場合は、かわりに -1 を出力してください。

制約

  • 入力は全て整数
  • 1 \leq N \leq 10^3
  • 0 \leq X \leq 10^6
  • 1 \leq V_i \leq 10^3
  • 0 \leq P_i \leq 100

入力

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

N X
V_1 P_1
\vdots
V_N P_N

出力

高橋君が酔っ払ったのが何杯目のお酒を飲んでいるときか出力せよ。ただし、N 杯全てのお酒を飲んだあとでも酔っ払っていない場合は、かわりに -1 を出力せよ。


入力例 1

2 15
200 5
350 3

出力例 1

2

1 杯目のお酒には、200\times \dfrac{5}{100}=10 ml のアルコールが含まれています。

2 杯目のお酒には、350\times \dfrac{3}{100}=10.5 ml のアルコールが含まれています。

2 杯目のお酒を飲んでいるときに、初めてアルコールの摂取量が 15 ml を超えます。


入力例 2

2 10
200 5
350 3

出力例 2

2

アルコールの摂取量がちょうど X ml のとき、高橋君はまだ酔っ払っていません。


入力例 3

3 1000000
1000 100
1000 100
1000 100

出力例 3

-1

高橋くんはお酒にとても強いようです。

Score : 200 points

Problem Statement

Takahashi had N glasses of liquor.

The amount and alcohol percentage of the i-th liquor were V_i milliliters and P_i percent by volume, respectively.

Takahashi gets drunk when his alcohol intake exceeds X milliliters.

Which of the N liquors was he drinking when he gets drunk? If he was not drunk even after drinking all the liquors, print -1 instead.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^3
  • 0 \leq X \leq 10^6
  • 1 \leq V_i \leq 10^3
  • 0 \leq P_i \leq 100

Input

Input is given from Standard Input in the following format:

N X
V_1 P_1
\vdots
V_N P_N

Output

If Takahashi got drunk when drinking the i-th liquor, print i. If he was not drunk even after drinking all the liquors, print -1 instead.


Sample Input 1

2 15
200 5
350 3

Sample Output 1

2

The 1-st liquor contains 200\times \dfrac{5}{100}=10 milliliters of alcohol.

The 2-nd liquor contains 350\times \dfrac{3}{100}=10.5 milliliters of alcohol.

His alcohol intake exceeds 15 milliliters for the first time when drinking the 2-nd liquor.


Sample Input 2

2 10
200 5
350 3

Sample Output 2

2

When his alcohol intake is exactly X milliliters, he is still not drunk.


Sample Input 3

3 1000000
1000 100
1000 100
1000 100

Sample Output 3

-1

He seems to be immune to alcohol.

C - Mandarin Orange

Time Limit: 1.5 sec / Memory Limit: 1024 MB

配点 : 300

問題文

高橋君の前に N 枚の皿が一列に並べられており、左から i 番目の皿には A_i 個のみかんが置かれています。

高橋君は次の 3 つの条件を全て満たすような整数の組 (l,r,x)1 つ選びます。

  • 1\leq l \leq r \leq N
  • 1 \le x
  • l 以上 r 以下の全ての整数 i について、x \le A_i

その後、高橋君は l 番目から r 番目まで (両端を含む) の全ての皿からみかんを x 個ずつ取って食べます。

整数の組 (l,r,x) を適切に選んだとき、高橋君は最大で何個のみかんを食べることができますか。

制約

  • 入力は全て整数
  • 1 \leq N \leq 10^4
  • 1 \leq A_i \leq 10^5

入力

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

N
A_1 \ldots A_N

出力

高橋君が食べることのできるみかんの個数の最大値を出力せよ。


入力例 1

6
2 4 4 9 4 9

出力例 1

20

(l,r,x)=(2,6,4) としたとき、20 個のみかんを食べることができます。


入力例 2

6
200 4 4 9 4 9

出力例 2

200

(l,r,x)=(1,1,200) としたとき、200 個のみかんを食べることができます。

Score : 300 points

Problem Statement

There are N dishes arranged in a row in front of Takahashi. The i-th dish from the left has A_i oranges on it.

Takahashi will choose a triple of integers (l, r, x) satisfying all of the following conditions:

  • 1\leq l \leq r \leq N;
  • 1 \le x;
  • for every integer i between l and r (inclusive), x \le A_i.

He will then pick up and eat x oranges from each of the l-th through r-th dishes from the left.

At most how many oranges can he eat by choosing the triple (l, r, x) to maximize this number?

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^4
  • 1 \leq A_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

Print the maximum number of oranges Takahashi can eat.


Sample Input 1

6
2 4 4 9 4 9

Sample Output 1

20

By choosing (l,r,x)=(2,6,4), he can eat 20 oranges.


Sample Input 2

6
200 4 4 9 4 9

Sample Output 2

200

By choosing (l,r,x)=(1,1,200), he can eat 200 oranges.

D - Logical Expression

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

N 個の文字列 S_1,\ldots,S_N が与えられます。各文字列は AND または OR です。

値が \text{True} または \text{False} であるような N+1 個の変数の組 (x_0,\ldots,x_N) であって、 以下のような計算を行った際に、y_N\text{True} となるようなものの個数を求めてください。

  • y_0=x_0
  • i\geq 1 のとき、S_iAND なら y_i=y_{i-1} \land x_iS_iOR なら y_i=y_{i-1} \lor x_i

a \land bab の論理積を表し、a \lor bab の論理和を表します。

制約

  • 1 \leq N \leq 60
  • S_iAND または OR

入力

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

N
S_1
\vdots
S_N

出力

答えを出力せよ。


入力例 1

2
AND
OR

出力例 1

5

例えば (x_0,x_1,x_2)=(\text{True},\text{False},\text{True}) のとき

  • y_0=x_0=\text{True}
  • y_1=y_0 \land x_1 = \text{True} \land \text{False}=\text{False}
  • y_2=y_1 \lor x_2 = \text{False} \lor \text{True}=\text{True}

となり、y_2\text{True} になります。

y_2\text{True} となるような (x_0,x_1,x_2) の組み合わせは、

  • (\text{True},\text{True},\text{True})
  • (\text{True},\text{True},\text{False})
  • (\text{True},\text{False},\text{True})
  • (\text{False},\text{True},\text{True})
  • (\text{False},\text{False},\text{True})

5 通りで全てです。


入力例 2

5
OR
OR
OR
OR
OR

出力例 2

63

全てが \text{False} のときを除く 2^6-1 通りで y_5\text{True} になります。

Score : 400 points

Problem Statement

Given are N strings S_1,\ldots,S_N, each of which is AND or OR.

Find the number of tuples of N+1 variables (x_0,\ldots,x_N), where each element is \text{True} or \text{False}, such that the following computation results in y_N being \text{True}:

  • y_0=x_0;
  • for i\geq 1, y_i=y_{i-1} \land x_i if S_i is AND, and y_i=y_{i-1} \lor x_i if S_i is OR.

Here, a \land b and a \lor b are logical operators.

Constraints

  • 1 \leq N \leq 60
  • S_i is AND or OR.

Input

Input is given from Standard Input in the following format:

N
S_1
\vdots
S_N

Output

Print the answer.


Sample Input 1

2
AND
OR

Sample Output 1

5

For example, if (x_0,x_1,x_2)=(\text{True},\text{False},\text{True}), we have y_2 = \text{True}, as follows:

  • y_0=x_0=\text{True}
  • y_1=y_0 \land x_1 = \text{True} \land \text{False}=\text{False}
  • y_2=y_1 \lor x_2 = \text{False} \lor \text{True}=\text{True}

All of the five tuples (x_0,x_1,x_2) resulting in y_2 = \text{True} are shown below:

  • (\text{True},\text{True},\text{True})
  • (\text{True},\text{True},\text{False})
  • (\text{True},\text{False},\text{True})
  • (\text{False},\text{True},\text{True})
  • (\text{False},\text{False},\text{True})

Sample Input 2

5
OR
OR
OR
OR
OR

Sample Output 2

63

All tuples except the one filled entirely with \text{False} result in y_5 = \text{True}.

E - Rotate and Flip

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

2 次元平面に N 個の駒が置かれています。駒には 1 から N までの番号が付いており、駒 i が置かれている座標は (X_i,Y_i) です。複数の駒が同じ座標に置かれている可能性もあります。

M 個の操作 \mathrm{op}_1, \ldots, \mathrm{op}_M を順に行います。操作は 4 種類あり、入力形式と操作の内容は以下の通りです。

  • 1:全ての駒を、原点を中心に時計回りに 90 度回転させた位置に移動する
  • 2:全ての駒を、原点を中心に反時計回りに 90 度回転させた位置に移動する
  • 3 p:全ての駒を、直線 x=p について対称な位置に移動する
  • 4 p:全ての駒を、直線 y=p について対称な位置に移動する

クエリが Q 個与えられます。 i 番目のクエリでは 2 つの整数 A_i,B_i が与えられるので、A_i 個目の操作を行った直後に駒 B_i がある座標を出力してください。ここで、1 個目の操作の直前を「0 個目の操作の直後」とみなします。

制約

  • 入力は全て整数
  • 1 \leq N \leq 2\times 10^5
  • 1 \leq M \leq 2\times 10^5
  • 1 \leq Q \leq 2\times 10^5
  • -10^9 \leq X_i,Y_i \leq 10^9
  • \mathrm{op}_i4 つの操作の種類のいずれかの入力形式に従う
  • 3 p 及び 4 p の操作において -10^9 \leq p \leq 10^9
  • 0 \leq A_i \leq M
  • 1 \leq B_i \leq N

入力

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

N
X_1 Y_1
\vdots
X_N Y_N
M
\mathrm{op}_1
\vdots
\mathrm{op}_M
Q
A_1 B_1
\vdots
A_Q B_Q

出力

各クエリに対する答えを、1 行に 1 つずつ、x 座標、y 座標の順に空白区切りで出力せよ。


入力例 1

1
1 2
4
1
3 3
2
4 2
5
0 1
1 1
2 1
3 1
4 1

出力例 1

1 2
2 -1
4 -1
1 4
1 0

最初、唯一の駒である駒 1(1,2) に置かれています。各操作により駒 1 の位置は (1,2)\to(2,-1)\to(4,-1)\to(1,4)\to(1,0) と変化します。


入力例 2

2
1000000000 0
0 1000000000
4
3 -1000000000
4 -1000000000
3 1000000000
4 1000000000
2
4 1
4 2

出力例 2

5000000000 4000000000
4000000000 5000000000

Score : 500 points

Problem Statement

There are N pieces on a two-dimensional plane. The coordinates of Piece i are (X_i,Y_i). There may be multiple pieces at the same coordinates.

We will do M operations \mathrm{op}_1, \ldots, \mathrm{op}_M, one by one. There are four kinds of operations, described below along with their formats in input.

  • 1:Rotate every piece 90 degrees clockwise about the origin;
  • 2:Rotate every piece 90 degrees counterclockwise about the origin;
  • 3 p:Move each piece to the point symmetric to it about the line x=p;
  • 4 p:Move each piece to the point symmetric to it about the line y=p.

You are given Q queries. In the i-th query, given two integers A_i and B_i, print the coordinates of Piece B_i just after the A_i-th operation. Here, the moment just before the 1-st operation is considered to be the moment just after "the 0-th operation".

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 2\times 10^5
  • 1 \leq M \leq 2\times 10^5
  • 1 \leq Q \leq 2\times 10^5
  • -10^9 \leq X_i,Y_i \leq 10^9
  • \mathrm{op}_i is in the format of one of the four kinds of operations.
  • In an operation with the form 3 p or 4 p, -10^9 \leq p \leq 10^9.
  • 0 \leq A_i \leq M
  • 1 \leq B_i \leq N

Input

Input is given from Standard Input in the following format:

N
X_1 Y_1
\vdots
X_N Y_N
M
\mathrm{op}_1
\vdots
\mathrm{op}_M
Q
A_1 B_1
\vdots
A_Q B_Q

Output

Print the response to each query in its own line: the x- and y-coordinates, in this order, with space in between.


Sample Input 1

1
1 2
4
1
3 3
2
4 2
5
0 1
1 1
2 1
3 1
4 1

Sample Output 1

1 2
2 -1
4 -1
1 4
1 0

Initially, the only piece - Piece 1 - is at (1, 2). Each operation moves the piece as follows: (1,2)\to(2,-1)\to(4,-1)\to(1,4)\to(1,0).


Sample Input 2

2
1000000000 0
0 1000000000
4
3 -1000000000
4 -1000000000
3 1000000000
4 1000000000
2
4 1
4 2

Sample Output 2

5000000000 4000000000
4000000000 5000000000
F - Sugoroku2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

高橋君は双六で遊んでいます。

この双六には 0 から N の番号がついた N+1 個のマスがあります。 高橋君はマス 0 からスタートし、マス N を目指します。

この双六では、1 から M までの M 種類の目が等確率で出るルーレットを使います。 各手番で、高橋君はルーレットを回して出た目の数だけ進みます。この結果マス N に到達するか、マス N を越えて進むことになる場合、ゴールとなります。

また、いくつかのマスは「振り出しに戻る」であり、それらのマスに止まると、マス 0 まで戻されます。 そのようなマスは K 個あり、マス A_1,\ldots,A_K です。

高橋君がゴールするまでにルーレットを回す回数の期待値を答えてください。 ゴールすることが不可能な場合は、かわりに -1 を出力してください。

制約

  • 入力はすべて整数
  • 1 \leq N \leq 10^5
  • 1 \leq M \leq 10^5
  • 0 \leq K \leq 10
  • 0 < A_1 < \ldots < A_K < N

入力

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

N M K
A_1 \ldots A_K

出力

高橋君がゴールするまでにルーレットを回す回数の期待値を出力せよ。 なお、想定解答との絶対誤差または相対誤差が 10^{-3} 以下であれば正解として扱われる。 ただし、ゴールすることが不可能な場合は、かわりに -1 と出力せよ。


入力例 1

2 2 0

出力例 1

1.5000

1 回目のルーレットで 1 を出した場合は 2 回、2 を出した場合は 1 回でゴールできるので、ルーレットを回す回数の期待値は 1.5 です。


入力例 2

2 2 1
1

出力例 2

2.0000

ルーレットで 1 を出すとマス 1 に移動しますが、このマスは「振り出しに戻る」なのでマス 0 に戻されます。
従って、2 が出るまでルーレットを回し続け、2 が初めて出た時点でゴールすることになります。
i 回目に初めて 2 が出る確率は \frac{1}{2^i} ですから、ルーレットを回す回数の期待値は \sum_{i = 1}^{\infty} (i \times \frac{1}{2^i}) = 2 となります。


入力例 3

100 6 10
11 12 13 14 15 16 17 18 19 20

出力例 3

-1

入力例 4

100000 2 2
2997 92458

出力例 4

201932.2222

Score : 600 points

Problem Statement

Takahashi is playing sugoroku.

The board has N+1 squares numbered 0 to N. Takahashi starts at Square 0 and head to Square N.

In this sugoroku, we use a wheel showing numbers from 1 through M with equal probability. In each turn, Takahashi spins the wheel and advances by the number shown by the wheel. When it makes him reach Square N or go past it, he wins.

Some of the squares send him to Square 0 when he stops on them. There are K such squares: Square A_1, \ldots, A_K.

Find the expected value of the number of times Takahashi spins the wheel before he wins. If it is impossible to win, print -1 instead.

Constraints

  • All values in input are integers.
  • 1 \leq N \leq 10^5
  • 1 \leq M \leq 10^5
  • 0 \leq K \leq 10
  • 0 < A_1 < \ldots < A_K < N

Input

Input is given from Standard Input in the following format:

N M K
A_1 \ldots A_K

Output

Print the expected value of the number of times Takahashi spins the wheel before he wins. Your output is considered as correct when its absolute or relative error from our answer is at most 10^{-3}. If it is impossible to win, print -1 instead.


Sample Input 1

2 2 0

Sample Output 1

1.5000

If the wheel shows 1 in the first spin, he will need two spins to win; if the wheel shows 2 in the first spin, he will need one spin to win. Thus, the expected number of spins is 1.5.


Sample Input 2

2 2 1
1

Sample Output 2

2.0000

If the wheel shows 1, he advances to Square 1, but it sends him back to Square 0.
Thus, he keeps spinning the wheel until he gets 2 and wins.
The probability that he gets 2 for the first time in the i-th spin is \frac{1}{2^i}, so the expected number of spins is \sum_{i = 1}^{\infty} (i \times \frac{1}{2^i}) = 2.


Sample Input 3

100 6 10
11 12 13 14 15 16 17 18 19 20

Sample Output 3

-1

Sample Input 4

100000 2 2
2997 92458

Sample Output 4

201932.2222