実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
正整数 D が与えられます。
非負整数 x,y に対する |x^2+y^2-D| の最小値を求めてください。
制約
- 1\leq D \leq 2\times 10^{12}
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
D
出力
答えを出力せよ。
入力例 1
21
出力例 1
1
x=4,y=2 のとき |x^2+y^2-D| = |16+4-21|=1 となります。
|x^2+y^2-D|=0 を満たすような非負整数 x,y は存在しないので、答えは 1 です。
入力例 2
998244353
出力例 2
0
入力例 3
264428617
出力例 3
32
Score : 300 points
Problem Statement
You are given a positive integer D.
Find the minimum value of |x^2+y^2-D| for non-negative integers x and y.
Constraints
- 1\leq D \leq 2\times 10^{12}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
D
Output
Print the answer.
Sample Input 1
21
Sample Output 1
1
For x=4 and y=2, we have |x^2+y^2-D| = |16+4-21|=1.
There are no non-negative integers x and y such that |x^2+y^2-D|=0, so the answer is 1.
Sample Input 2
998244353
Sample Output 2
0
Sample Input 3
264428617
Sample Output 3
32
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 250 点
問題文
9\times 9 のマス目 A があり、各マスには 1 以上 9 以下の整数が書き込まれています。
具体的には、 A の上から i 行目、左から j 列目のマスには A_{i,j} が書き込まれています。
A が次の条件をすべてみたしているならば Yes を、そうでないならば No を出力してください。
- A の各行について、その行に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
- A の各列について、その列に含まれる 9 マスには 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
- A の行を上から 3 行ずつ 3 つに分け、同様に列も左から 3 列ずつ 3 つに分ける。 これによって A を 9 つの 3\times 3 のマス目に分けたとき、それぞれの 3\times 3 のマス目には 1 以上 9 以下の整数がちょうど 1 個ずつ書き込まれている。
制約
- 1\leq A_{i,j}\leq 9
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A_{1,1} A_{1,2} \ldots A_{1,9}
A_{2,1} A_{2,2} \ldots A_{2,9}
\vdots
A_{9,1} A_{9,2} \ldots A_{9,9}
出力
マス目 A が問題文の条件をすべてみたすならば Yes を、
そうでないならば No を出力せよ。
入力例 1
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 4 5 6 7 8 9 1 5 6 7 8 9 1 2 3 4 8 9 1 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 6 7 8 9 1 2 3 4 5 9 1 2 3 4 5 6 7 8
出力例 1
Yes
マス目 A は次のようになっています。

マス目 A は 3 つの条件をすべてみたしているため、Yes を出力します。
入力例 2
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 1 3 4 5 6 7 8 9 1 2 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 4 5 7 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 7 9 1 2 3 4 5 6 7 8
出力例 2
No
マス目 A は次のようになっています。

例えば左上の 3\times 3 のマス目に注目すると 3 つめの条件をみたしていないことが分かるため、No を出力します。
入力例 3
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6
出力例 3
No
マス目 A は次のようになっています。

例えば一番左の列に注目すると 2 つめの条件をみたしていないことが分かるため、No を出力します。
Score : 250 points
Problem Statement
There is a 9\times 9 grid A, where each cell contains an integer between 1 and 9, inclusive.
Specifically, the cell at the i-th row from the top and j-th column from the left contains A_{i,j}.
If A satisfies all of the following conditions, print Yes. Otherwise, print No.
- For each row of A, the nine cells in that row contain each integer from 1 to 9 exactly once.
- For each column of A, the nine cells in that column contain each integer from 1 to 9 exactly once.
- Divide the rows of A into three groups, each of three rows, from top to bottom, and similarly divide the columns into three groups, each of three columns, from left to right. Each 3\times 3 grid obtained from A in this way contains each integer from 1 to 9 exactly once.
Constraints
- 1\leq A_{i,j}\leq 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A_{1,1} A_{1,2} \ldots A_{1,9}
A_{2,1} A_{2,2} \ldots A_{2,9}
\vdots
A_{9,1} A_{9,2} \ldots A_{9,9}
Output
If the grid A satisfies all the conditions in the problem statement, print Yes; otherwise, print No.
Sample Input 1
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 2 3 4 5 6 7 8 9 1 5 6 7 8 9 1 2 3 4 8 9 1 2 3 4 5 6 7 3 4 5 6 7 8 9 1 2 6 7 8 9 1 2 3 4 5 9 1 2 3 4 5 6 7 8
Sample Output 1
Yes
The grid A is shown below.

The grid A satisfies all three conditions, so print Yes.
Sample Input 2
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 1 3 4 5 6 7 8 9 1 2 4 5 6 7 8 9 1 2 3 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 4 5 7 8 9 1 2 3 4 5 6 8 9 1 2 3 4 5 6 7 9 1 2 3 4 5 6 7 8
Sample Output 2
No
The grid A is shown below.

For example, if you look at the top left 3\times 3 grid, you can see that the third condition is unsatisfied, so print No.
Sample Input 3
1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6
Sample Output 3
No
The grid A is shown below.

For example, if you look at the leftmost column, you can see that the second condition is unsatisfied, so print No.
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
2 次元平面上に N 個の相異なる点があり、1,2,\ldots ,N の番号がついています。点 i\,(1 \leq i \leq N) の座標は (x_i,y_i) です。
これらの点のうち 4 つを頂点とし、全ての辺が x 軸または y 軸に平行であるような長方形はいくつありますか?
制約
- 4 \leq N \leq 2000
- 0 \leq x_i, y_i \leq 10^9
- (x_i,y_i) \neq (x_j,y_j) (i \neq j)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N x_1 y_1 x_2 y_2 \vdots x_N y_N
出力
答えを出力せよ。
入力例 1
6 0 0 0 1 1 0 1 1 2 0 2 1
出力例 1
3
点 1 、点 2 、点 3 、点 4 を頂点とする長方形、
点 1 、点 2 、点 5 、点 6 を頂点とする長方形、
点 3 、点 4 、点 5 、点 6 を頂点とする長方形
の合計 3 つです。
入力例 2
4 0 1 1 2 2 3 3 4
出力例 2
0
入力例 3
7 0 1 1 0 2 0 2 1 2 2 3 0 3 2
出力例 3
1
Score : 400 points
Problem Statement
We have N distinct points on a two-dimensional plane, numbered 1,2,\ldots,N. Point i (1 \leq i \leq N) has the coordinates (x_i,y_i).
How many rectangles are there whose vertices are among the given points and whose edges are parallel to the x- or y-axis?
Constraints
- 4 \leq N \leq 2000
- 0 \leq x_i, y_i \leq 10^9
- (x_i,y_i) \neq (x_j,y_j) (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N x_1 y_1 x_2 y_2 \vdots x_N y_N
Output
Print the answer.
Sample Input 1
6 0 0 0 1 1 0 1 1 2 0 2 1
Sample Output 1
3
There are three such rectangles:
the rectangle whose vertices are Points 1, 2, 3, 4,
the rectangle whose vertices are Points 1, 2, 5, 6,
and the rectangle whose vertices are Points 3, 4, 5, 6.
Sample Input 2
4 0 1 1 2 2 3 3 4
Sample Output 2
0
Sample Input 3
7 0 1 1 0 2 0 2 1 2 2 3 0 3 2
Sample Output 3
1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
N 頂点 M 辺の無向グラフが与えられます。 頂点は頂点 1 ,頂点 2 , \ldots ,頂点 N、辺は辺 1 ,辺 2 , \ldots ,辺 M と番号付けられており、特に辺 i (1 \leq i \leq M) は頂点 U_i と頂点 V_i を結んでいます。 また、このグラフは単純であることが保証されます。すなわち、自己ループや多重辺は存在しません。
このグラフの M 本の辺すべてに向き付けをする方法は 2^M 通り考えられますが、 そのうち、どの頂点についても、その頂点から他の頂点に向かう辺がちょうど 1 本ずつ存在するような向き付けの方法は何通りありますか。 答えは非常に大きくなる可能性があるので、998244353 で割った余りを出力してください。
制約
- 2 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 1 \leq U_i,V_i \leq N
- U_i \neq V_i
- 入力は全て整数である。
- 与えられるグラフは単純である。
入力
入力は以下の形式で標準入力から与えられる。
N M U_1 V_1 U_2 V_2 \vdots U_M V_M
出力
答えを出力せよ。
入力例 1
3 3 1 2 1 3 2 3
出力例 1
2
条件をみたす辺の向き付けの方法は、
- 1\rightarrow 2 , 2\rightarrow 3 , 1\leftarrow 3
- 1\leftarrow 2 , 2\leftarrow 3 , 1\rightarrow 3
の 2 通りです。
入力例 2
2 1 1 2
出力例 2
0
すべての頂点から 1 本ずつ辺が出ているようにすることは明らかに不可能です。
入力例 3
7 7 1 2 2 3 3 4 4 2 5 6 6 7 7 5
出力例 3
4
Score : 500 points
Problem Statement
Given is an undirected graph with N vertices and M edges. The vertices are called Vertex 1, Vertex 2, \ldots, Vertex N, and the edges are called Edge 1, Edge 2, \ldots, Edge M. Edge i (1 \leq i \leq M) connects Vertex U_i and Vertex V_i. It is guaranteed that the graph is simple: it has no self-loops and no multi-edges.
There are 2^M ways to direct every edge in this graph. We want each vertex to have exactly one edge going from that vertex to another vertex. How many ways are there to direct the edges in that way? Since the answer may be enormous, print it modulo 998244353.
Constraints
- 2 \leq N \leq 2\times 10^5
- 1 \leq M \leq 2\times 10^5
- 1 \leq U_i,V_i \leq N
- U_i \neq V_i
- All values in input are integers.
- The given graph is simple.
Input
Input is given from Standard Input in the following format:
N M U_1 V_1 U_2 V_2 \vdots U_M V_M
Output
Print the answer.
Sample Input 1
3 3 1 2 1 3 2 3
Sample Output 1
2
There are two ways to direct the edges to achieve the objective:
- 1\rightarrow 2 , 2\rightarrow 3 , 1\leftarrow 3
- 1\leftarrow 2 , 2\leftarrow 3 , 1\rightarrow 3
Sample Input 2
2 1 1 2
Sample Output 2
0
It is obviously impossible to make every vertex have one edge going from that vertex.
Sample Input 3
7 7 1 2 2 3 3 4 4 2 5 6 6 7 7 5
Sample Output 3
4
実行時間制限: 4 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
高橋君は N 本の砂糖水を、青木君は M 本の砂糖水を持っています。
高橋君の持っている i 番目の砂糖水は砂糖 A_i グラムと水 B_i グラムからなります。
青木君の持っている i 番目の砂糖水は砂糖 C_i グラムと水 D_i グラムからなります。
2 人の持つ砂糖水をそれぞれ 1 本ずつ選んで混ぜる方法は NM 通りあります。そのような方法でできる砂糖水の中で、濃度が高い方から K 番目の砂糖水の濃度が何 \% であるかを求めてください。
ここで、砂糖 x グラムと水 y グラムからなる砂糖水の濃度は \dfrac{100x}{x+y}\ \% です。また、砂糖が溶け残ることは考えないものとします。
制約
- 1 \leq N, M \leq 5 \times 10^4
- 1 \leq K \leq N \times M
- 1 \leq A_i, B_i, C_i, D_i \leq 10^5
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M K A_1 B_1 A_2 B_2 \vdots A_N B_N C_1 D_1 C_2 D_2 \vdots C_M D_M
出力
濃度が高い方から K 番目の砂糖水の濃度をパーセントで出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{−9} 以下であれば正解として扱われる。
入力例 1
3 1 1 1 2 4 1 1 4 1 4
出力例 1
50.000000000000000
以下では高橋君が持っている i 番目の砂糖水と青木君が持っている j 番目の砂糖水を混ぜてできる砂糖水を (i, j) と表します。
あり得る砂糖水の混ぜ方とその濃度を列挙すると以下のようになります。
- (1, 1) : 100 \times \frac{1 + 1}{(1 + 1) + (2 + 4)} = 25 \%
- (2, 1) : 100 \times \frac{1 + 4}{(4 + 1) + (1 + 4)} = 50 \%
- (3, 1) : 100 \times \frac{1 + 1}{(1 + 1) + (4 + 4)} = 20 \%
この中で濃度が高い方から 1 番目の砂糖水は (2, 1) で、濃度は 50 \% です。
入力例 2
2 2 2 6 4 10 1 5 8 9 6
出力例 2
62.500000000000000
入力例 3
4 5 10 5 4 1 6 7 4 9 8 2 2 5 6 6 7 5 3 8 1
出力例 3
54.166666666666664
Score : 500 points
Problem Statement
Takahashi and Aoki have N and M bottles of sugar water, respectively.
Takahashi's i-th sugar water is composed of A_i grams of sugar and B_i grams of water.
Aoki's i-th sugar water is composed of C_i grams of sugar and D_i grams of water.
There are NM ways to choose one from Takahashi's sugar waters and one from Aoki's and mix them. Among the NM sugar waters that can be obtained in this way, find the concentration of sugar in the sugar water with the K-th highest concentration of sugar.
Here, the concentration of sugar in sugar water composed of x grams of sugar and y grams of water is \dfrac{100x}{x+y} percent. We will ignore saturation.
Constraints
- 1 \leq N, M \leq 5 \times 10^4
- 1 \leq K \leq N \times M
- 1 \leq A_i, B_i, C_i, D_i \leq 10^5
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M K A_1 B_1 A_2 B_2 \vdots A_N B_N C_1 D_1 C_2 D_2 \vdots C_M D_M
Output
Print the concentration of sugar in the sugar water with the K-th highest concentration of sugar in percent.
Your output will be considered correct if the absolute or relative error from the true value is at most 10^{−9}.
Sample Input 1
3 1 1 1 2 4 1 1 4 1 4
Sample Output 1
50.000000000000000
Let (i, j) denote the sugar water obtained by mixing Takahashi's i-th sugar water and Aoki's j-th.
Below are the sugar waters that can be obtained and their concentrations of sugar.
- (1, 1) : 100 \times \frac{1 + 1}{(1 + 1) + (2 + 4)} = 25 \%
- (2, 1) : 100 \times \frac{1 + 4}{(4 + 1) + (1 + 4)} = 50 \%
- (3, 1) : 100 \times \frac{1 + 1}{(1 + 1) + (4 + 4)} = 20 \%
Among them, the sugar water with the highest concentration of sugar is (2, 1), with a concentration of 50 percent.
Sample Input 2
2 2 2 6 4 10 1 5 8 9 6
Sample Output 2
62.500000000000000
Sample Input 3
4 5 10 5 4 1 6 7 4 9 8 2 2 5 6 6 7 5 3 8 1
Sample Output 3
54.166666666666664