C - Pizza

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

ここに円形のピザが 1 枚あります。
高橋くんは長さ N の数列 A を使ってこのピザを以下の手順で切り分けます。

  • 最初に、円の中心から 12 時の方向に切れ込みをひとつ入れます。
  • 次に、以下の操作を N 回繰り返します。 i 回目の操作では以下を行います。
    • まず、ピザを時計回りに A_i 度回転させる。
    • 次に、円の中心から 12 時の方向に切れ込みをひとつ入れる。

例えば、A=(90,180,45,195) として手順を行うと、下図のようになります。

このとき、最も大きなピザの中心角が何度であるか求めてください。

制約

  • 入力は全て整数
  • 1 \le N \le 359
  • 1 \le A_i \le 359
  • 同じ場所に複数回切れ込みが入ることはない。

入力

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

N
A_1 A_2 \dots A_N

出力

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


入力例 1

4
90 180 45 195

出力例 1

120

この入力は問題文中の例と一致します。
最も大きなピザの中心角は 120 度です。


入力例 2

1
1

出力例 2

359

入力例 3

10
215 137 320 339 341 41 44 18 241 149

出力例 3

170

Score : 200 points

Problem Statement

We have a circular pizza.
Takahashi will cut this pizza using a sequence A of length N, according to the following procedure.

  • First, make a cut from the center in the 12 o'clock direction.
  • Next, do N operations. The i-th operation is as follows.
    • Rotate the pizza A_i degrees clockwise.
    • Then, make a cut from the center in the 12 o'clock direction.

For example, if A=(90,180,45,195), the procedure cuts the pizza as follows.

Find the center angle of the largest pizza after the procedure.

Constraints

  • All values in input are integers.
  • 1 \le N \le 359
  • 1 \le A_i \le 359
  • There will be no multiple cuts at the same position.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the answer as an integer.


Sample Input 1

4
90 180 45 195

Sample Output 1

120

This input coincides with the example in the Problem Statement.
The center angle of the largest pizza is 120 degrees.


Sample Input 2

1
1

Sample Output 2

359

Sample Input 3

10
215 137 320 339 341 41 44 18 241 149

Sample Output 3

170
D - LOOKUP

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

英小文字からなる文字列 S,T が与えられるので、 TS の(連続する)部分文字列かどうか判定してください。

なお、文字列 X に以下の操作を 0 回以上施して文字列 Y が得られる時、またその時に限り YX の(連続する)部分文字列であると言います。

  • 以下の 2 つの操作から 1 つを選択して、その操作を行う。
    • X の先頭の 1 文字を削除する。
    • X の末尾の 1 文字を削除する。

例えば tagvoltage の(連続する)部分文字列ですが、 aceatcoder の(連続する)部分文字列ではありません。

制約

  • S,T は英小文字からなる
  • 1 \le |S|,|T| \le 100 ( |X| は文字列 X の長さ )

入力

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

S
T

出力

TS の(連続する)部分文字列なら Yes 、そうでないなら No と出力せよ。


入力例 1

voltage
tag

出力例 1

Yes

tagvoltage の(連続する)部分文字列です。


入力例 2

atcoder
ace

出力例 2

No

aceatcoder の(連続する)部分文字列ではありません。


入力例 3

gorilla
gorillagorillagorilla

出力例 3

No

入力例 4

toyotasystems
toyotasystems

出力例 4

Yes

S=T である場合もあります。

Score : 200 points

Problem Statement

You are given strings S and T consisting of lowercase English letters. Determine whether T is a (contiguous) substring of S.

A string Y is said to be a (contiguous) substring of X if and only if Y can be obtained by performing the operation below on X zero or more times.

  • Do one of the following.
    • Delete the first character in X.
    • Delete the last character in X.

For instance, tag is a (contiguous) substring of voltage, while ace is not a (contiguous) substring of atcoder.

Constraints

  • S and T consist of lowercase English letters.
  • 1 \le |S|,|T| \le 100 (|X| denotes the length of a string X.)

Input

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

S
T

Output

If T is a (contiguous) substring of S, print Yes; otherwise, print No.


Sample Input 1

voltage
tag

Sample Output 1

Yes

tag is a (contiguous) substring of voltage.


Sample Input 2

atcoder
ace

Sample Output 2

No

ace is not a (contiguous) substring of atcoder.


Sample Input 3

gorilla
gorillagorillagorilla

Sample Output 3

No

Sample Input 4

toyotasystems
toyotasystems

Sample Output 4

Yes

It is possible that S=T.

E - X drawing

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

上下左右に広がる N\times N のマス目があり、最初全てのマスは白く塗られています。このマス目の上から i 行目、左から j 列目のマスを (i,j) で表します。

高橋君は 1 以上 N 以下の整数 A, B を持っており、次のような操作を行います。

  • \max(1-A,1-B)\leq k\leq \min(N-A,N-B) をみたす全ての整数 k について、(A+k,B+k) を黒く塗る。
  • \max(1-A,B-N)\leq k\leq \min(N-A,B-1) をみたす全ての整数 k について、(A+k,B-k) を黒く塗る。

この操作を行った後のマス目について、P\leq i\leq Q かつ R\leq j\leq S をみたす各マス (i,j) がそれぞれ何色で塗られているか求めてください。

制約

  • 1 \leq N \leq 10^{18}
  • 1 \leq A \leq N
  • 1 \leq B \leq N
  • 1 \leq P \leq Q \leq N
  • 1 \leq R \leq S \leq N
  • (Q-P+1)\times(S-R+1)\leq 3\times 10^5
  • 入力は全て整数である。

入力

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

N A B
P Q R S

出力

Q-P+1 行出力せよ。
各行は #. のみからなる長さ S-R+1 の文字列であり、 i 行目の文字列の j 番目の文字が # であることは (P+i-1,R+j-1) が黒く塗られていることを、 . であることは (P+i-1,R+j-1) が白く塗られていることをさす。


入力例 1

5 3 2
1 5 1 5

出力例 1

...#.
#.#..
.#...
#.#..
...#.

1 つめの操作で (2,1), (3,2), (4,3), (5,4)4 マスが、 2 つめの操作で (4,1), (3,2), (2,3), (1,4)4 マスが黒く塗られます。
よって、P=1, Q=5, R=1, S=5 より、上のように出力します。


入力例 2

5 3 3
4 5 2 5

出力例 2

#.#.
...#

操作によって、 (1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5)9 マスが 黒く塗られます。
P=4, Q=5, R=2, S=5 より、上のように出力します。


入力例 3

1000000000000000000 999999999999999999 999999999999999999
999999999999999998 1000000000000000000 999999999999999998 1000000000000000000

出力例 3

#.#
.#.
#.#

入力が 32 bit 整数型に収まらないことがあることに注意してください。

Score : 300 points

Problem Statement

There is an N\times N grid with horizontal rows and vertical columns, where all squares are initially painted white. Let (i,j) denote the square at the i-th row and j-th column.

Takahashi has integers A and B, which are between 1 and N (inclusive). He will do the following operations.

  • For every integer k such that \max(1-A,1-B)\leq k\leq \min(N-A,N-B), paint (A+k,B+k) black.
  • For every integer k such that \max(1-A,B-N)\leq k\leq \min(N-A,B-1), paint (A+k,B-k) black.

In the grid after these operations, find the color of each square (i,j) such that P\leq i\leq Q and R\leq j\leq S.

Constraints

  • 1 \leq N \leq 10^{18}
  • 1 \leq A \leq N
  • 1 \leq B \leq N
  • 1 \leq P \leq Q \leq N
  • 1 \leq R \leq S \leq N
  • (Q-P+1)\times(S-R+1)\leq 3\times 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B
P Q R S

Output

Print Q-P+1 lines.
Each line should contain a string of length S-R+1 consisting of # and .. The j-th character of the string in the i-th line should be # to represent that (P+i-1, R+j-1) is painted black, and . to represent that (P+i-1, R+j-1) is white.


Sample Input 1

5 3 2
1 5 1 5

Sample Output 1

...#.
#.#..
.#...
#.#..
...#.

The first operation paints the four squares (2,1), (3,2), (4,3), (5,4) black, and the second paints the four squares (4,1), (3,2), (2,3), (1,4) black.
Thus, the above output should be printed, since P=1, Q=5, R=1, S=5.


Sample Input 2

5 3 3
4 5 2 5

Sample Output 2

#.#.
...#

The operations paint the nine squares (1,1), (1,5), (2,2), (2,4), (3,3), (4,2), (4,4), (5,1), (5,5).
Thus, the above output should be printed, since P=4, Q=5, R=2, S=5.


Sample Input 3

1000000000000000000 999999999999999999 999999999999999999
999999999999999998 1000000000000000000 999999999999999998 1000000000000000000

Sample Output 3

#.#
.#.
#.#

Note that the input may not fit into a 32-bit integer type.

F - Inverse of Permutation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

1,2,\dots,N1 回ずつ現れる長さ N の数列を「長さ N の順列」と呼びます。
長さ N の順列 P = (p_1, p_2,\dots,p_N) が与えられるので、以下の条件を満たす長さ N の順列 Q = (q_1,\dots,q_N) を出力してください。

  • 全ての i (1 \leq i \leq N) に対して Qp_i 番目の要素が i である。

ただし、条件を満たす Q は必ずただ 1 つ存在することが証明できます。

制約

  • 1 \leq N \leq 2 \times 10^5
  • (p_1,p_2,\dots,p_N) は長さ N の順列である。
  • 入力は全て整数である。

入力

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

N
p_1 p_2 \dots p_N

出力

数列 Q を空白区切りで 1 行で出力せよ。

q_1 q_2 \dots q_N

入力例 1

3
2 3 1

出力例 1

3 1 2

以下に説明する通り、 Q=(3,1,2) は条件を満たす順列です。

  • i = 1 のとき p_i = 2, q_2 = 1
  • i = 2 のとき p_i = 3, q_3 = 2
  • i = 3 のとき p_i = 1, q_1 = 3

入力例 2

3
1 2 3

出力例 2

1 2 3

全ての i (1 \leq i \leq N) に対して p_i = i が成り立つときは P = Q になります。


入力例 3

5
5 3 2 4 1

出力例 3

5 3 2 4 1

Score : 300 points

Problem Statement

We will call a sequence of length N where each of 1,2,\dots,N occurs once as a permutation of length N.
Given a permutation of length N, P = (p_1, p_2,\dots,p_N), print a permutation of length N, Q = (q_1,\dots,q_N), that satisfies the following condition.

  • For every i (1 \leq i \leq N), the p_i-th element of Q is i.

It can be proved that there exists a unique Q that satisfies the condition.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • (p_1,p_2,\dots,p_N) is a permutation of length N (defined in Problem Statement).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 \dots p_N

Output

Print the sequence Q in one line, with spaces in between.

q_1 q_2 \dots q_N

Sample Input 1

3
2 3 1

Sample Output 1

3 1 2

The permutation Q=(3,1,2) satisfies the condition, as follows.

  • For i = 1, we have p_i = 2, q_2 = 1.
  • For i = 2, we have p_i = 3, q_3 = 2.
  • For i = 3, we have p_i = 1, q_1 = 3.

Sample Input 2

3
1 2 3

Sample Output 2

1 2 3

If p_i = i for every i (1 \leq i \leq N), we will have P = Q.


Sample Input 3

5
5 3 2 4 1

Sample Output 3

5 3 2 4 1
G - Laser Marking

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350

問題文

xy 平面に対し、レーザを照射しながら線分を印字する印字機があります。

  • 印字開始時、レーザ照射位置は座標 (0, 0) にある。
  • 線分を印字する際は、以下の流れに従う。

    • まず、レーザ照射位置を線分の端点のうちどちらか 1 つに移動させる。
      • どちらの端点から描画を始めてもよい。
    • その後、レーザ照射位置のある端点からもう一方の端点まで、レーザを照射しながらレーザ照射位置を一直線に移動させる。
      • 線分の途中で印字を中止することは許されない。
  • レーザを照射していない時、レーザ照射位置は 1 秒あたり速度 S で任意の方向に移動できる。

  • レーザを照射している時、レーザ照射位置は 1 秒あたり速度 T で印字中の線分に沿って移動できる。
  • レーザ照射位置の移動にかかる時間以外の所要時間は無視できる。

高橋君はこの印字機で N 本の線分を印字したいです。
そのうち i 本目の線分は、座標 (A_i, B_i) と座標 (C_i, D_i) を結びます。
なお、複数の線分が重なっていることがありますが、全ての線分についてその都度重なっている部分を印字する必要があります。

うまく印字機を操作したとき、全ての線分を印字完了するまでにかかる最小の時間は何秒ですか?

制約

  • 入力は全て整数
  • 1 \le N \le 6
  • 1 \le T \le S \le 1000
  • -1000 \le A_i,B_i,C_i,D_i \le 1000
  • (A_i,B_i) \neq (C_i,D_i) ( 1 \le i \le N )

入力

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

N S T
A_1 B_1 C_1 D_1
\vdots
A_N B_N C_N D_N

出力

答えを出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-6} 以下であれば正解として扱われる。


入力例 1

3 2 1
1 3 2 1
0 2 0 0
3 0 2 0

出力例 1

6.44317475868633722080
  • レーザを照射しながらレーザ照射位置を (0,0) から (0,2) まで移動させ、 2 本目の線分を描画する。
    • この描画に要する時間は 2 秒である。
  • レーザを照射せずレーザ照射位置を (0,2) から (1,3) まで移動させる。
    • この移動に要する時間は \sqrt{2}/2 秒である。
  • レーザを照射しながらレーザ照射位置を (1,3) から (2,1) まで移動させ、 1 本目の線分を描画する。
    • この描画に要する時間は \sqrt{5} 秒である。
  • レーザを照射せずレーザ照射位置を (2,1) から (2,0) まで移動させる。
    • この移動に要する時間は 1/2 秒である。
  • レーザを照射しながらレーザ照射位置を (2,0) から (3,0) まで移動させ、 3 本目の線分を描画する。

    • この描画に要する時間は 1 秒である。
  • 全体の所要時間は 2 + (\sqrt{2}/2) + \sqrt{5} + (1/2) + 1\approx 6.443175 秒です。


入力例 2

2 1 1
0 0 10 10
0 2 2 0

出力例 2

20.97056274847714058517

入力例 3

6 3 2
-1000 -1000 1000 1000
1000 -1000 -1000 1000
-1000 -1000 1000 1000
1000 -1000 -1000 1000
1000 1000 -1000 -1000
-1000 1000 1000 -1000

出力例 3

9623.35256169626864153344

複数の線分が重なっていますが、全ての線分についてその都度重なっている部分を印字する必要があります。


入力例 4

6 10 8
1000 1000 -1000 -1000
1000 -1000 -1000 -1000
-1000 1000 1000 1000
-1000 1000 -1000 -1000
1000 1000 1000 -1000
1000 -1000 -1000 1000

出力例 4

2048.52813742385702910909

Score : 350 points

Problem Statement

There is a printing machine that prints line segments on the xy-plane by emitting a laser.

  • At the start of printing, the laser position is at coordinate (0, 0).
  • When printing a line segment, the procedure below is followed.

    • First, move the laser position to one of the endpoints of the line segment.
      • One may start drawing from either endpoint.
    • Then, move the laser position in a straight line from the current endpoint to the other endpoint while emitting the laser.
      • It is not allowed to stop printing in the middle of a line segment.
  • When not emitting the laser, the laser position can move in any direction at a speed of S units per second.

  • When emitting the laser, the laser position can move along the line segment being printed at a speed of T units per second.
  • The time required for operations other than moving the laser position can be ignored.

Takahashi wants to print N line segments using this printing machine.
The i-th line segment connects coordinates (A_i, B_i) and (C_i, D_i).
Some line segments may overlap, in which case he needs to print the overlapping parts for each line segment separately.

What is the minimum number of seconds required to complete printing all the line segments when he operates the printing machine optimally?

Constraints

  • All input values are integers.
  • 1 \le N \le 6
  • 1 \le T \le S \le 1000
  • -1000 \le A_i,B_i,C_i,D_i \le 1000
  • (A_i,B_i) \neq (C_i,D_i) ( 1 \le i \le N )

Input

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

N S T
A_1 B_1 C_1 D_1
\vdots
A_N B_N C_N D_N

Output

Print the answer.

Your output will be considered correct if the absolute or relative error from the true value does not exceed 10^{-6}.


Sample Input 1

3 2 1
1 3 2 1
0 2 0 0
3 0 2 0

Sample Output 1

6.44317475868633722080
  • Emit the laser while moving the laser position from (0,0) to (0,2), printing the second line segment.
    • This takes 2 seconds.
  • Move the laser position from (0,2) to (1,3) without emitting the laser.
    • This takes \sqrt{2}/2 seconds.
  • Emit the laser while moving the laser position from (1,3) to (2,1), printing the first line segment.
    • This takes \sqrt{5} seconds.
  • Move the laser position from (2,1) to (2,0) without emitting the laser.
    • This takes 1/2 second.
  • Emit the laser while moving the laser position from (2,0) to (3,0), printing the third line segment.
    • This takes 1 second.
  • The total time taken is 2 + (\sqrt{2}/2) + \sqrt{5} + (1/2) + 1 \approx 6.443175 seconds.

Sample Input 2

2 1 1
0 0 10 10
0 2 2 0

Sample Output 2

20.97056274847714058517

Sample Input 3

6 3 2
-1000 -1000 1000 1000
1000 -1000 -1000 1000
-1000 -1000 1000 1000
1000 -1000 -1000 1000
1000 1000 -1000 -1000
-1000 1000 1000 -1000

Sample Output 3

9623.35256169626864153344

Multiple line segments overlap here, and you need to print the overlapping parts for each line segment separately.


Sample Input 4

6 10 8
1000 1000 -1000 -1000
1000 -1000 -1000 -1000
-1000 1000 1000 1000
-1000 1000 -1000 -1000
1000 1000 1000 -1000
1000 -1000 -1000 1000

Sample Output 4

2048.52813742385702910909