Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 1 ≤ N ≤ 100
- 1 ≤ p_i ≤ 100
Input Format
N p_1 p_2 ... p_N
Output Format
Sample Input 1
3 2 3 5
Sample Output 1
7
Sample Input 2
10 1 1 1 1 1 1 1 1 1 1
Sample Output 2
11
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
- 両方の山が空であれば、ゲームを終了する。
- 片方の山が空であれば、空でないほうの山の一番上のものをとる。
- 両方の山が空でなければ、好きなほうの山を選び、一番上のものをとる。
Constraints
- 1 ≤ A, B ≤ 1000
- 1 ≤ a_i, b_i ≤ 1000
Input Format
A B a_1 ...a_A b_1 ... b_B
Output Format
Sample Input 1
1 2 1 2 10
Sample Output 1
11
Sample Input 2
5 5 2 4 5 4 2 2 8 3 4 5
Sample Output 2
21
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
- 第 1 ラウンドでは、1 と 2、3 と 4、… が試合を行う。
- 第 2 ラウンドでは、(1 と 2 の勝者) と (3 と 4 の勝者), (5 と 6 の勝者) と (7 と 8 の勝者), … が試合を行う。
- 第 3 ラウンドでは、((1 と 2 の勝者) と (3 と 4 の勝者) の勝者) と ((5 と 6 の勝者) と (7 と 8 の勝者) の勝者), ((9 と 10 の勝者) と (11 と 12 の勝者) の勝者) と ((13 と 14 の勝者) と (15 と 16 の勝者) の勝者), … が試合を行う。
- 以下同様に第 K ラウンドまで行う。
ただし、Elo Rating R_P の人 P と Elo Rating R_Q の人 Q が対戦した場合、人 P が勝つ確率は 1 / (1 + 10^{(R_Q - R_P) / 400}) であり、異なる試合の勝敗は独立であるとする。
Constraints
- 1 ≤ K ≤ 10
- 0 ≤ R_i ≤ 4000
Input Format
K R_1 … R_{2^K}
Output Format
Sample Input 1
1 2200 2600
Sample Output 1
0.090909091 0.909090909
Sample Input 2
3 2000 2500 2300 2700 2100 2400 2600 2200
Sample Output 2
0.000086893 0.122042976 0.005522752 0.493464665 0.000651695 0.053982389 0.321828438 0.002420190
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 1 ≤ N ≤ 100
- 1 ≤ D ≤ 10^{18}
Input Format
N D
Output Format
Sample Input 1
2 6
Sample Output 1
0.416666667
Sample Input 2
3 2
Sample Output 2
0.875000000
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 1 ≤ N ≤ 10^{10000}
- 1 ≤ D ≤ 100
Input Format
D N
Output Format
Sample Input 1
3 100
Sample Output 1
33
Sample Input 2
7 123456789012345678901234567890
Sample Output 2
468357804
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
- 準急は、駅 1 に止まり、{駅 2, ..., 駅 N-1} の部分集合に止まり、駅 N に止まる。
- 連続する K個以上の駅に止まると、客が飽きてしまうので、そのようなことはしない。
Constraints
- 2 ≤ K ≤ N ≤ 1000000
Input Format
N K
Output Format
Sample Input 1
10 2
Sample Output 1
21
Sample Input 2
10 10
Sample Output 2
255
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
ただし、s から何文字か取り除き (0 文字でもよい)、残りの文字を順番を変えずにつなげたものを部分列という。たとえば、"aba" の部分列は "a", "b", "aa", "ab", "ba", "aba" の 6 個である。"a" は異なる場所に二回現れるが、文字列として同じであれば区別しないものとする。
Constraints
- 1 ≤ |s| ≤ 1000000
- Each character in s will be a lowercase letter ('a'-'z').
- 1 ≤ K ≤ 10^{18}
Input Format
s K
Output Format
Sample Input 1
eel 6
Sample Output 1
Eel
Sample Input 2
lexicographical 100
Sample Output 2
capal
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 1 ≤ N ≤100
- 1 ≤ W ≤10000
- 1 ≤ C ≤ 50
- 1 ≤ w_i, v_i ≤ 10000
- 1 ≤ c_i ≤ 50
Input Format
N W C w_1 v_1 c_1 … w_N v_N c_N
Output Format
Sample Input 1
4 5 2 1 10 1 1 20 2 1 30 3 10 100 4
Sample Output 1
50
Sample Input 2
10 20 2 4 5 6 3 3 9 5 2 9 4 1 6 6 8 3 3 7 6 2 4 9 4 7 3 6 5 6 3 2 9
Sample Output 2
27
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 1 ≤ |s| ≤ 300
- Each character in s will be either 'i' or 'w'.
Input Format
s
Output Format
Sample Input 1
iwiwii
Sample Output 1
2
Sample Input 2
iwiwwwiiiwiwiwiiwii
Sample Output 2
5
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
追記 : ボールを投げる場所は、前に投げたボールの飛んだ場所を見た後に決めることができる。
Constraints
- 1 ≤ N ≤ 16
- 0 ≤ x_i ≤ 15
- x_i are pairwise distinct.
Input Format
N x_1 ... x_N
Output Format
Sample Input 1
2 0 2
Sample Output 1
4.500000000
Sample Input 2
5 1 3 4 2 5
Sample Output 2
8.986111111
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 1 ≤ N ≤ 100000
- 0 ≤ x_i ≤ 100,000,000
- 1 ≤ r_i ≤ 100,000,000
Input Format
N x_1 r_1 … x_N r_N
Output Format
Sample Input 1
3 1 1 0 3 3 2
Sample Output 1
2
Sample Input 2
2 1 1 2 2
Sample Output 2
1
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 1 ≤ N ≤ 1000
- -1000 ≤ f_{i,j} ≤ 1000
- f_{i,i} = 0
- f_{i,j} = f_{j,i}
Input Format
N f_{1,1} ... f_{1,N} ... f_{N,1} ... f_{N,N}
Output Format
Sample Input 1
3 0 2 3 2 0 -10 3 -10 0
Sample Output 1
4
Sample Input 2
5 0 -3 5 2 -6 -3 0 6 -3 1 5 6 0 2 0 2 -3 2 0 4 -6 1 0 4 0
Sample Output 2
28
Time Limit: 8 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 2 ≤ H ≤ 1,000,000,000
- 1 ≤ R ≤ 16
- 0 ≤ g_{i,j} ≤ 1
- g_{i,i} = 0
- g_{i,j} = g_{j,i}
Input Format
H R g_{1,1} ... g_{1,R} ... g_{R.1} ... g_{R,R}
Output Format
Sample Input 1
10 2 0 1 1 0
Sample Output 1
512
Sample Input 2
2 5 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0
Sample Output 2
1025
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 2 ≤ N ≤ 1000
- 1 ≤ a_i, b_i ≤ N
- The input will represent a tree.
Input Format
N a_1 b_1 ... a_{N-1} b_{N-1}
Output Format
Sample Input 1
4 1 2 2 3 3 4
Sample Output 1
4
- 1-2 -> 2-3 -> 3-4
- 2-3 -> 1-2 -> 3-4
- 2-3 -> 3-4 -> 1-2
- 3-4 -> 2-3 -> 1-2
Sample Input 2
8 1 2 4 6 6 7 3 2 2 4 4 5 8 6
Sample Output 2
752
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
- a を freq_1 個、b を freq_2 個、... z を freq_{26} 個含む (他の文字は含まない)。
- 同じ文字が隣り合うことはない。
Constraints
- 0 ≤ freq_i ≤ 10
- At least one of freq_i will be nonzero.
Input Format
freq_1 ... freq_{26}
Output Format
Sample Input 1
1 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output 1
6
Sample Input 2
1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output 2
3628800
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
ただし、パスとは、異なる 二頂点間の木上での経路のことである。二つのパスは、共通の頂点を通らないとき disjoint であるという。また、パスを書く順番は区別しないものとする (たとえば、パス P-Q を書いた後にパス R-S を書くことも、パス S-R を書いた後にパス P-Q を書くことも同じであるとみなす。)
Constraints
- 2 ≤ N ≤ 1000
- 1 ≤ K ≤ 50
- 1 ≤ a_i, b_i ≤ N
- The input will represent a tree.
Input Format
N K a_1 b_1 ... a_{N-1} b_{N-1}
Output Format
Sample Input 1
4 1 1 2 2 3 3 4
Sample Output 1
6
Sample Input 2
8 3 1 2 4 6 6 7 3 2 2 4 4 5 8 6
Sample Output 2
9
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
Constraints
- 1 ≤ N ≤ 510
- 1 ≤ |w_i| ≤ 8
- 1 ≤ L ≤ 100
- Each character in w_i will be either '0' or '1'.
- w_i are pairwise distinct.
Input Format
N L w_1 ... w_N
Output Format
Sample Input 1
4 10 00 01 10 11
Sample Output 1
1024
Sample Input 2
3 5 01 10 0
Sample Output 2
14
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
- ある頂点を選び、その頂点から有向辺をたどっていくつかの頂点に訪れる。同じ頂点を複数回とおってもよい。
- 一回以上通った頂点をすべて黒く塗る。
Constraints
- 1 ≤ N ≤ 300
- 0 ≤ g_{i,j} ≤ 1
- g_{i,i} = 0
Input Format
N g_{1,1} ... g_{1,N} ... g_{N,1} ... g_{N,N}
Output Format
Sample Input 1
4 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0
Sample Output 1
3
Sample Input 2
6 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
Sample Output 2
6
Time Limit: 8 sec / Memory Limit: 256 MB
Problem Statement
- 左上のマス目と右下のマス目は黒に塗る。
- 左上のマス目から、黒いますを上下左右にたどって、右下のマス目に行くことができる。
Constraints
- 2 ≤ H ≤ 6
- 2 ≤ W ≤ 100
Input Format
H W
Output Format
Sample Input 1
2 2
Sample Output 1
3
Sample Input 2
5 8
Sample Output 2
950397139
Time Limit: 2 sec / Memory Limit: 256 MB
Problem Statement
- a_1 = a_2 = ... = a_K = 1
- a_i = a_{i-1} + ... + a_{i-K} (i > K)
Constraints
- 2 ≤ K ≤ 1000
- 1 ≤ N ≤ 10^9
Input Format
K N
Output Format
Sample Input 1
2 10
Sample Output 1
55
Sample Input 2
3 10
Sample Output 2
105