Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。
制約
- K は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22 のような指数表記や、 0523 のような先頭に不要な 0 を付けたような表記は許されない。
入力例 1
3
出力例 1
22
10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。
入力例 2
11
出力例 2
2022
入力例 3
923423423420220108
出力例 3
220022020000202020002022022000002020002222002200002022002200
たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。
Score : 300 points
Problem Statement
Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.
Constraints
- K is an integer between 1 and 10^{18} (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22, for example, or unnecessary leading zeros such as 0523 are not allowed.
Sample Input 1
3
Sample Output 1
22
The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.
Sample Input 2
11
Sample Output 2
2022
Sample Input 3
923423423420220108
Sample Output 3
220022020000202020002022022000002020002222002200002022002200
Note that the exact value of the answer must be printed as an integer, even if it is big.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
二次元平面があります。1 以上 9 以下の整数 r,c について、S_{r} の c 番目の文字が # であるとき座標 (r,c) にポーンが置いてあり、S_{r} の c 番目の文字が . であるとき座標 (r,c) に何も置かれていません。
この平面上の正方形であって、4 頂点全てにポーンが置いてあるものの個数を求めてください。
制約
- S_1,\ldots,S_9 はそれぞれ
#と.からなる長さ 9 の文字列
入力
入力は以下の形式で標準入力から与えられる。
S_1 S_2 \vdots S_9
出力
答えを出力せよ。
入力例 1
##....... ##....... ......... .......#. .....#... ........# ......#.. ......... .........
出力例 1
2
座標 (1,1),(1,2),(2,2),(2,1) を頂点とする正方形は、4 頂点全てにポーンが置かれています。
座標 (4,8),(5,6),(7,7),(6,9) を頂点とする正方形も、4 頂点全てにポーンが置かれています。
よって答えは 2 です。
入力例 2
.#....... #.#...... .#....... ......... ....#.#.# ......... ....#.#.# ........# .........
出力例 2
3
Score : 300 points
Problem Statement
There is a two-dimensional plane. For integers r and c between 1 and 9, there is a pawn at the coordinates (r,c) if the c-th character of S_{r} is #, and nothing if the c-th character of S_{r} is ..
Find the number of squares in this plane with pawns placed at all four vertices.
Constraints
- Each of S_1,\ldots,S_9 is a string of length 9 consisting of
#and..
Input
The input is given from Standard Input in the following format:
S_1 S_2 \vdots S_9
Output
Print the answer.
Sample Input 1
##....... ##....... ......... .......#. .....#... ........# ......#.. ......... .........
Sample Output 1
2
The square with vertices (1,1), (1,2), (2,2), and (2,1) have pawns placed at all four vertices.
The square with vertices (4,8), (5,6), (7,7), and (6,9) also have pawns placed at all four vertices.
Thus, the answer is 2.
Sample Input 2
.#....... #.#...... .#....... ......... ....#.#.# ......... ....#.#.# ........# .........
Sample Output 2
3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
N 個の頂点と M 本の辺からなる単純な(すなわち、自己ループも多重辺も含まない)無向グラフ G が与えられます。 i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i と頂点 v_i を結びます。
1 \leq u \lt v \leq N を満たす整数の組 (u, v) であって、下記の 2 つの条件をともに満たすものの個数を出力してください。
- グラフ G において、頂点 u と頂点 v を結ぶ辺は存在しない。
- グラフ G に、頂点 u と頂点 v を結ぶ辺を追加して得られるグラフは、二部グラフである。
二部グラフとは?
無向グラフが二部グラフであるとは、下記の条件を満たすように各頂点を黒または白のどちらかの色で塗ることができることを言います。
- 同じ色に塗られた頂点どうしを結ぶ辺は存在しない。
制約
- 2 \leq N \leq 2 \times 10^5
- 0 \leq M \leq \min \lbrace 2 \times 10^5, N(N-1)/2 \rbrace
- 1 \leq u_i, v_i \leq N
- グラフ G は単純
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N M u_1 v_1 u_2 v_2 \vdots u_M v_M
出力
答えを出力せよ。
入力例 1
5 4 4 2 3 1 5 2 3 2
出力例 1
2
問題文中の条件を満たす整数の組 (u, v) は、(1, 4) と (1, 5) の 2 つです。よって、2 を出力します。
他の組については、例えば、(1, 3) はグラフ G において頂点 1 と頂点 3 を結ぶ辺が存在することから、
(4, 5) はグラフ G に頂点 4 と頂点 5 を結ぶ辺を追加して得られるグラフが二部グラフではないことから、
それぞれ問題文中の条件を満たしません。
入力例 2
4 3 3 1 3 2 1 2
出力例 2
0
与えられるグラフが二部グラフであったり連結であるとは限らないことに注意してください。
入力例 3
9 11 4 9 9 1 8 2 8 3 9 2 8 4 6 7 4 6 7 5 4 5 7 8
出力例 3
9
Score : 400 points
Problem Statement
You are given a simple undirected graph G with N vertices and M edges (a simple graph does not contain self-loops or multi-edges). For i = 1, 2, \ldots, M, the i-th edge connects vertex u_i and vertex v_i.
Print the number of pairs of integers (u, v) that satisfy 1 \leq u \lt v \leq N and both of the following conditions.
- The graph G does not have an edge connecting vertex u and vertex v.
- Adding an edge connecting vertex u and vertex v in the graph G results in a bipartite graph.
What is a bipartite graph?
An undirected graph is said to be bipartite if and only if one can paint each vertex black or white to satisfy the following condition.
- No edge connects vertices painted in the same color.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 0 \leq M \leq \min \lbrace 2 \times 10^5, N(N-1)/2 \rbrace
- 1 \leq u_i, v_i \leq N
- The graph G is simple.
- All values in the input are integers.
Input
The 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
5 4 4 2 3 1 5 2 3 2
Sample Output 1
2
We have two pairs of integers (u, v) that satisfy the conditions in the problem statement: (1, 4) and (1, 5). Thus, you should print 2.
The other pairs do not satisfy the conditions. For instance, for (1, 3), the graph G has an edge connecting vertex 1 and vertex 3; for (4, 5), adding an edge connecting vertex 4 and vertex 5 in the graph G does not result in a bipartite graph.
Sample Input 2
4 3 3 1 3 2 1 2
Sample Output 2
0
Note that the given graph may not be bipartite or connected.
Sample Input 3
9 11 4 9 9 1 8 2 8 3 9 2 8 4 6 7 4 6 7 5 4 5 7 8
Sample Output 3
9
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 450 点
問題文
高橋君と青木君が二次元平面上を歩きます。
高橋君のスタート地点は (TS_X, TS_Y)、ゴール地点は (TG_X, TG_Y) です。 青木君のスタート地点は (AS_X, AS_Y)、ゴール地点は (AG_X, AG_Y) です。
二人は同時に各々のスタート地点を出発し、各々のゴール地点に向かって真っ直ぐ速さ 1 で歩き続け、各々のゴール地点に到達すると停止します。 (出発は同時ですが、停止するタイミングは同時とは限らないことに注意してください。)
二人の間の距離が最も短いタイミング(二人が出発する瞬間および停止した後を含む)における、二人の間の距離を求めてください。
ここで、距離はユークリッド距離を指すものとします。すなわち、2 点 (x_1,y_1),(x_2,y_2) の間の距離は \sqrt{(x_1-x_2)^2+(y_1-y_2)^2} として定められます。
T 個のテストケースが与えられるので、それぞれについて答えを求めてください。
制約
- 1\leq T\leq 2\times 10^5
- -100\leq TS_X,TS_Y,TG_X,TG_Y,AS_X,AS_Y,AG_X,AG_Y \leq 100
- (TS_X,TS_Y)\neq (TG_X,TG_Y)
- (AS_X,AS_Y)\neq (AG_X,AG_Y)
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
\text{case}_i は i 番目のテストケースを表す。各テストケースは以下の形式で与えられる。
TS_X TS_Y TG_X TG_Y AS_X AS_Y AG_X AG_Y
出力
T 行出力せよ。i 行目 (1\leq i\leq T) には i 番目のテストケースに対する答えを出力せよ。
出力は、真の値との絶対誤差または相対誤差が 10^{-6} 以下のとき、正解と判定される。
入力例 1
4 0 0 -2 2 -1 -1 4 4 4 0 2 0 6 0 8 0 1 0 1 1 -1 0 1 1 -8 9 2 6 -10 -10 17 20
出力例 1
1.000000000000000 2.000000000000000 0.000000000000000 1.783905950993199
1 番目のテストケースについて、二人が出発する時刻を 0 とおくと、二人の行動は以下のようになります。
- 時刻 0:高橋君が (0,0) を出発し、(-2,2) に向かって速さ 1 で歩き始める。同時に、青木君が (-1,-1) を出発し、(4,4) に向かって速さ 1 で歩き始める。
- 時刻 2\sqrt{2}:高橋君がゴール地点の (-2,2) に到達し、停止する。このとき、青木君は (1,1) におり、まだ歩き続けている。
- 時刻 5\sqrt{2}:青木君がゴール地点の (4,4) に到達し、停止する。
二人の間の距離が最も短いのは時刻 \frac{1}{\sqrt{2}} であり、このとき高橋君と青木君はそれぞれ (-\frac{1}{2},\frac{1}{2}), (-\frac{1}{2},-\frac{1}{2}) にいて、その距離は 1 です。
2 番目のテストケースについて、二人の間の距離が最も短いのは二人が出発する瞬間であり、そのときの距離は 2 です。
3 番目のテストケースについて、二人の間の距離が最も短いのは二人が共に停止した後であり、そのときの距離は 0 です。
Score : 450 points
Problem Statement
Takahashi and Aoki walk on a two-dimensional plane.
Takahashi's start point is (TS_X, TS_Y) and goal point is (TG_X, TG_Y). Aoki's start point is (AS_X, AS_Y) and goal point is (AG_X, AG_Y).
They simultaneously depart from their respective start points and walk straight toward their respective goal points at speed 1, and stop when they reach their respective goal points. (Note that they depart simultaneously, but they do not necessarily stop at the same time.)
Find the distance between them at the moment when the distance between them is shortest (including the moment they depart and after they stop).
Here, distance refers to Euclidean distance. That is, the distance between two points (x_1,y_1),(x_2,y_2) is defined as \sqrt{(x_1-x_2)^2+(y_1-y_2)^2}.
You are given T test cases, so solve each of them.
Constraints
- 1\leq T\leq 2\times 10^5
- -100\leq TS_X,TS_Y,TG_X,TG_Y,AS_X,AS_Y,AG_X,AG_Y \leq 100
- (TS_X,TS_Y)\neq (TG_X,TG_Y)
- (AS_X,AS_Y)\neq (AG_X,AG_Y)
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
\text{case}_i represents the i-th test case. Each test case is given in the following format:
TS_X TS_Y TG_X TG_Y AS_X AS_Y AG_X AG_Y
Output
Output T lines. The i-th line (1\leq i\leq T) should contain the answer for the i-th test case.
Your answer will be considered correct if the absolute or relative error from the true value is at most 10^{-6}.
Sample Input 1
4 0 0 -2 2 -1 -1 4 4 4 0 2 0 6 0 8 0 1 0 1 1 -1 0 1 1 -8 9 2 6 -10 -10 17 20
Sample Output 1
1.000000000000000 2.000000000000000 0.000000000000000 1.783905950993199
For the first test case, let time 0 be the moment they depart. Their behavior is as follows:
- Time 0: Takahashi departs from (0,0) and starts walking toward (-2,2) at speed 1. At the same time, Aoki departs from (-1,-1) and starts walking toward (4,4) at speed 1.
- Time 2\sqrt{2}: Takahashi reaches his goal point (-2,2) and stops. At this time, Aoki is at (1,1) and is still walking.
- Time 5\sqrt{2}: Aoki reaches his goal point (4,4) and stops.
The distance between them is shortest at time \frac{1}{\sqrt{2}}, when Takahashi and Aoki are at (-\frac{1}{2},\frac{1}{2}) and (-\frac{1}{2},-\frac{1}{2}) respectively, and the distance is 1.
For the second test case, the distance between them is shortest at the moment they depart, and the distance at that time is 2.
For the third test case, the distance between them is shortest after they both stop, and the distance at that time is 0.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 個のサイコロがあります。 i = 1, 2, \ldots, N について、i 番目のサイコロを振ると 1 以上 A_i 以下の整数の出目がそれぞれ等確率でランダムにでます。
N 個のサイコロすべてを同時に振るとき、その結果が下記の条件を満たす確率を \text{mod } 998244353 で求めてください。
N 個のサイコロの中からいくつか( N 個全部でも良い)を選ぶ方法であって、選んだサイコロの出目の和がちょうど 10 であるようなものが存在する。
確率 \text{mod } 998244353 の定義
この問題で求める確率は必ず有理数になることが証明できます。 また、この問題の制約下では、求める確率を既約分数 \frac{y}{x} で表したときに x が 998244353 で割り切れないことが保証されます。
このとき xz \equiv y \pmod{998244353} を満たすような 0 以上 998244352 以下の整数 z が一意に定まります。この z を答えてください。
制約
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^6
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 1 7 2 9
出力例 1
942786334
例えば、1, 2, 3, 4 個目のサイコロの出目が順に 1, 3, 2, 7 だった場合、この結果は問題文中の条件を満たします。 実際、2, 4 番目のサイコロを選択すると、選んだサイコロの出目の和が 3 + 7 = 10 になります。 また、1, 3, 4 番目のサイコロを選択しても、選んだサイコロの出目の和が 1 + 2 + 7 = 10 になります。
一方、1, 2, 3, 4 個目のサイコロの出目が順に 1, 6, 1, 5 だった場合、 どのようにサイコロを選んでも選んだサイコロの出目の和が 10 にならないため、この結果は問題文中の条件を満たしません。
この入力例では、N 個のサイコロを振った結果が問題文中の条件を満たす確率は \frac{11}{18} です。 よって、その \text{mod } 998244353 における値である 942786334 を出力します。
入力例 2
7 1 10 100 1000 10000 100000 1000000
出力例 2
996117877
Score : 500 points
Problem Statement
We have N dice. For each i = 1, 2, \ldots, N, when the i-th die is thrown, it shows a random integer between 1 and A_i, inclusive, with equal probability.
Find the probability, modulo 998244353, that the following condition is satisfied when the N dice are thrown simultaneously.
There is a way to choose some (possibly all) of the N dice so that the sum of their results is 10.
How to find a probability modulo 998244353
It can be proved that the sought probability is always a rational number. Additionally, the constraints of this problem guarantee that if the sought probability is represented as an irreducible fraction \frac{y}{x}, then x is not divisible by 998244353.
Here, there is a unique integer z such that xz \equiv y \pmod{998244353}. Report this z.
Constraints
- 1 \leq N \leq 100
- 1 \leq A_i \leq 10^6
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
4 1 7 2 9
Sample Output 1
942786334
For instance, if the first, second, third, and fourth dice show 1, 3, 2, and 7, respectively, these results satisfy the condition. In fact, if the second and fourth dice are chosen, the sum of their results is 3 + 7 = 10. Alternatively, if the first, third, and fourth dice are chosen, the sum of their results is 1 + 2 + 7 = 10.
On the other hand, if the first, second, third, and fourth dice show 1, 6, 1, and 5, respectively, there is no way to choose some of them so that the sum of their results is 10, so the condition is not satisfied.
In this sample input, the probability of the results of the N dice satisfying the condition is \frac{11}{18}. Thus, print this value modulo 998244353, that is, 942786334.
Sample Input 2
7 1 10 100 1000 10000 100000 1000000
Sample Output 2
996117877