Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
長さ N の数列 A=(A_1,A_2,\dots,A_N) と、長さ M の数列 B=(B_1,B_2,\dots,B_M) が与えられます。ここで、A,B のすべての要素は互いに相異なります。A,B のすべての要素を昇順に並べた長さ N+M の数列 C=(C_1,C_2,\dots,C_{N+M}) において、A に現れる要素が2つ連続するかどうか判定してください。
制約
- 1\leq N,M \leq 100
- 1\leq A_i,B_j \leq 200
- A_1, A_2, \dots, A_N, B_1, B_2, \dots, B_M は相異なる
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
出力
A に現れる要素が C において2つ連続するならば Yes を、そうでないなら No を出力せよ。
入力例 1
3 2 3 2 5 4 1
出力例 1
Yes
C=(1,2,3,4,5) です。A に現れる 2,3 が C で連続しているため、Yes を出力します。
入力例 2
3 2 3 1 5 4 2
出力例 2
No
C=(1,2,3,4,5) です。A に現れる要素が C で連続している箇所はないため、No を出力します。
入力例 3
1 1 1 2
出力例 3
No
Score : 200 points
Problem Statement
You are given a sequence A=(A_1,A_2,\dots,A_N) of length N and a sequence B=(B_1,B_2,\dots,B_M) of length M. Here, all elements of A and B are pairwise distinct. Determine whether the sequence C=(C_1,C_2,\dots,C_{N+M}) formed by sorting all elements of A and B in ascending order contains two consecutive elements appearing in A.
Constraints
- 1 \leq N, M \leq 100
- 1 \leq A_i, B_j \leq 200
- A_1, A_2, \dots, A_N, B_1, B_2, \dots, B_M are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
Output
If C contains two consecutive elements appearing in A, print Yes; otherwise, print No.
Sample Input 1
3 2 3 2 5 4 1
Sample Output 1
Yes
C=(1,2,3,4,5). Since 2 and 3 from A occur consecutively in C, print Yes.
Sample Input 2
3 2 3 1 5 4 2
Sample Output 2
No
C=(1,2,3,4,5). Since no two elements from A occur consecutively in C, print No.
Sample Input 3
1 1 1 2
Sample Output 3
No
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
二次元平面上の点 (0,0) から点 (A,B) に向かって距離 1 だけ移動します。移動後の座標を求めてください。
ただし、点 X から点 Y に向かって距離 d (\le 線分 XY の長さ) だけ移動すると、線分 XY 上で点 X からの距離が d であるような点に辿りつくものとします。
なお、制約より点 (0,0) と点 (A,B) の距離は 1 以上であることが保証されます。
制約
- 入力は全て整数
- 0 \le A,B \le 1000
- (A,B) \neq (0,0)
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
移動後の点を (x,y) とするとき、 x と y をこの順に空白区切りで出力せよ。
なお、各出力について、想定解との絶対誤差または相対誤差が 10^{−6} 以下であれば正解として扱われる。
入力例 1
3 4
出力例 1
0.600000000000 0.800000000000
他にも、例えば 0.5999999999 0.8000000001 という出力も許容されます。
入力例 2
1 0
出力例 2
1.000000000000 0.000000000000
点 (A,B) に到着する場合もあります。
入力例 3
246 402
出力例 3
0.521964870245 0.852966983083
Score : 200 points
Problem Statement
From the point (0,0) in a two-dimensional plane, let us move the distance of 1 toward the point (A, B). Find our coordinates after the move.
Here, after moving the distance of d from a point X to a point Y (d \le length of the segment XY), we are at the point on the segment XY whose distance from X is d.
The Constraints guarantee that the distance between the points (0, 0) and (A, B) is at least 1.
Constraints
- All values in input are integers.
- 0 \le A,B \le 1000
- (A,B) \neq (0,0)
Input
Input is given from Standard Input in the following format:
A B
Output
Let (x, y) be our coordinates after the move. Print x and y in this order, separated by a space.
Your output is considered correct when, for each printed value, the absolute or relative error from the judge's answer is at most 10^{−6}.
Sample Input 1
3 4
Sample Output 1
0.600000000000 0.800000000000
Printing 0.5999999999 0.8000000001, for example, would also be accepted.
Sample Input 2
1 0
Sample Output 2
1.000000000000 0.000000000000
We may arrive at (A, B).
Sample Input 3
246 402
Sample Output 3
0.521964870245 0.852966983083
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 人のすぬけ君が円周上に並んでおり、反時計回りに 1,2,...,N の番号がついています。
i\, (1 \leq i \leq N) 番目のすぬけ君は時刻 t に宝石をもらうと S_i 単位時間後、すなわち時刻 t+S_i にその宝石を (i+1) 番目のすぬけ君に渡します。ただし、(N+1) 番目のすぬけ君とは 1 番目のすぬけ君のことを指すとします。
また、高橋君は時刻 T_i に i 番目のすぬけ君に宝石を渡します。
全ての i\, (1 \leq i \leq N) について、i 番目のすぬけ君が初めて宝石をもらう時刻を求めてください。なお、宝石の受け渡しにかかる時間は無視できるものとします。
制約
- 1 \leq N \leq 200000
- 1 \leq S_i,T_i \leq 10^9
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \ldots S_N T_1 T_2 \ldots T_N
出力
N 行出力せよ。i\, (1 \leq i \leq N) 行目には、i 番目のすぬけ君が初めて宝石をもらう時刻を出力すること。
入力例 1
3 4 1 5 3 10 100
出力例 1
3 7 8
時刻 13 までのすぬけ君と高橋君の行動を時系列順に並べます。
時刻 3 : 高橋君が 1 番目のすぬけ君に宝石を渡します。
時刻 7 : 1 番目のすぬけ君が 2 番目のすぬけ君に宝石を渡します。
時刻 8 : 2 番目のすぬけ君が 3 番目のすぬけ君に宝石を渡します。
時刻 10 : 高橋君が 2 番目のすぬけ君に宝石を渡します。
時刻 11 : 2 番目のすぬけ君が 3 番目のすぬけ君に宝石を渡します。
時刻 13 : 3 番目のすぬけ君が 1 番目のすぬけ君に宝石を渡します。
時刻 14 以降も彼らは宝石の受け渡しを行いますが、答えには影響しません。
入力例 2
4 100 100 100 100 1 1 1 1
出力例 2
1 1 1 1
S_i や T_i が相異なるとは限らないことに注意してください。
入力例 3
4 1 2 3 4 1 2 4 7
出力例 3
1 2 4 7
あるすぬけくんが同時刻に複数の宝石の受け渡しをする可能性があること、特に高橋くんとすぬけくんの両方から同時に宝石を貰う可能性があることに注意してください。
入力例 4
8 84 87 78 16 94 36 87 93 50 22 63 28 91 60 64 27
出力例 4
50 22 63 28 44 60 64 27
Score : 300 points
Problem Statement
There are N creatures standing in a circle, called Snuke 1, 2, ..., N in counter-clockwise order.
When Snuke i (1 \leq i \leq N) receives a gem at time t, S_i units of time later, it will hand that gem to Snuke i+1 at time t+S_i. Here, Snuke N+1 is Snuke 1.
Additionally, Takahashi will hand a gem to Snuke i at time T_i.
For each i (1 \leq i \leq N), find the time when Snuke i receives a gem for the first time. Assume that it takes a negligible time to hand a gem.
Constraints
- 1 \leq N \leq 200000
- 1 \leq S_i,T_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N S_1 S_2 \ldots S_N T_1 T_2 \ldots T_N
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain the time when Snuke i receives a gem for the first time.
Sample Input 1
3 4 1 5 3 10 100
Sample Output 1
3 7 8
We will list the three Snuke's and Takahashi's actions up to time 13 in chronological order.
Time 3: Takahashi hands a gem to Snuke 1.
Time 7: Snuke 1 hands a gem to Snuke 2.
Time 8: Snuke 2 hands a gem to Snuke 3.
Time 10: Takahashi hands a gem to Snuke 2.
Time 11: Snuke 2 hands a gem to Snuke 3.
Time 13: Snuke 3 hands a gem to Snuke 1.
After that, they will continue handing gems, though it will be irrelevant to the answer.
Sample Input 2
4 100 100 100 100 1 1 1 1
Sample Output 2
1 1 1 1
Note that the values S_i and T_i may not be distinct.
Sample Input 3
4 1 2 3 4 1 2 4 7
Sample Output 3
1 2 4 7
Note that a Snuke may perform multiple transactions simultaneously. Particularly, a Snuke may receive gems simultaneously from Takahashi and another Snuke.
Sample Input 4
8 84 87 78 16 94 36 87 93 50 22 63 28 91 60 64 27
Sample Output 4
50 22 63 28 44 60 64 27
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君は黒いマスと透明なマスからなるシート A,B を 1 枚ずつと、透明なマスのみからなる無限に広がるシート C を持っています。
また、高橋君には黒いマスと透明なマスからなる、理想とするシート X が存在します。
シート A,B,X の大きさはそれぞれ縦 H_A マス \times 横 W_A マス、縦 H_B マス \times 横 W_B マス、縦 H_X マス \times 横 W_X マスです。
シート A の各マスは . と # からなる長さ W_A の文字列 H_A 個 A_1,A_2,\ldots,A_{H_A} によって表され、
A_i (1\leq i\leq H_A) の j 文字目 (1\leq j\leq W_A) が、
. のときシート A の上から i 行目かつ左から j 列目のマスは透明なマスであり、
# のとき黒いマスです。
シート B,X の各マスも、同様に長さ W_B の文字列 H_B 個 B_1,B_2,\ldots,B_{H_B} および長さ W_X の文字列 H_X 個 X_1,X_2,\ldots,X_{H_X} によって表されます。
高橋君の目標は、次の手順で、シート A,B,C から、A,B に存在する すべての黒いマスを使って シート X を作り出すことです。
- シート A,B をマス目に沿ってシート C に貼り付ける。この時、シート A,B はそれぞれ好きな場所に平行移動させて貼って良いが、シートを切り分けたり、回転させたりしてはいけない。
- シート C からマス目に沿って H_X\times W_X マスの領域を切り出す。ここで、切り出されたシートの各マスは、シート A または B の黒いマスが貼り付けられていれば黒いマスに、そうでなければ透明なマスとなる。
このとき、貼り付ける位置と切り出す領域をうまくとることで高橋君は目標を達成できるか、すなわち次の条件をともにみたすことにできるか判定してください。
- 切り出されたシートはシート A,B の 黒いマスをすべて 含む。切り出されたシートの上でシート A,B の黒いマスどうしが重なって存在していても構わない。
- 切り出されたシートは、回転させたり裏返したりすることなくシート X と一致する。
制約
- 1\leq H_A,W_A,H_B,W_B,H_X,W_X\leq 10
- H_A,W_A,H_B,W_B,H_X,W_X は整数
- A_i は
.と#のみからなる長さ W_A の文字列 - B_i は
.と#のみからなる長さ W_B の文字列 - X_i は
.と#のみからなる長さ W_X の文字列 - シート A,B,X はそれぞれ少なくとも 1 つ以上の黒いマスを含む。
入力
入力は以下の形式で標準入力から与えられる。
H_A W_A
A_1
A_2
\vdots
A_{H_A}
H_B W_B
B_1
B_2
\vdots
B_{H_B}
H_X W_X
X_1
X_2
\vdots
X_{H_X}
出力
高橋君が問題文中の目標を達成できるならば Yes を、できないならば No を出力せよ。
入力例 1
3 5 #.#.. ..... .#... 2 2 #. .# 5 3 ... #.# .#. .#. ...
出力例 1
Yes
まず、シート A をシート C に貼り付けると下図のようになります。
\vdots
.......
.#.#...
\cdots.......\cdots
..#....
.......
\vdots
さらに、シート B をシート A と左上を合わせて貼ってみると下図のようになります。
\vdots
.......
.#.#...
\cdots..#....\cdots
..#....
.......
\vdots
ここで、上で具体的に図示されている範囲のうち、上から 1 行目かつ左から 2 列目のマスを左上として 5\times 3 マスを切り出すと下図のようになります。
... #.# .#. .#. ...
これはシート A,B のすべての黒いマスを含んでおり、また、シート X と一致しているため条件を満たしています。
よって、Yes を出力します。
入力例 2
2 2 #. .# 2 2 #. .# 2 2 ## ##
出力例 2
No
シート A や B を回転させて貼ってはいけないことに注意してください。
入力例 3
1 1 # 1 2 ## 1 1 #
出力例 3
No
どのように貼ったり切り出したりしても、シート B の黒いマスをすべて含むように切り出すことはできないため、1 つめの条件をみたすことができません。
よって、No を出力します。
入力例 4
3 3 ### ... ... 3 3 #.. #.. #.. 3 3 ..# ..# ###
出力例 4
Yes
Score : 300 points
Problem Statement
Takahashi has two sheets A and B, each composed of black squares and transparent squares, and an infinitely large sheet C composed of transparent squares.
There is also an ideal sheet X for Takahashi composed of black squares and transparent squares.
The sizes of sheets A, B, and X are H_A rows \times W_A columns, H_B rows \times W_B columns, and H_X rows \times W_X columns, respectively.
The squares of sheet A are represented by H_A strings of length W_A, A_1, A_2, \ldots, A_{H_A} consisting of . and #.
If the j-th character (1\leq j\leq W_A) of A_i (1\leq i\leq H_A) is ., the square at the i-th row from the top and j-th column from the left is transparent; if it is #, that square is black.
Similarly, the squares of sheets B and X are represented by H_B strings of length W_B, B_1, B_2, \ldots, B_{H_B}, and H_X strings of length W_X, X_1, X_2, \ldots, X_{H_X}, respectively.
Takahashi's goal is to create sheet X using all black squares in sheets A and B by following the steps below with sheets A, B, and C.
- Paste sheets A and B onto sheet C along the grid. Each sheet can be pasted anywhere by translating it, but it cannot be cut or rotated.
- Cut out an H_X\times W_X area from sheet C along the grid. Here, a square of the cut-out sheet will be black if a black square of sheet A or B is pasted there, and transparent otherwise.
Determine whether Takahashi can achieve his goal by appropriately choosing the positions where the sheets are pasted and the area to cut out, that is, whether he can satisfy both of the following conditions.
- The cut-out sheet includes all black squares of sheets A and B. The black squares of sheets A and B may overlap on the cut-out sheet.
- The cut-out sheet coincides sheet X without rotating or flipping.
Constraints
- 1\leq H_A, W_A, H_B, W_B, H_X, W_X\leq 10
- H_A, W_A, H_B, W_B, H_X, W_X are integers.
- A_i is a string of length W_A consisting of
.and#. - B_i is a string of length W_B consisting of
.and#. - X_i is a string of length W_X consisting of
.and#. - Sheets A, B, and X each contain at least one black square.
Input
The input is given from Standard Input in the following format:
H_A W_A
A_1
A_2
\vdots
A_{H_A}
H_B W_B
B_1
B_2
\vdots
B_{H_B}
H_X W_X
X_1
X_2
\vdots
X_{H_X}
Output
If Takahashi can achieve the goal described in the problem statement, print Yes; otherwise, print No.
Sample Input 1
3 5 #.#.. ..... .#... 2 2 #. .# 5 3 ... #.# .#. .#. ...
Sample Output 1
Yes
First, paste sheet A onto sheet C, as shown in the figure below.
\vdots
.......
.#.#...
\cdots.......\cdots
..#....
.......
\vdots
Next, paste sheet B so that its top-left corner aligns with that of sheet A, as shown in the figure below.
\vdots
.......
.#.#...
\cdots..#....\cdots
..#....
.......
\vdots
Now, cut out a 5\times 3 area with the square in the first row and second column of the range illustrated above as the top-left corner, as shown in the figure below.
... #.# .#. .#. ...
This includes all black squares of sheets A and B and matches sheet X, satisfying the conditions.
Therefore, print Yes.
Sample Input 2
2 2 #. .# 2 2 #. .# 2 2 ## ##
Sample Output 2
No
Note that sheets A and B may not be rotated or flipped when pasting them.
Sample Input 3
1 1 # 1 2 ## 1 1 #
Sample Output 3
No
No matter how you paste or cut, you cannot cut out a sheet that includes all black squares of sheet B, so you cannot satisfy the first condition.
Therefore, print No.
Sample Input 4
3 3 ### ... ... 3 3 #.. #.. #.. 3 3 ..# ..# ###
Sample Output 4
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
高橋くんは、これから N 個のプレゼントをもらいます。
高橋くんにはテンションという非負整数のパラメータがあり、テンションはプレゼントをもらうごとに変動します。 それぞれのプレゼントは価値 P 、テンション上げ度 A 、テンション下げ度 B という 3 つのパラメータをもち、これらのパラメータによって高橋くんのテンションは次のように変動します。
- もらったプレゼントの価値 P がテンションの値以上であるとき、高橋くんはプレゼントに喜び、テンションが A だけ増加する。
- もらったプレゼントの価値 P がテンションの値より小さいとき、高橋くんはプレゼントにがっかりし、テンションが B だけ減少する。ただし、高橋くんのテンションの値が B より小さかった場合、高橋くんのテンションは 0 になる。
i 番目 (1\le i\le N) に受け取るプレゼントの価値は P _ i 、テンション上げ度は A _ i 、テンション下げ度は B _ i です。
Q 個の質問が与えられるので、その全てに答えてください。 i 番目 (1\le i\le Q) の質問では、非負整数 X _ i が与えられるので次の質問に答えてください。
高橋くんのテンションがはじめ X _ i だったときの、N 個のプレゼントをすべて受け取ったあとの高橋くんのテンションを求めよ。
制約
- 1\le N\le10000
- 1\le P _ i\le500\ (1\le i\le N)
- 1\le A _ i\le500\ (1\le i\le N)
- 1\le B _ i\le500\ (1\le i\le N)
- 1\le Q\le5\times10 ^ 5
- 0\le X _ i\le10 ^ 9\ (1\le i\le Q)
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N P _ 1 A _ 1 B _ 1 P _ 2 A _ 2 B _ 2 \vdots P _ N A _ N B _ N Q X _ 1 X _ 2 \vdots X _ Q
出力
Q 行にわたって出力せよ。 i 行目には、i 番目の質問に対する答えを出力せよ。
入力例 1
4 3 1 4 1 5 9 2 6 5 3 5 8 11 0 1 2 3 4 5 6 7 8 9 10
出力例 1
6 0 0 0 5 6 0 0 0 0 0
高橋くんのテンションがはじめ 10 だったとき、高橋くんのテンションは以下のように変動します。
- 1 つめのプレゼントの価値 3 は高橋くんのテンション 10 未満なので、テンション下げ度 4 だけ高橋くんのテンションが減少し、高橋くんのテンションが 6 になる。
- 2 つめのプレゼントの価値 1 は高橋くんのテンション 6 未満で、高橋くんのテンション 6 はテンション下げ度 9 未満なので、高橋くんのテンションが 0 になる。
- 3 つめのプレゼントの価値 2 は高橋くんのテンション 0 以上なので、テンション上げ度 6 だけ高橋くんのテンションが増加し、高橋くんのテンションが 6 になる。
- 4 つめのプレゼントの価値 3 は高橋くんのテンション 6 未満で、高橋くんのテンション 6 はテンション下げ度 8 未満なので、高橋くんのテンションが 0 になる。
よって、最終的な高橋くんのテンションは 0 になります。
入力例 2
3 500 500 500 500 500 500 500 500 500 1 1000000000
出力例 2
999998500
高橋くんのテンションが高すぎるため、最高のプレゼントを貰っていても高橋くんのテンションは下がり続けます。
入力例 3
20 124 370 105 280 200 420 425 204 302 435 141 334 212 287 231 262 410 481 227 388 466 222 314 366 307 205 401 226 460 452 336 291 119 302 104 432 478 348 292 246 337 403 102 404 371 368 399 417 291 416 351 236 263 231 170 415 482 101 339 184 20 1162 1394 1695 2501 3008 3298 4053 4093 4330 5199 5302 5869 5875 6332 6567 7483 7562 7725 9723 9845
出力例 3
339 339 339 339 339 339 339 339 339 339 339 339 339 389 339 643 722 885 2883 3005
Score : 425 points
Problem Statement
Takahashi will receive N presents.
He has a parameter called mood, which is a non-negative integer, and his mood changes every time he receives a present. Each present has three parameters: value P, mood increase A, and mood decrease B, and his mood changes as follows based on these parameters:
- When the value P of the received present is greater than or equal to his mood, he is happy with the present, and his mood increases by A.
- When the value P of the received present is less than his mood, he is disappointed with the present, and his mood decreases by B. However, if his mood is originally less than B, it becomes 0.
The i-th (1\le i\le N) present he receives has value P _ i, mood increase A _ i, and mood decrease B _ i.
You are given Q questions, so answer all of them. In the i-th (1\le i\le Q) question, you are given a non-negative integer X _ i, so answer the following question:
Find Takahashi's mood after receiving all N presents when his mood is initially X _ i.
Constraints
- 1\le N\le10000
- 1\le P _ i\le500\ (1\le i\le N)
- 1\le A _ i\le500\ (1\le i\le N)
- 1\le B _ i\le500\ (1\le i\le N)
- 1\le Q\le5\times10 ^ 5
- 0\le X _ i\le10 ^ 9\ (1\le i\le Q)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N P _ 1 A _ 1 B _ 1 P _ 2 A _ 2 B _ 2 \vdots P _ N A _ N B _ N Q X _ 1 X _ 2 \vdots X _ Q
Output
Output Q lines. The i-th line should contain the answer to the i-th question.
Sample Input 1
4 3 1 4 1 5 9 2 6 5 3 5 8 11 0 1 2 3 4 5 6 7 8 9 10
Sample Output 1
6 0 0 0 5 6 0 0 0 0 0
When Takahashi's initial mood is 10, his mood changes as follows:
- The value 3 of the first present is less than his mood 10, so his mood decreases by the mood decrease 4, and his mood becomes 6.
- The value 1 of the second present is less than his mood 6, and Takahashi's mood 6 is less than the mood decrease 9, so his mood becomes 0.
- The value 2 of the third present is not less than his mood 0, so his mood increases by the mood increase 6, and his mood becomes 6.
- The value 3 of the fourth present is less than his mood 6, and Takahashi's mood 6 is less than the mood decrease 8, so his mood becomes 0.
Therefore, his final mood is 0.
Sample Input 2
3 500 500 500 500 500 500 500 500 500 1 1000000000
Sample Output 2
999998500
Because Takahashi's mood is too high, his mood keeps decreasing even when he receives the best presents.
Sample Input 3
20 124 370 105 280 200 420 425 204 302 435 141 334 212 287 231 262 410 481 227 388 466 222 314 366 307 205 401 226 460 452 336 291 119 302 104 432 478 348 292 246 337 403 102 404 371 368 399 417 291 416 351 236 263 231 170 415 482 101 339 184 20 1162 1394 1695 2501 3008 3298 4053 4093 4330 5199 5302 5869 5875 6332 6567 7483 7562 7725 9723 9845
Sample Output 3
339 339 339 339 339 339 339 339 339 339 339 339 339 389 339 643 722 885 2883 3005