A - Square Inequality

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

整数 A, B, C が与えられます。
A^2 + B^2 < C^2 かを判定してください。

制約

  • 0 \le A \le 1000
  • 0 \le B \le 1000
  • 0 \le C \le 1000
  • A, B, C は整数である

入力

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

A B C

出力

A^2 + B^2 < C^2 なら Yes を、そうでないなら No を出力せよ。


入力例 1

2 2 4

出力例 1

Yes

A^2 + B^2 = 2^2 + 2^2 = 8C^2 = 4^2 = 16 より A^2 + B^2 < C^2 なので Yes を出力します。


入力例 2

10 10 10

出力例 2

No

A^2 + B^2 = 200C^2 = 100 なので A^2 + B^2 < C^2 ではありません。


入力例 3

3 4 5

出力例 3

No

Score : 100 points

Problem Statement

You are given integers A, B, and C.
Determine whether A^2 + B^2 < C^2 holds.

Constraints

  • 0 \le A \le 1000
  • 0 \le B \le 1000
  • 0 \le C \le 1000
  • A, B, and C are integers.

Input

Input is given from Standard Input in the following format:

A B C

Output

If A^2 + B^2 < C^2 holds, print Yes; otherwise, print No.


Sample Input 1

2 2 4

Sample Output 1

Yes

Since A^2 + B^2 = 2^2 + 2^2 = 8 and C^2 = 4^2 = 16, we have A^2 + B^2 < C^2, so we should print Yes.


Sample Input 2

10 10 10

Sample Output 2

No

Since A^2 + B^2 = 200 and C^2 = 100, A^2 + B^2 < C^2 does not hold.


Sample Input 3

3 4 5

Sample Output 3

No
B - Intersection

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

長さ N の数列 A = (A_1, A_2, A_3, \dots, A_N), B = (B_1, B_2, B_3, \dots, B_N) が与えられます。
以下の条件を満たす整数 x の個数を求めてください。

  • 1 \le i \le N を満たす全ての整数 i について A_i \le x \le B_i

制約

  • 1 \le N \le 100
  • 1 \le A_i \le B_i \le 1000
  • 入力に含まれる値は全て整数

入力

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

N
A_1 A_2 A_3 \dots A_N
B_1 B_2 B_3 \dots B_N

出力

答えを出力せよ。


入力例 1

2
3 2
7 5

出力例 1

3

x3 \le x \le 72 \le x \le 5 の両方を満たさなければなりません。
そのような整数 x3, 4, 53 個あります。


入力例 2

3
1 5 3
10 7 3

出力例 2

0

条件を満たす整数 x が存在しないこともあります。


入力例 3

3
3 2 5
6 9 8

出力例 3

2

Score : 200 points

Problem Statement

You are given sequences of length N each: A = (A_1, A_2, A_3, \dots, A_N) and B = (B_1, B_2, B_3, \dots, B_N).
Find the number of integers x satisfying the following condition:

  • A_i \le x \le B_i holds for every integer i such that 1 \le i \le N.

Constraints

  • 1 \le N \le 100
  • 1 \le A_i \le B_i \le 1000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 A_3 \dots A_N
B_1 B_2 B_3 \dots B_N

Output

Print the answer.


Sample Input 1

2
3 2
7 5

Sample Output 1

3

x must satisfy both 3 \le x \le 7 and 2 \le x \le 5.
There are three such integers: 3, 4, and 5.


Sample Input 2

3
1 5 3
10 7 3

Sample Output 2

0

There may be no integer x satisfying the condition.


Sample Input 3

3
3 2 5
6 9 8

Sample Output 3

2
C - IPFL

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

長さ 2N の文字列 S があります。
この文字列に対して Q 個のクエリが与えられます。i 番目のクエリでは 3 つの整数 T_i, A_i, B_i が与えられるので、以下の処理をします。

  • T_i = 1 のとき : SA_i 文字目と B_i 文字目を入れ替える
  • T_i = 2 のとき : S の前半 N 文字と後半 N 文字を入れ替える(A_i, B_i の値は用いない)
    例えば SFLIP のときにこのクエリを処理すると、SIPFL となる。

これら Q 個のクエリを与えられた順に全て処理した後の S を出力してください。

制約

  • 1 \le N \le 2 \times 10^5
  • S は長さ 2N の英大文字のみからなる文字列
  • 1 \le Q \le 3 \times 10^5
  • T_i1 または 2
  • T_i = 1 のとき、1 \le A_i \lt B_i \le 2N
  • T_i = 2 のとき、A_i = B_i = 0

入力

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

N
S
Q
T_1 A_1 B_1
T_2 A_2 B_2
T_3 A_3 B_3
\hspace{21pt} \vdots
T_Q A_Q B_Q

出力

クエリ処理後の S を出力せよ。


入力例 1

2
FLIP
2
2 0 0
1 1 4

出力例 1

LPFI

1 番目のクエリでは S の前半 N 文字と後半 N 文字を入れ替えるため、SIPFL となります。
2 番目のクエリでは S1 文字目と 4 文字目を入れ替えるため、SLPFI となります。


入力例 2

2
FLIP
6
1 1 3
2 0 0
1 1 2
1 2 3
2 0 0
1 1 4

出力例 2

ILPF

Score : 300 points

Problem Statement

We have a string S of length 2N.
You are given Q queries on this string.
In the i-th query, given three integers T_i, A_i, and B_i, do the following:

  • if T_i = 1: swap the A_i-th and B_i-th characters of S;
  • if T_i = 2: swap the first N characters and last N characters of S (the values A_i and B_i are not used).
    For example, if S is FLIP, this query makes it IPFL.

Print the string S after processing all Q queries in the order they are given.

Constraints

  • 1 \le N \le 2 \times 10^5
  • S is a string of length 2N consisting of uppercase English letters.
  • 1 \le Q \le 3 \times 10^5
  • T_i is 1 or 2.
  • If T_i = 1, 1 \le A_i \lt B_i \le 2N.
  • If T_i = 2, A_i = B_i = 0.

Input

Input is given from Standard Input in the following format:

N
S
Q
T_1 A_1 B_1
T_2 A_2 B_2
T_3 A_3 B_3
\hspace{21pt} \vdots
T_Q A_Q B_Q

Output

Print the string S after processing the queries.


Sample Input 1

2
FLIP
2
2 0 0
1 1 4

Sample Output 1

LPFI

The 1-st query swaps the first N characters and last N characters of S, making it IPFL.
The 2-nd query swaps the 1-st and 4-th characters of S, making it LPFI.


Sample Input 2

2
FLIP
6
1 1 3
2 0 0
1 1 2
1 2 3
2 0 0
1 1 4

Sample Output 2

ILPF
D - RGB Coloring 2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

N 頂点 M 辺の単純無向グラフがあります。頂点には 1 から N までの、辺には 1 から M までの番号がついています。
i は頂点 A_i と頂点 B_i を結んでいます。
このグラフの各頂点を赤、緑、青の 3 色のいずれかで塗る方法であって、以下の条件を満たすものの数を求めてください。

  • 辺で直接結ばれている 2 頂点は必ず異なる色で塗られている

なお、使われない色があっても構いません。

制約

  • 1 \le N \le 20
  • 0 \le M \le \frac{N(N - 1)}{2}
  • 1 \le A_i \le N
  • 1 \le B_i \le N
  • 与えられるグラフは単純 (多重辺や自己ループを含まない)

入力

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

N M
A_1 B_1
A_2 B_2
A_3 B_3
\hspace{15pt} \vdots
A_M B_M

出力

答えを出力せよ。


入力例 1

3 3
1 2
2 3
3 1

出力例 1

6

頂点 1, 2, 3 の色をそれぞれ c_1, c_2, c_3 とし、赤、緑、青をそれぞれ R, G, B で表すと、以下の 6 通りが条件を満たします。

  • c_1c_2c_3 = RGB
  • c_1c_2c_3 = RBG
  • c_1c_2c_3 = GRB
  • c_1c_2c_3 = GBR
  • c_1c_2c_3 = BRG
  • c_1c_2c_3 = BGR

入力例 2

3 0

出力例 2

27

辺がないため、各頂点の色を自由に決めることができます。


入力例 3

4 6
1 2
2 3
3 4
2 4
1 3
1 4

出力例 3

0

条件を満たす塗り方が存在しない場合もあります。


入力例 4

20 0

出力例 4

3486784401

答えは 32 ビット符号付き整数型に収まらないことがあります。

Score : 400 points

Problem Statement

We have a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M.
Edge i connects Vertex A_i and Vertex B_i.
Find the number of ways to paint each vertex in this graph red, green, or blue so that the following condition is satisfied:

  • two vertices directly connected by an edge are always painted in different colors.

Here, it is not mandatory to use all the colors.

Constraints

  • 1 \le N \le 20
  • 0 \le M \le \frac{N(N - 1)}{2}
  • 1 \le A_i \le N
  • 1 \le B_i \le N
  • The given graph is simple (that is, has no multi-edges and no self-loops).

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
A_3 B_3
\hspace{15pt} \vdots
A_M B_M

Output

Print the answer.


Sample Input 1

3 3
1 2
2 3
3 1

Sample Output 1

6

Let c_1, c_2, c_3 be the colors of Vertices 1, 2, 3 and R, G, B denote red, green, blue, respectively. There are six ways to satisfy the condition:

  • c_1c_2c_3 = RGB
  • c_1c_2c_3 = RBG
  • c_1c_2c_3 = GRB
  • c_1c_2c_3 = GBR
  • c_1c_2c_3 = BRG
  • c_1c_2c_3 = BGR

Sample Input 2

3 0

Sample Output 2

27

Since the graph has no edge, we can freely choose the colors of the vertices.


Sample Input 3

4 6
1 2
2 3
3 4
2 4
1 3
1 4

Sample Output 3

0

There may be no way to satisfy the condition.


Sample Input 4

20 0

Sample Output 4

3486784401

The answer may not fit into the 32-bit signed integer type.

E - Permutation

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

(1, 2, 3, \dots, N) を並び替えてできる数列 a であって、以下の条件を満たすものの数を出力してください。

  • 1 \le i \le M を満たす全ての整数 i について、a_1, a_2, a_3, \dots, a_{X_i} の中に Y_i 以下の数は Z_i 個以下しか存在しない

制約

  • 2 \le N \le 18
  • 0 \le M \le 100
  • 1 \le X_i \lt N
  • 1 \le Y_i \lt N
  • 0 \le Z_i \lt N
  • 入力に含まれる値は全て整数である

入力

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

N M
X_1 Y_1 Z_1
X_2 Y_2 Z_2
X_3 Y_3 Z_3
\hspace{23pt} \vdots
X_M Y_M Z_M

出力

答えを出力せよ。


入力例 1

3 1
2 2 1

出力例 1

4

条件を満たす a は以下の 4 つです。

  • (1, 3, 2)
  • (2, 3, 1)
  • (3, 1, 2)
  • (3, 2, 1)

(1, 2, 3)(2, 1, 3) は、a_1, a_2 の中に 2 以下の数が 2 つあるため条件を満たしません。


入力例 2

5 2
3 3 2
4 4 3

出力例 2

90

入力例 3

18 0

出力例 3

6402373705728000

Score : 500 points

Problem Statement

Print the number of sequences a that are permutations of (1, 2, 3, \dots, N) and satisfy the following condition:

  • for every integer i such that 1 \le i \le M, at most Z_i numbers among a_1, a_2, a_3, \dots, a_{X_i} are less than or equal to Y_i .

Constraints

  • 2 \le N \le 18
  • 0 \le M \le 100
  • 1 \le X_i \lt N
  • 1 \le Y_i \lt N
  • 0 \le Z_i \lt N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
X_1 Y_1 Z_1
X_2 Y_2 Z_2
X_3 Y_3 Z_3
\hspace{23pt} \vdots
X_M Y_M Z_M

Output

Print the answer.


Sample Input 1

3 1
2 2 1

Sample Output 1

4

The four sequences a satisfying the condition are:

  • (1, 3, 2)
  • (2, 3, 1)
  • (3, 1, 2)
  • (3, 2, 1)

(1, 2, 3) and (2, 1, 3) violate the condition, since each of them has two numbers less than or equal to 2 among a_1, a_2.


Sample Input 2

5 2
3 3 2
4 4 3

Sample Output 2

90

Sample Input 3

18 0

Sample Output 3

6402373705728000
F - Graph Smoothing

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

N 頂点 M 辺の単純無向グラフがあります。頂点には 1 から N までの、辺には 1 から M までの番号がついています。
i は頂点 X_i と頂点 Y_i を結んでいます。また、頂点 i には最初整数 A_i が書かれています。
あなたは K 回にわたって以下の操作を行います。

  • M 本ある辺の中から、一様ランダムかつ他の選択と独立に 1 本選ぶ。その辺が結ぶ 2 頂点に書かれている数の平均を x として、その 2 頂点に書かれている数を両方 x で置き換える。

各頂点 i について、K 回の操作後に頂点 i に書かれている数の期待値を求め、注記の通り \bmod (10^9 + 7) で出力してください。

注記

有理数を出力する際は、まずその有理数を分数 \frac{y}{x} として表してください。
ここで、x,y は整数であり、x10^9+7 で割り切れてはなりません (この問題の制約下で、そのような表現は必ず可能です)。
そして、xz \equiv y \pmod {10^9+7} を満たすような 0 以上 10^9+6 以下の唯一の整数 z を出力してください。

制約

  • 2 \le N \le 100
  • 1 \le M \le \frac{N(N - 1)}{2}
  • 0 \le K \le 10^9
  • 0 \le A_i \le 10^9
  • 1 \le X_i \le N
  • 1 \le Y_i \le N
  • 与えられるグラフは単純
  • 入力に含まれる値は全て整数である

入力

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

N M K
A_1 A_2 A_3 \dots A_N
X_1 Y_1
X_2 Y_2
X_3 Y_3
\hspace{15pt} \vdots
X_M Y_M

出力

N 行にわたって出力せよ。
i 行目には、K 回の操作後に頂点 i に書かれている数の期待値を、注記に従って \bmod (10^9 + 7) で出力せよ。


入力例 1

3 2 1
3 1 5
1 2
1 3

出力例 1

3
500000005
500000008
  • 唯一の操作で辺 1 が選ばれた場合 : 頂点 1, 2, 3 に書かれている数はそれぞれ 2, 2, 5 となります
  • 唯一の操作で辺 2 が選ばれた場合 : 頂点 1, 2, 3 に書かれている数はそれぞれ 4, 1, 4 となります

従って、操作後に頂点 1, 2, 3 に書かれている数の期待値はそれぞれ 3, \frac{3}{2}, \frac{9}{2} となります。
これらを注記に従って \bmod (10^9 + 7) の表現に変換すると、それぞれ 3, 500000005, 500000008 となります。


入力例 2

3 2 2
12 48 36
1 2
1 3

出力例 2

750000036
36
250000031
  • 1 回目の操作で辺 1 が選ばれた場合
    頂点 1, 2, 3 に書かれている数はそれぞれ 30, 30, 36 となります
    • 2 回目の操作で辺 1 が選ばれた場合 : 頂点 1, 2, 3 に書かれている数はそれぞれ 30, 30, 36 となります
    • 2 回目の操作で辺 2 が選ばれた場合 : 頂点 1, 2, 3 に書かれている数はそれぞれ 33, 30, 33 となります
  • 1 回目の操作で辺 2 が選ばれた場合
    頂点 1, 2, 3 に書かれている数はそれぞれ 24, 48, 24 となります
    • 2 回目の操作で辺 1 が選ばれた場合 : 頂点 1, 2, 3 に書かれている数はそれぞれ 36, 36, 24 となります
    • 2 回目の操作で辺 2 が選ばれた場合 : 頂点 1, 2, 3 に書かれている数はそれぞれ 24, 48, 24 となります

これら 4 通りのケースが各 \frac{1}{4} の確率で起こるので、頂点 1, 2, 3 に最終的に書かれている数の期待値はそれぞれ \frac{123}{4}, \frac{144}{4} (=36), \frac{117}{4} となります。


入力例 3

4 5 1000
578 173 489 910
1 2
2 3
3 4
4 1
1 3

出力例 3

201113830
45921509
67803140
685163678

Score : 600 points

Problem Statement

We have a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N and the edges are numbered 1 through M.
Edge i connects Vertex X_i and Vertex Y_i. Initially, Vertex i has an integer A_i written on it.
You will do the following operation K times:

  • Choose one from the M edges uniformly at random and independently from other choices. Let x be the arithmetic mean of the numbers written on the two vertices connected by that edge. Replace each number written on those vertices with x.

For each vertex i, find the expected value of the number written on that vertex after K operations, and print it modulo (10^9 + 7) as described in Notes.

Notes

When printing a rational number, first, represent it as a fraction \frac{y}{x}, where x and y are integers and x is not divisible by (10^9+7) (under the Constraints of this problem, such a representation is always possible).
Then, print the only integer z between 0 and (10^9+6) (inclusive) such that xz \equiv y \pmod {10^9+7}.

Constraints

  • 2 \le N \le 100
  • 1 \le M \le \frac{N(N - 1)}{2}
  • 0 \le K \le 10^9
  • 0 \le A_i \le 10^9
  • 1 \le X_i \le N
  • 1 \le Y_i \le N
  • The given graph is simple.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 A_3 \dots A_N
X_1 Y_1
X_2 Y_2
X_3 Y_3
\hspace{15pt} \vdots
X_M Y_M

Output

Print N lines.
The i-th line should contain the expected value of the number written on that vertex after K operations, modulo (10^9 + 7), as described in Notes.


Sample Input 1

3 2 1
3 1 5
1 2
1 3

Sample Output 1

3
500000005
500000008
  • If Edge 1 is chosen in the only operation: the vertices written on Vertices 1, 2, 3 will be 2, 2, 5, respectively.
  • If Edge 2 is chosen in the only operation: the vertices written on Vertices 1, 2, 3 will be 4, 1, 4, respectively.

Thus, the expected values of the numbers written on Vertices 1, 2, 3 are 3, \frac{3}{2}, \frac{9}{2}, respectively.
If we express them modulo (10^9 + 7) as described in Notes, they will be 3, 500000005, 500000008, respectively.


Sample Input 2

3 2 2
12 48 36
1 2
1 3

Sample Output 2

750000036
36
250000031
  • If Edge 1 is chosen in the 1-st operation: The numbers written on Vertices 1, 2, 3 will be 30, 30, 36, respectively.
    • If Edge 1 is chosen in the 2-nd operation: The numbers written on Vertices 1, 2, 3 will be 30, 30, 36, respectively.
    • If Edge 2 is chosen in the 2-nd operation: The numbers written on Vertices 1, 2, 3 will be 33, 30, 33, respectively.
  • If Edge 2 is chosen in the 1-st operation: The numbers written on Vertices 1, 2, 3 will be 24, 48, 24, respectively.
    • If Edge 1 is chosen in the 2-nd operation: The numbers written on Vertices 1, 2, 3 will be 36, 36, 24, respectively.
    • If Edge 2 is chosen in the 2-nd operation: The numbers written on Vertices 1, 2, 3 will be 24, 48, 24, respectively.

Each of these four scenarios happen with probability \frac{1}{4}, so the expected values of the numbers written on Vertices 1, 2, 3 are \frac{123}{4}, \frac{144}{4} (=36), \frac{117}{4}, respectively.


Sample Input 3

4 5 1000
578 173 489 910
1 2
2 3
3 4
4 1
1 3

Sample Output 3

201113830
45921509
67803140
685163678