C - log2(N)

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

正整数 N が与えられるので、 2^k \le N となる最大の整数 k を求めてください。

制約

  • N1 \le N \le 10^{18} を満たす整数である

入力

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

N

出力

答えを整数として出力せよ。


入力例 1

6

出力例 1

2
  • k=22^2=4 \le 6 を満たします。
  • k \ge 3 である全ての整数 k について 2^k > 6 となります。

以上より、答えは k=2 となります。


入力例 2

1

出力例 2

0

2^0=1 であることに注意してください。


入力例 3

1000000000000000000

出力例 3

59

入力が 32 bit 整数に収まらない場合があります。

Score : 200 points

Problem Statement

Given a positive integer N, find the maximum integer k such that 2^k \le N.

Constraints

  • N is an integer satisfying 1 \le N \le 10^{18}.

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

6

Sample Output 1

2
  • k=2 satisfies 2^2=4 \le 6.
  • For every integer k such that k \ge 3, 2^k > 6 holds.

Therefore, the answer is k=2.


Sample Input 2

1

Sample Output 2

0

Note that 2^0=1.


Sample Input 3

1000000000000000000

Sample Output 3

59

The input value may not fit into a 32-bit integer.

D - Seek Grid

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

N \times N のグリッド SM\times M のグリッド T が与えられます。上から i 行目、左から j 列目のマス目をマス (i,j) と表します。

S,T の各マスの色はそれぞれ N^2個の文字 S_{i,j} \; (1\leq i,j\leq N) および M^2 個の文字 T_{i,j} \; (1\leq i,j\leq M) によって表されます。 S_{i,j}. のとき S のマス (i,j) は白色、S_{i,j}# のとき S のマス (i,j) は黒色で塗られています。T についても同様です。

S の中から T を探してください。具体的には、以下の条件を満たす a,b \; (1 \leq a,b \leq N-M+1) を出力してください。

  • すべての i,j \; (1\leq i,j \leq M) について、S_{a+i-1,b+j-1} = T_{i,j}

制約

  • 1 \leq M \leq N \leq 50
  • N,M は整数
  • S_{i,j},T_{i,j}. または #
  • 条件を満たす a,b はちょうど 1 組存在する。

入力

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

N M
S_{1,1}S_{1,2}\dots S_{1,N}
S_{2,1}S_{2,2}\dots S_{2,N}
\vdots
S_{N,1}S_{N,2}\dots S_{N,N}
T_{1,1}T_{1,2}\dots T_{1,M}
T_{2,1}T_{2,2}\dots T_{2,M}
\vdots
T_{M,1}T_{M,2}\dots T_{M,M}

出力

a,b をこの順に空白区切りで 1 行に出力せよ。


入力例 1

3 2
#.#
..#
##.
.#
#.

出力例 1

2 2

S2 行目から 3 行目、2 列目から 3 列目の 2 \times 2 マスが T と一致します。


入力例 2

2 1
#.
##
.

出力例 2

1 2

Score : 200 points

Problem Statement

You are given an N \times N grid S and an M \times M grid T. The cell at the i-th row from the top and the j-th column from the left is denoted by (i,j).

The colors of the cells in S and T are represented by N^2 characters S_{i,j} (1\leq i,j\leq N) and M^2 characters T_{i,j} (1\leq i,j\leq M), respectively. In grid S, cell (i,j) is white if S_{i,j} is ., and black if S_{i,j} is #. The same applies for grid T.

Find T within S. More precisely, output integers a and b (1 \leq a,b \leq N-M+1) that satisfy the following condition:

  • S_{a+i-1,b+j-1} = T_{i,j} for every i,j (1\leq i,j \leq M).

Constraints

  • 1 \leq M \leq N \leq 50
  • N and M are integers.
  • Each of S_{i,j} and T_{i,j} is . or #.
  • There is exactly one pair (a,b) satisfying the condition.

Input

The input is given from Standard Input in the following format:

N M
S_{1,1}S_{1,2}\dots S_{1,N}
S_{2,1}S_{2,2}\dots S_{2,N}
\vdots
S_{N,1}S_{N,2}\dots S_{N,N}
T_{1,1}T_{1,2}\dots T_{1,M}
T_{2,1}T_{2,2}\dots T_{2,M}
\vdots
T_{M,1}T_{M,2}\dots T_{M,M}

Output

Print a and b in this order, separated by a space on one line.


Sample Input 1

3 2
#.#
..#
##.
.#
#.

Sample Output 1

2 2

The 2 \times 2 subgrid of S from the 2nd to the 3rd row and from the 2nd to the 3rd column matches T.


Sample Input 2

2 1
#.
##
.

Sample Output 2

1 2
E - Coverage

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

1 以上 N 以下の整数からなる集合が M 個あり、順に S_1, S_2, \dots, S_M と呼びます。
S_iC_i 個の整数 a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i} からなります。

M 個の集合から 1 個以上の集合を選ぶ方法は 2^M-1 通りあります。
このうち、次の条件を満たす選び方は何通りありますか?

  • 1 \leq x \leq N を満たす全ての整数 x に対して、選んだ集合の中に x を含む集合が少なくとも 1 個存在する。

制約

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • 1 \leq C_i \leq N
  • 1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N
  • 入力される値は全て整数

入力

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

N M
C_1
a_{1,1} a_{1,2} \dots a_{1,C_1}
C_2
a_{2,1} a_{2,2} \dots a_{2,C_2}
\vdots
C_M
a_{M,1} a_{M,2} \dots a_{M,C_M}

出力

問題文の条件を満たす集合の選び方の数を出力せよ。


入力例 1

3 3
2
1 2
2
1 3
1
2

出力例 1

3

入力で与えられている集合はそれぞれ S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace です。
問題文の条件を満たす集合の選び方は次の 3 通りです。

  • S_1, S_2 を選ぶ。
  • S_1, S_2, S_3 を選ぶ。
  • S_2, S_3 を選ぶ。

入力例 2

4 2
2
1 2
2
1 3

出力例 2

0

問題文の条件を満たす選び方が存在しない場合もあります。


入力例 3

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

出力例 3

18

Score : 300 points

Problem Statement

There are M sets, called S_1, S_2, \dots, S_M, consisting of integers between 1 and N.
S_i consists of C_i integers a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i}.

There are (2^M-1) ways to choose one or more sets from the M sets.
How many of them satisfy the following condition?

  • For all integers x such that 1 \leq x \leq N, there is at least one chosen set containing x.

Constraints

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • 1 \leq C_i \leq N
  • 1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

N M
C_1
a_{1,1} a_{1,2} \dots a_{1,C_1}
C_2
a_{2,1} a_{2,2} \dots a_{2,C_2}
\vdots
C_M
a_{M,1} a_{M,2} \dots a_{M,C_M}

Output

Print the number of ways to choose sets that satisfy the conditions in the Problem Statement.


Sample Input 1

3 3
2
1 2
2
1 3
1
2

Sample Output 1

3

The sets given in the input are S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace.
The following three ways satisfy the conditions in the Problem Statement:

  • choosing S_1, S_2;
  • choosing S_1, S_2, S_3;
  • choosing S_2, S_3.

Sample Input 2

4 2
2
1 2
2
1 3

Sample Output 2

0

There may be no way to choose sets that satisfies the conditions in the Problem Statement.


Sample Input 3

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

Sample Output 3

18
F - Minimum Glutton

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 250

問題文

N 個の料理があり、i 個目の料理の甘さA_iしょっぱさB_i です。

高橋君はこれらの N 個の料理を好きな順番で並べ、その順に食べようとします。

高橋君は並べた順番の通りに料理を食べていきますが、食べた料理の甘さの合計が X より大きくなるかしょっぱさの合計が Y より大きくなるとその時点で食べるのをやめます。

高橋君が食べることになる料理の個数としてあり得る最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq X, Y \leq 2 \times 10^{14}
  • 1 \leq A_i, B_i \leq 10^9
  • 入力される値はすべて整数

入力

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

N X Y
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

出力

答えを出力せよ。


入力例 1

4 7 18
2 3 5 1
8 8 1 4

出力例 1

2

i 個目の料理のことを料理 i と書きます。

高橋君が 4 個の料理を料理 2, 3, 1, 4 の順に並べ替えたとき、料理 2, 3 を食べた時点での食べた料理の甘さの合計が 8 となり 7 より大きくなります。したがってこの場合は高橋君が食べることになる料理の個数は 2 個です。

高橋君が食べる料理の個数が 1 個以下になることはないため、2 を出力します。


入力例 2

5 200000000000000 200000000000000
1 1 1 1 1
2 2 2 2 2

出力例 2

5

入力例 3

8 30 30
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1

出力例 3

6

Score : 250 points

Problem Statement

There are N dishes, and the i-th dish has a sweetness of A_i and a saltiness of B_i.

Takahashi plans to arrange these N dishes in any order he likes and eat them in that order.

He will eat the dishes in the arranged order, but he will stop eating as soon as the total sweetness of the dishes he has eaten exceeds X or the total saltiness exceeds Y.

Find the minimum possible number of dishes that he will end up eating.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq X, Y \leq 2 \times 10^{14}
  • 1 \leq A_i, B_i \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N X Y
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N

Output

Print the answer.


Sample Input 1

4 7 18
2 3 5 1
8 8 1 4

Sample Output 1

2

The i-th dish will be denoted as dish i.

If he arranges the four dishes in the order 2, 3, 1, 4, as soon as he eats dishes 2 and 3, their total sweetness is 8, which is greater than 7. Therefore, in this case, he will end up eating two dishes.

The number of dishes he will eat cannot be 1 or less, so print 2.


Sample Input 2

5 200000000000000 200000000000000
1 1 1 1 1
2 2 2 2 2

Sample Output 2

5

Sample Input 3

8 30 30
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1

Sample Output 3

6
G - Money in Hand

実行時間制限: 3 sec / メモリ制限: 1024 MiB

配点 : 400

問題文

高橋君は N 種類の硬貨をそれぞれ何枚か持っており、 具体的には、1\leq i\leq N について A_i 円硬貨を B_i 枚持っています。

高橋君が現在持っている硬貨を用いて、(お釣りが出ないように)ちょうど X 円を支払うことができるか判定してください。

制約

  • 1\leq N\leq 50
  • 1\leq X\leq 10^4
  • 1\leq A_i\leq 100
  • 1\leq B_i\leq 50
  • A_i はすべて異なる。
  • 入力はすべて整数

入力

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

N X
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

高橋君が現在持っている硬貨を用いてちょうど X 円を支払うことができる場合は Yes を、 できない場合は No を出力せよ。


入力例 1

2 19
2 3
5 6

出力例 1

Yes

高橋君は 2 円硬貨を 3 枚、5 円硬貨を 6 枚持っています。 このうち、2 円硬貨を 2 枚、5 円硬貨を 3 枚用いることでちょうど 2\times 2+5\times 3=19 円を支払うことができます。 よって、Yes を出力します。


入力例 2

2 18
2 3
5 6

出力例 2

No

持っている硬貨をどのように組み合わせてもちょうど 18 円を支払うことはできません。 よって、No を出力します。


入力例 3

3 1001
1 1
2 1
100 10

出力例 3

Yes

1 枚も使用しない硬貨が存在しても構いません。

Score : 400 points

Problem Statement

Takahashi has N kinds of coins; specifically, for 1\leq i\leq N, he has B_i coins worth A_i yen (the currency in Japan) each.

Determine if Takahashi can pay exactly X yen (without change) with the coins he currently has.

Constraints

  • 1\leq N\leq 50
  • 1\leq X\leq 10^4
  • 1\leq A_i\leq 100
  • 1\leq B_i\leq 50
  • A_i are pairwise distinct.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

N X
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print Yes if Takahashi can pay exactly X yen with the coins he currently has; print No otherwise.


Sample Input 1

2 19
2 3
5 6

Sample Output 1

Yes

Takahashi has three 2-yen coins and six 5-yen coins. He can use two 2-yen coins and three 5-yen coins to pay exactly 2\times 2+5\times 3=19 yen. Thus, Yes should be printed.


Sample Input 2

2 18
2 3
5 6

Sample Output 2

No

There is no combination of the coins that he can use to pay exactly 18 yen. Thus, No should be printed.


Sample Input 3

3 1001
1 1
2 1
100 10

Sample Output 3

Yes

He need not use all kinds of coins.