Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
この問題における 11/22 文字列の定義は A 問題および E 問題と同じです。
文字列 T が以下の条件を全て満たすとき、T を 11/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 は / を 1 個以上含みます。
11/22 文字列であるような S の(連続な)部分文字列の長さの最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- S は
1,2,/からなる長さ N の文字列 - S は
/を 1 個以上含む
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
11/22 文字列であるような S の(連続な)部分文字列の長さの最大値を出力せよ。
入力例 1
8 211/2212
出力例 1
5
S の 2 文字目から 6 文字目からなる部分文字列は 11/22 で、これは 11/22 文字列です。S の部分文字列のうち 11/22 文字列であるものはこれが最長です。よって 5 が答えです。
入力例 2
5 22/11
出力例 2
1
入力例 3
22 /1211/2///2111/2222/11
出力例 3
7
Score : 300 points
Problem Statement
The definition of an 11/22 string in this problem is the same as in Problems A 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.
You are given a string S of length N consisting of 1, 2, and /, where S contains at least one /.
Find the maximum length of a (contiguous) substring of S that is an 11/22 string.
Constraints
- 1 \leq N \leq 2 \times 10^5
- S is a string of length N consisting of
1,2, and/. - S contains at least one
/.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the maximum length of a (contiguous) substring of S that is an 11/22 string.
Sample Input 1
8 211/2212
Sample Output 1
5
The substring from the 2-nd to 6-th character of S is 11/22, which is an 11/22 string. Among all substrings of S that are 11/22 strings, this is the longest. Therefore, the answer is 5.
Sample Input 2
5 22/11
Sample Output 2
1
Sample Input 3
22 /1211/2///2111/2222/11
Sample Output 3
7
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
2 次元座標平面があります。x 軸正方向を右向き、y 軸正方向を上向きとします。
この平面上に自己交差のない四角形があります。
4 つの頂点の座標は反時計回りに (A_x,A_y),(B_x,B_y),(C_x,C_y),(D_x,D_y) です。
この四角形が凸であるか判定してください。
なお、四角形の 4 つの内角が全て 180 度未満であるとき、かつ、その時に限り、その四角形は凸であるといいます。
制約
- -100 \leq A_x,A_y,B_x,B_y,C_x,C_y,D_x,D_y \leq 100
- 入力に含まれる値は全て整数である
- 与えられる 4 点は四角形の 4 頂点を反時計回りに並べたものである
- 与えられる 4 点のなす四角形は自己交差がなく退化していない。すなわち
- どの 2 頂点も同じ座標にない
- どの 3 頂点も同一直線上にない
- 隣接しない 2 辺は共有点を持たない
入力
入力は以下の形式で標準入力から与えられる。
A_x A_y B_x B_y C_x C_y D_x D_y
出力
与えられる四角形が凸なら Yes、凸でないなら No を出力せよ。
入力例 1
0 0 1 0 1 1 0 1
出力例 1
Yes
与えられた四角形は正方形であり、4 つの内角は全て 90 度です。したがって、この四角形は凸です。

入力例 2
0 0 1 1 -1 0 1 -1
出力例 2
No
角 A が 270 度です。したがって、この四角形は凸ではありません。

Score : 300 points
Problem Statement
Consider a two-dimensional coordinate plane, where the x-axis is oriented to the right, and the y-axis is oriented upward.
In this plane, there is a quadrilateral without self-intersection.
The coordinates of the four vertices are (A_x,A_y), (B_x,B_y), (C_x,C_y), and (D_x,D_y), in counter-clockwise order.
Determine whether this quadrilateral is convex.
Here, a quadrilateral is convex if and only if all four interior angles are less than 180 degrees.
Constraints
- -100 \leq A_x,A_y,B_x,B_y,C_x,C_y,D_x,D_y \leq 100
- All values in input are integers.
- The given four points are the four vertices of a quadrilateral in counter-clockwise order.
- The quadrilateral formed by the given four points has no self-intersection and is non-degenerate. That is,
- no two vertices are at the same coordinates;
- no three vertices are colinear; and
- no two edges that are not adjacent have a common point.
Input
Input is given from Standard Input in the following format:
A_x A_y B_x B_y C_x C_y D_x D_y
Output
If the given quadrilateral is convex, print Yes; otherwise, print No.
Sample Input 1
0 0 1 0 1 1 0 1
Sample Output 1
Yes
The given quadrilateral is a square, whose four interior angles are all 90 degrees. Thus, this quadrilateral is convex.

Sample Input 2
0 0 1 1 -1 0 1 -1
Sample Output 2
No
The angle A is 270 degrees. Thus, this quadrilateral is not convex.

Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
頂点に 1 から N の番号が付いた N 頂点の重み付き無向完全グラフが与えられます。頂点 i と頂点 j\ (i< j) を結ぶ辺の重みは D_{i,j} です。
以下の条件を満たすように何本かの辺を選ぶとき、選んだ辺の重みの総和としてあり得る最大値を求めてください。
- 選んだ辺の端点はどの 2 個も相異なる。
制約
- 2\leq N\leq 16
- 1\leq D_{i,j} \leq 10^9
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N
D_{1,2} D_{1,3} \ldots D_{1,N}
D_{2,3} \ldots D_{2,N}
\vdots
D_{N-1,N}
出力
答えを整数として出力せよ。
入力例 1
4 1 5 4 7 8 6
出力例 1
13
頂点 1 と頂点 3 を結ぶ辺、頂点 2 と頂点 4 を結ぶ辺を選ぶと、辺の重みの総和が 5+8=13 となります。
これが達成可能な最大値であることが示せます。
入力例 2
3 1 2 3
出力例 2
3
N が奇数の場合もあります。
入力例 3
16 5 6 5 2 1 7 9 7 2 5 5 2 4 7 6 8 7 7 9 8 1 9 6 10 8 8 6 10 3 10 5 8 1 10 7 8 4 8 6 5 1 10 7 4 1 4 5 4 5 10 1 5 1 2 2 9 9 7 6 2 2 8 3 5 2 9 10 3 1 1 2 10 7 7 5 10 6 1 8 9 3 2 4 2 10 10 8 9 2 10 7 9 5 8 8 7 5 8 2 4 2 2 6 8 3 2 7 3 10 3 5 7 10 3 8 5 7 9 1 4
出力例 3
75
Score : 400 points
Problem Statement
You are given a weighted undirected complete graph with N vertices numbered from 1 to N. The edge connecting vertices i and j (i< j) has a weight of D_{i,j}.
When choosing some number of edges under the following condition, find the maximum possible total weight of the chosen edges.
- The endpoints of the chosen edges are pairwise distinct.
Constraints
- 2\leq N\leq 16
- 1\leq D_{i,j} \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
D_{1,2} D_{1,3} \ldots D_{1,N}
D_{2,3} \ldots D_{2,N}
\vdots
D_{N-1,N}
Output
Print the answer as an integer.
Sample Input 1
4 1 5 4 7 8 6
Sample Output 1
13
If you choose the edge connecting vertices 1 and 3, and the edge connecting vertices 2 and 4, the total weight of the edges is 5+8=13.
It can be shown that this is the maximum achievable value.
Sample Input 2
3 1 2 3
Sample Output 2
3
N can be odd.
Sample Input 3
16 5 6 5 2 1 7 9 7 2 5 5 2 4 7 6 8 7 7 9 8 1 9 6 10 8 8 6 10 3 10 5 8 1 10 7 8 4 8 6 5 1 10 7 4 1 4 5 4 5 10 1 5 1 2 2 9 9 7 6 2 2 8 3 5 2 9 10 3 1 1 2 10 7 7 5 10 6 1 8 9 3 2 4 2 10 10 8 9 2 10 7 9 5 8 8 7 5 8 2 4 2 2 6 8 3 2 7 3 10 3 5 7 10 3 8 5 7 9 1 4
Sample Output 3
75
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 425 点
問題文
正整数 N に対し、N が 400 number であることは以下の 2 つの条件をともに満たすことであると定義します。
- N の素因数はちょうど 2 種類である。
- N の各素因数 p について、N が p で割り切れる回数は偶数回である。より厳密には、N の各素因数 p について p^k が N の約数であるような最大の非負整数 k は偶数である。
Q 個のクエリが与えられるので、それぞれについて答えてください。各クエリでは、整数 A が与えられるので、A 以下の最大の 400 number の値を求めてください。ただし、本問題の制約下では A 以下の 400 number は常に存在します。
制約
- 1 \leq Q \leq 2 \times 10^5
- 各クエリについて、36 \leq A \leq 10^{12}
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
ここで、\text{query}_i は i 番目のクエリであり、以下の形式で与えられる。
A
出力
Q 行出力せよ。i 行目には i 番目のクエリに対する答えを出力せよ。
入力例 1
5 404 36 60 1000000000000 123456789
出力例 1
400 36 36 1000000000000 123454321
1 番目のクエリについて説明します。
400 の素因数は 2, 5 のちょうど 2 種類であり、400 が 2 で割り切れる回数は 4 回、5 で割り切れる回数は 2 回であるため 400 は 400 number です。401, 402, 403, 404 は 400 number ではないため答えは 400 となります。
Score : 425 points
Problem Statement
A positive integer N is a 400 number if and only if it satisfies both of the following two conditions:
- N has exactly 2 distinct prime factors.
- For each prime factor p of N, p divides N an even number of times. More formally, the maximum non-negative integer k such that p^k divides N is even.
Process Q queries. Each query gives you an integer A, so find the largest 400 number not exceeding A. Under the constraints of this problem, a 400 number not exceeding A always exists.
Constraints
- 1 \leq Q \leq 2 \times 10^5
- For each query, 36 \leq A \leq 10^{12}.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Q
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
Here, \text{query}_i is the i-th query, given in the following format:
A
Output
Print Q lines. The i-th line should contain the answer to the i-th query.
Sample Input 1
5 404 36 60 1000000000000 123456789
Sample Output 1
400 36 36 1000000000000 123454321
Let us explain the first query.
There are exactly 2 prime factors of 400: 2 and 5. Also, 2 divides 400 four times and 5 divides it twice, so 400 is a 400 number. None of 401, 402, 403, and 404 is a 400 number, so the answer is 400.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
H 行 W 列のグリッドがあります。 このグリッドの上から i\ (1\leq i\leq H) 行目、左から j\ (1\leq j\leq W) 列目のマスを (i,j) と表記します。
1 から N までの番号が付けられた N 個の横長のバーがグリッド上に置かれています。 バー i は 1\times 1 のブロックが横に L_i 個繋がった形をしており、その左端のブロックは最初マス (R_i,C_i) 上にあります。 すなわち、バー i は最初マス (R_i,C_i), (R_i,C_i+1), \dots, (R_i,C_i+L_i-1) を占めています。 ここで、相異なる 2 つのバーに占められているマスは存在しないことが保証されます。
現在の時刻は t=0 です。 非負整数 n を用いて t=0.5+n と表されるようなすべての時刻において、i=1,2,\dots,N の順に以下のことが起こります。
- バー i が一番下の行(H 行目)になく、かつバー i が占める各マスの 1 つ下のマスをどのバーも占めていない場合、バー i 全体が 1 マス分下に移動する。 すなわち、その時点でバー i が占めているマスが (r,C_i),(r,C_i+1),\dots,(r,C_i+L_i-1)\ (r < H) であり、どの j\ (0\leq j\leq L_i-1) についてもマス (r+1,C_i+j) を占めているバーが存在しないならば、 バー i の占めるマスが (r+1,C_i),(r+1,C_i+1),\dots,(r+1,C_i+L_i-1) に変化する。
- そうでないならば、何も起こらない。
t=10^{100} においてバー i が占めているマスを (R'_i,C_i), (R'_i,C_i+1), \dots, (R'_i,C_i+L_i-1) とします。 R'_1,R'_2,\dots,R'_N を求めてください。
制約
- 1\leq H,W \leq 2\times 10^5
- 1\leq N \leq 2\times 10^5
- 1\leq R_i\leq H
- 1\leq C_i\leq W
- 1\leq L_i\leq W-C_i+1
- 与えられる初期状態において、相異なる 2 つのバーに占められているマスは存在しない
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
H W N R_1 C_1 L_1 R_2 C_2 L_2 \vdots R_N C_N L_N
出力
N 行出力せよ。 i\ (1\leq i \leq N) 行目には、R'_i を出力せよ。
入力例 1
4 4 4 1 2 3 3 2 2 2 1 2 2 4 1
出力例 1
2 4 3 4
以下の 3 つの図は左から順に t=0,1,2 でのグリッドの様子を表しています。 色の塗られた長方形は各バーを表し、長方形の中に書かれた数字はそのバーの番号です。

グリッドの状態の変化は以下の通り説明されます。
- t=0.5:
- i=1: バー 1 が占める各マスの 1 つ下のマスである (2,2),(2,3),(2,4) のうち、(2,2) がバー 3 に、(2,4) がバー 4 にそれぞれ占められているため、何も起こらない。
- i=2: バー 2 が占める各マスの 1 つ下のマスである (4,2),(4,3) がいずれも他のバーに占められていないため、バー 2 全体が 1 マス分下に移動する。
- i=3: バー 3 が占める各マスの 1 つ下のマスである (3,1),(3,2) がいずれも他のバーに占められていないため、バー 3 全体が 1 マス分下に移動する。
- i=4: バー 4 が占めるマスの 1 つ下のマスである (3,4) が他のバーに占められていないため、バー 4 全体が 1 マス分下に移動する。
- t=1.5:
- i=1: バー 1 が占める各マスの 1 つ下のマスである (2,2),(2,3),(2,4) がいずれも他のバーに占められていないため、バー 1 全体が 1 マス分下に移動する。
- i=2: バー 2 は一番下の行にあるため、何も起こらない。
- i=3: バー 3 が占める各マスの 1 つ下のマスである (4,1),(4,2) のうち、(4,2) がバー 2 に占められているため、何も起こらない。
- i=4: バー 4 が占めるマスの 1 つ下のマスである (4,4) が他のバーに占められていないため、バー 4 全体が 1 マス分下に移動する。
t=2.5,3.5,\dots においては 1 つ下のマスがすべて空いているようなバーが存在せず、何も起こらないため、t=10^{100} でのグリッドの状態は t=2 でのグリッドの状態(上図における一番右の状態)と同じです。
よって、R'_1=2,R'_2=4,R'_3=3,R'_4=4 です。
入力例 2
382 382 3 3 3 3 8 8 8 2 2 2
出力例 2
382 382 381
入力例 3
5 10 8 2 2 1 4 3 1 4 8 2 1 2 2 2 5 3 5 4 3 4 5 2 1 5 2
出力例 3
5 5 5 4 3 5 4 2
Score: 525 points
Problem Statement
There is a grid with H rows and W columns. Let (i,j) denote the cell at the i-th row from the top and the j-th column from the left.
There are N horizontal bars numbered from 1 to N placed on the grid. Bar i consists of L_i blocks of size 1 \times 1 connected horizontally, and its leftmost block is initially at cell (R_i, C_i). That is, initially, bar i occupies the cells (R_i, C_i), (R_i, C_i + 1), \dots, (R_i, C_i + L_i - 1). It is guaranteed that there is no cell occupied by two different bars.
The current time is t = 0. At every time t = 0.5 + n for some non-negative integer n, the following occurs in order of i = 1, 2, \dots, N:
- If bar i is not on the bottom row (the H-th row), and none of the cells directly below the cells occupied by bar i is occupied by any bar, then bar i moves down by one cell. That is, if at that time bar i occupies the cells (r,C_i),(r,C_i+1),\dots,(r,C_i+L_i-1)\ (r < H), and the cell (r + 1, C_i + j) is not occupied by any bar for all j (0 \leq j \leq L_i - 1), then bar i now occupies (r + 1, C_i), (r + 1, C_i + 1), \dots, (r + 1, C_i + L_i - 1).
- Otherwise, nothing happens.
Let (R'_i, C_i), (R'_i, C_i + 1), \dots, (R'_i, C_i + L_i - 1) be the cells occupied by bar i at time t = 10^{100}. Find R'_1, R'_2, \dots, R'_N.
Constraints
- 1 \leq H, W \leq 2 \times 10^5
- 1 \leq N \leq 2 \times 10^5
- 1 \leq R_i \leq H
- 1 \leq C_i \leq W
- 1 \leq L_i \leq W - C_i + 1
- In the initial state, there is no cell occupied by two different bars.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
H W N R_1 C_1 L_1 R_2 C_2 L_2 \vdots R_N C_N L_N
Output
Print N lines. The i-th line (1 \leq i \leq N) should contain R'_i.
Sample Input 1
4 4 4 1 2 3 3 2 2 2 1 2 2 4 1
Sample Output 1
2 4 3 4
The following three diagrams represent the grid at times t = 0, 1, and 2 from left to right. Colored rectangles represent the bars, and the number inside each rectangle indicates its bar number.

The changes in the grid state are explained as follows:
- At t = 0.5:
- i = 1: The cells directly below bar 1 are (2,2),(2,3),(2,4). Among these, (2,2) is occupied by bar 3 and (2,4) is occupied by bar 4, so nothing happens.
- i = 2: The cells directly below bar 2 are (4,2),(4,3), which are not occupied by any other bar, so bar 2 moves down by one cell.
- i = 3: The cells directly below bar 3 are (3,1),(3,2), which are not occupied by any other bar, so bar 3 moves down by one cell.
- i = 4: The cell directly below bar 4 is (3,4), which is not occupied by any other bar, so bar 4 moves down by one cell.
- At t = 1.5:
- i = 1: The cells directly below bar 1 are (2,2),(2,3),(2,4), which are not occupied by any other bar, so bar 1 moves down by one cell.
- i = 2: Bar 2 is on the bottom row, so nothing happens.
- i = 3: The cells directly below bar 3 are (4,1),(4,2). Among these, (4,2) is occupied by bar 2, so nothing happens.
- i = 4: The cell directly below bar 4 is (4,4), which is not occupied by any other bar, so bar 4 moves down by one cell.
At times t = 2.5, 3.5, \dots, there is no bar such that the cells directly below it are all unoccupied, so nothing happens. Thus, the grid at time t = 10^{100} is the same as at t = 2 (the rightmost diagram above).
Therefore, R'_1 = 2, R'_2 = 4, R'_3 = 3, R'_4 = 4.
Sample Input 2
382 382 3 3 3 3 8 8 8 2 2 2
Sample Output 2
382 382 381
Sample Input 3
5 10 8 2 2 1 4 3 1 4 8 2 1 2 2 2 5 3 5 4 3 4 5 2 1 5 2
Sample Output 3
5 5 5 4 3 5 4 2