実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 266 点
問題文
高橋君は、大きな倉庫で荷物の検品作業を担当しています。倉庫には一直線上に N 個の棚が並んでおり、それぞれ 1 から N までの番号が順に付けられています。棚 i から棚 j への移動には |i - j| \times D 分かかります。ここで D は隣接する棚の間の移動にかかる時間(分)を表す正の整数です。
各棚には検品すべき荷物が置かれており、棚 i の荷物を検品するのにかかる時間は T_i 分です。検品は棚の前に立ち止まって行う必要があり、移動しながら検品することはできません。また、ある棚の検品を終えてから次の棚への移動を開始するものとし、検品と移動を同時に行うことはできません。移動の途中で他の棚の前を通過することがありますが、通過しただけでは検品したことにはなりません。検品するためには、改めてその棚へ移動して立ち止まる必要があります。
高橋君は最初、棚 S の前にいます。最初に検品する棚は自由に選ぶことができます。高橋君は棚 S の前から最初に検品する棚まで移動し、そこで検品を行います。棚 S を最初に検品する場合は移動時間 0 分で直ちに検品を開始できます。
高橋君は N 個すべての棚の荷物をちょうど 1 回ずつ検品しなければなりません。検品する棚の順序は自由に決めることができます。最後の棚の検品を終えた時点で作業は完了し、元の位置に戻る必要はありません。
すべての棚の荷物を検品し終えるまでの合計時間(すべての移動時間とすべての検品時間の合計)の最小値を求めてください。
制約
- 1 \leq N \leq 10^6
- 1 \leq D \leq 10^9
- 1 \leq S \leq N
- 1 \leq T_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数である。
入力
N D S T_1 T_2 \ldots T_N
- 1 行目には、棚の個数を表す整数 N 、隣接する棚の間の移動時間を表す整数 D 、開始位置の棚番号を表す整数 S が、スペース区切りで与えられる。
- 2 行目には、各棚の荷物を検品するのにかかる時間 T_1, T_2, \ldots, T_N が、スペース区切りで与えられる。
出力
すべての棚の荷物をちょうど 1 回ずつ検品するときの、合計時間(移動時間+検品時間)の最小値を 1 行で出力せよ。
入力例 1
4 2 2 3 1 4 2
出力例 1
18
入力例 2
5 3 5 2 8 1 6 4
出力例 2
33
入力例 3
12 5 6 7 2 9 4 6 3 8 5 1 10 2 7
出力例 3
144
入力例 4
30 100000000 17 12 999999999 345678901 1 500000000 234567890 876543210 111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 999999998 123456789 987654321 314159265 271828182 161803398 141421356 173205080 223606797 707106781 1000000000 42 424242424 606060606 808080808
出力例 4
18099415856
入力例 5
1 1000000000 1 1000000000
出力例 5
1000000000
Score : 266 pts
Problem Statement
Takahashi is in charge of inspecting goods in a large warehouse. In the warehouse, N shelves are lined up in a straight line, numbered 1 to N in order. Moving from shelf i to shelf j takes |i - j| \times D minutes, where D is a positive integer representing the travel time (in minutes) between adjacent shelves.
Each shelf has goods to be inspected, and inspecting the goods on shelf i takes T_i minutes. The inspection must be performed while standing in front of the shelf; it cannot be done while moving. Furthermore, Takahashi must start moving to the next shelf only after finishing the inspection of the current shelf; inspection and movement cannot be performed simultaneously. Although he may pass by other shelves during movement, merely passing by does not count as inspecting them. To inspect them, he must move to that shelf again and stop.
Takahashi is initially in front of shelf S. He can freely choose which shelf to inspect first. Takahashi moves from the front of shelf S to the first shelf to be inspected, and performs the inspection there. If he chooses to inspect shelf S first, he can start the inspection immediately with a travel time of 0 minutes.
Takahashi must inspect the goods on all N shelves exactly once. The order in which he inspects the shelves can be chosen freely. The work is complete once the inspection of the last shelf is finished, and he does not need to return to his starting position.
Find the minimum total time (the sum of all travel times and all inspection times) required to finish inspecting the goods on all shelves.
Constraints
- 1 \leq N \leq 10^6
- 1 \leq D \leq 10^9
- 1 \leq S \leq N
- 1 \leq T_i \leq 10^9 (1 \leq i \leq N)
- All input values are integers.
Input
N D S T_1 T_2 \ldots T_N
- The first line contains three space-separated integers: N, the number of shelves; D, the travel time between adjacent shelves; and S, the starting shelf number.
- The second line contains N space-separated integers T_1, T_2, \ldots, T_N, representing the time required to inspect the goods on each shelf.
Output
Print the minimum total time (travel time + inspection time) to inspect the goods on all shelves exactly once in a single line.
Sample Input 1
4 2 2 3 1 4 2
Sample Output 1
18
Sample Input 2
5 3 5 2 8 1 6 4
Sample Output 2
33
Sample Input 3
12 5 6 7 2 9 4 6 3 8 5 1 10 2 7
Sample Output 3
144
Sample Input 4
30 100000000 17 12 999999999 345678901 1 500000000 234567890 876543210 111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 999999998 123456789 987654321 314159265 271828182 161803398 141421356 173205080 223606797 707106781 1000000000 42 424242424 606060606 808080808
Sample Output 4
18099415856
Sample Input 5
1 1000000000 1 1000000000
Sample Output 5
1000000000
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
高橋君は N 個の鉢植えを一列に並べて育てています。左から順に 1, 2, \ldots, N と番号が付けられており、鉢植え i には現在 A_i ミリリットルの水が入っています。
夏の暑さにより、毎日すべての鉢植えから水が蒸発します。具体的には、 1 日が経過するごとに各鉢植えの水量が D ミリリットルずつ減少します(ただし、水量が 0 未満になることはなく、 0 で止まります)。
一方、いたずら好きの青木君は、高橋君の花壇を台無しにしようと企んでいます。青木君は毎日の始まりに 1 回だけ行動でき、任意の鉢植えを 1 つ選んでその鉢植えの水量を 0 にすることができます(水を捨てるいたずら)。青木君はこの行動を合計 K 回まで行えます。ただし、同じ鉢植えを複数回選ぶこともできます。青木君のいたずらは、その日の蒸発による減少が起こる前に実行されます。
高橋君は水を補充する手段を持っておらず、蒸発やいたずらを防ぐこともできません。 M 日後( M 日分の蒸発と青木君のいたずらがすべて終わった後)に、水量が 1 ミリリットル以上残っている鉢植えの数をできるだけ多く保ちたいと考えています。
青木君は高橋君にとって最悪の結果になるように最適に行動します。つまり、青木君は M 日後に水量が 1 以上の鉢植えの数を最小化するようにいたずらの対象を選びます。
青木君が最適に行動したとき、 M 日後に水量が 1 ミリリットル以上残っている鉢植えの数を求めてください。
制約
- 1 \leq N \leq 10^6
- 1 \leq M \leq 10^9
- 1 \leq D \leq 10^9
- 0 \leq K \leq N
- 0 \leq A_i \leq 10^{18}
- 入力はすべて整数である
入力
N M D K A_1 A_2 \ldots A_N
- 1 行目には、鉢植えの数 N 、経過日数 M 、 1 日あたりの蒸発量 D 、青木君のいたずら回数の上限 K が、スペース区切りで与えられる。
- 2 行目には、各鉢植えの初期水量 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
青木君が最適にいたずらを行ったとき、 M 日後に水量が 1 ミリリットル以上残っている鉢植えの数を 1 行で出力せよ。
入力例 1
5 3 2 1 1 5 6 7 10
出力例 1
1
入力例 2
4 2 3 0 0 5 6 7
出力例 2
1
入力例 3
12 10 7 3 0 1 69 70 71 100 150 35 80 500 70 72
出力例 3
3
入力例 4
40 123456789 98765 15 0 100 1000000000 5000000000 10000000000 12190000000000 12193209765584 12193209765585 12193209765586 15000000000000 20000000000000 999999999999999999 123456789012345678 42 7777777777777 8888888888888 9999999999999 11111111111111 22222222222222 33333333333333 44444444444444 55555555555555 66666666666666 77777777777777 88888888888888 99999999999999 314159265358979323 271828182845904523 1000000000000000000 999999999999999998 12193209765583 12193209765584 12193209765585 1 2 3 4 5 6 7
出力例 4
2
入力例 5
1 1 1 1 1000000000000000000
出力例 5
0
Score : 300 pts
Problem Statement
Takahashi is growing N potted plants arranged in a row. They are numbered 1, 2, \ldots, N from left to right, and plant i currently contains A_i milliliters of water.
Due to the summer heat, water evaporates from all potted plants every day. Specifically, as each day passes, the amount of water in each plant decreases by D milliliters (however, the amount of water will never drop below 0; it stops at 0).
Meanwhile, the mischievous Aoki is planning to ruin Takahashi's flowerbed. Aoki can perform an action at most once at the beginning of each day: he can choose any single potted plant and set its water amount to 0 (a prank of discarding the water). Aoki can perform this action up to K times in total. He may choose the same potted plant multiple times. Aoki's pranks are executed before the evaporation for that day occurs.
Takahashi has no way to refill the water, nor can he prevent evaporation or Aoki's pranks. He wants to keep the number of potted plants with at least 1 milliliter of water remaining after M days (after all M days of evaporation and Aoki's pranks are completed) as large as possible.
Aoki acts optimally to achieve the worst possible outcome for Takahashi. In other words, Aoki chooses the targets of his pranks to minimize the number of potted plants with at least 1 milliliter of water remaining after M days.
Find the number of potted plants with at least 1 milliliter of water remaining after M days, assuming Aoki acts optimally.
Constraints
- 1 \leq N \leq 10^6
- 1 \leq M \leq 10^9
- 1 \leq D \leq 10^9
- 0 \leq K \leq N
- 0 \leq A_i \leq 10^{18}
- All input values are integers.
Input
N M D K A_1 A_2 \ldots A_N
- The first line contains the number of potted plants N, the number of days M, the daily evaporation amount D, and the maximum number of Aoki's pranks K, separated by spaces.
- The second line contains the initial water amounts of the potted plants A_1, A_2, \ldots, A_N, separated by spaces.
Output
Print the number of potted plants with at least 1 milliliter of water remaining after M days, assuming Aoki acts optimally, in a single line.
Sample Input 1
5 3 2 1 1 5 6 7 10
Sample Output 1
1
Sample Input 2
4 2 3 0 0 5 6 7
Sample Output 2
1
Sample Input 3
12 10 7 3 0 1 69 70 71 100 150 35 80 500 70 72
Sample Output 3
3
Sample Input 4
40 123456789 98765 15 0 100 1000000000 5000000000 10000000000 12190000000000 12193209765584 12193209765585 12193209765586 15000000000000 20000000000000 999999999999999999 123456789012345678 42 7777777777777 8888888888888 9999999999999 11111111111111 22222222222222 33333333333333 44444444444444 55555555555555 66666666666666 77777777777777 88888888888888 99999999999999 314159265358979323 271828182845904523 1000000000000000000 999999999999999998 12193209765583 12193209765584 12193209765585 1 2 3 4 5 6 7
Sample Output 4
2
Sample Input 5
1 1 1 1 1000000000000000000
Sample Output 5
0
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 366 点
問題文
高橋君は、N 個の歯車が一列に並んだ装置を組み立てました。歯車には 1 から N まで順に番号が付けられており、隣り合う歯車 i と歯車 i+1(1 \leq i \leq N-1)は互いにかみ合っています。
各歯車 i(1 \leq i \leq N)には T_i 枚の歯があります。歯車 i と歯車 i+1 がかみ合っているとき、一方が回転すると他方も連動して回転します。かみ合う2つの歯車は同じ数だけ歯が進むため、歯車 i が1回転(T_i 歯分)する間に歯車 i+1 は \frac{T_i}{T_{i+1}} 回転します。すなわち、歯車 i の回転数と歯車 i+1 の回転数の比は T_{i+1} : T_i です(歯数が多い歯車ほどゆっくり回転します)。
各歯車にはちょうど 1 枚だけ印の付いた歯があります。歯車がちょうど正の整数回だけ回転すると、すべての歯は元の位置に戻るため、印の付いた歯も元の位置に戻ります。逆に、回転数が正の整数でなければ印は元の位置に戻りません。なお、隣り合う歯車は互いに逆方向に回転しますが、印が元の位置に戻るかどうかは回転の向きには依存せず、回転数のみで決まります。
歯車 1 を回すと、かみ合いにより歯車 2, 3, \ldots, N も連動して回転します。歯車 1 の回転数を R(R > 0)としたとき、すべての歯車の印が同時にそれぞれの元の位置に戻るような最小の正の R を求めてください。ここで回転数とは、回転した回数を表す正の実数であり、回転の向きによらない量です。
R は必ず正の有理数になることが証明できます。R を既約分数 \frac{P}{Q}(P, Q は正の整数、\gcd(P, Q) = 1)で表し、P と Q を / で区切って出力してください。R が整数の場合は P/1 の形式で出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq T_i \leq 10^9
- 入力はすべて整数である。
- 答えを既約分数 \frac{P}{Q} で表したとき、P, Q はともに 10^{18} 以下であることが保証される。
入力
N T_1 T_2 \ldots T_N
- 1 行目には、歯車の個数を表す整数 N が与えられる。
- 2 行目には、各歯車の歯の枚数を表す N 個の整数 T_1, T_2, \ldots, T_N がスペース区切りで与えられる。
出力
すべての歯車の印が同時にそれぞれの元の位置に戻るような歯車 1 の最小の正の回転数を既約分数で表したとき、分子 P と分母 Q を / で区切って 1 行で出力せよ。ただし、答えが整数の場合は P/1 の形式で出力せよ。
入力例 1
3 8 12 6
出力例 1
3/1
入力例 2
2 6 10
出力例 2
5/1
入力例 3
10 18 24 30 45 60 72 90 120 150 180
出力例 3
100/1
入力例 4
30 840 1260 1680 2100 2520 3150 3360 4200 5040 6300 6720 7560 8400 10080 12600 15120 16800 20160 25200 27720 30240 33600 37800 42000 50400 55440 60480 75600 83160 100800
出力例 4
19800/1
入力例 5
1 1000000000
出力例 5
1/1
Score : 366 pts
Problem Statement
Takahashi has assembled a device consisting of N gears arranged in a row. The gears are numbered from 1 to N in order, and adjacent gears i and i+1 (1 \leq i \leq N-1) mesh with each other.
Each gear i (1 \leq i \leq N) has T_i teeth. When gear i and gear i+1 are meshed, if one rotates, the other rotates accordingly. Since two meshing gears advance the same number of teeth, while gear i makes one full rotation (T_i teeth), gear i+1 rotates \frac{T_i}{T_{i+1}} times. In other words, the ratio of the number of rotations of gear i to gear i+1 is T_{i+1} : T_i (a gear with more teeth rotates more slowly).
Each gear has exactly one marked tooth. When a gear rotates exactly a positive integer number of times, all teeth return to their original positions, so the marked tooth also returns to its original position. Conversely, if the number of rotations is not a positive integer, the mark does not return to its original position. Note that adjacent gears rotate in opposite directions, but whether the mark returns to its original position depends only on the number of rotations, not on the direction of rotation.
When gear 1 is rotated, gears 2, 3, \ldots, N also rotate accordingly through the meshing. Let R (R > 0) be the number of rotations of gear 1. Find the smallest positive R such that the marks on all gears simultaneously return to their respective original positions. Here, the number of rotations is a positive real number representing how many times the gear has rotated, regardless of the direction of rotation.
It can be proven that R is always a positive rational number. Express R as an irreducible fraction \frac{P}{Q} (P, Q are positive integers, \gcd(P, Q) = 1), and output P and Q separated by /. If R is an integer, output it in the format P/1.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq T_i \leq 10^9
- All inputs are integers.
- It is guaranteed that when the answer is expressed as an irreducible fraction \frac{P}{Q}, both P and Q are at most 10^{18}.
Input
N T_1 T_2 \ldots T_N
- The first line contains an integer N representing the number of gears.
- The second line contains N integers T_1, T_2, \ldots, T_N separated by spaces, representing the number of teeth on each gear.
Output
Output the numerator P and denominator Q of the irreducible fraction representing the smallest positive number of rotations of gear 1 such that the marks on all gears simultaneously return to their respective original positions, separated by / on a single line. If the answer is an integer, output it in the format P/1.
Sample Input 1
3 8 12 6
Sample Output 1
3/1
Sample Input 2
2 6 10
Sample Output 2
5/1
Sample Input 3
10 18 24 30 45 60 72 90 120 150 180
Sample Output 3
100/1
Sample Input 4
30 840 1260 1680 2100 2520 3150 3360 4200 5040 6300 6720 7560 8400 10080 12600 15120 16800 20160 25200 27720 30240 33600 37800 42000 50400 55440 60480 75600 83160 100800
Sample Output 4
19800/1
Sample Input 5
1 1000000000
Sample Output 5
1/1
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 400 点
問題文
高橋君は果物屋を経営しています。
店には N 種類の果物がそれぞれ 1 個ずつあり、i 番目の果物(1 \leq i \leq N)には仕入れ値 C_i と売値 P_i が設定されています。高橋君はこの中からいくつかの果物を選んで本日のおすすめコーナーに並べたいと考えています。各果物は選ぶか選ばないかのいずれかであり、少なくとも 1 個は選ばなければなりません。
しかし、おすすめコーナーに並べる果物の価格帯があまりにもバラバラだと、お客さんが混乱してしまいます。そこで、選んだ果物の売値の最大値と最小値の差が D 以下でなければなりません。ここで D は入力で与えられる非負整数です。なお、果物を 1 個だけ選んだ場合、売値の最大値と最小値は等しいため差は 0 となり、この条件を必ず満たします。
各果物の利益は、売値から仕入れ値を引いた値 P_i - C_i で定まります。利益は負になることもあります。
高橋君は、上の条件を満たすように果物を選んだとき、選んだ果物の利益の合計を最大化したいと考えています。すべての果物の利益が負であっても、少なくとも 1 個は選ばなければならないことに注意してください。
利益の合計の最大値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 0 \leq D \leq 10^9
- 1 \leq C_i \leq 10^9
- 1 \leq P_i \leq 10^9
- 入力はすべて整数である。
入力
N D C_1 P_1 C_2 P_2 \vdots C_N P_N
- 1 行目には、果物の種類数を表す整数 N と、売値の最大値と最小値の差の上限を表す整数 D が、スペース区切りで与えられる。
- 1 + i 行目(1 \leq i \leq N)には、i 番目の果物の仕入れ値 C_i と売値 P_i が、スペース区切りで与えられる。
出力
条件を満たすように 1 個以上の果物を選んだときの、利益の合計の最大値を 1 行で出力せよ。答えが負になる場合もあることに注意せよ。
入力例 1
4 3 3 5 4 7 10 9 2 12
出力例 1
10
入力例 2
3 10 10 5 8 6 20 13
出力例 2
-2
入力例 3
10 5 8 10 5 12 20 15 1 17 9 20 25 22 7 23 30 26 10 27 15 30
出力例 3
33
入力例 4
25 100 1000 500 100 550 200 610 800 650 300 700 900 720 150 760 500 790 400 810 1200 850 350 900 600 940 100 980 1100 1020 700 1050 200 1100 1300 1150 250 1190 800 1230 300 1280 900 1320 100 1360 1500 1400 500 1450 200 1500
出力例 4
2660
入力例 5
1 0 1000000000 1
出力例 5
-999999999
Score : 400 pts
Problem Statement
Takahashi runs a fruit shop.
The shop has N types of fruits, one of each, and the i-th fruit (1 \leq i \leq N) has a cost price C_i and a selling price P_i. Takahashi wants to select some of these fruits to display in today's recommended section. Each fruit is either selected or not selected, and at least 1 fruit must be selected.
However, if the price range of the fruits displayed in the recommended section varies too much, customers will be confused. Therefore, the difference between the maximum and minimum selling prices among the selected fruits must be at most D, where D is a non-negative integer given in the input. Note that if only 1 fruit is selected, the maximum and minimum selling prices are equal, so the difference is 0, and this condition is always satisfied.
The profit of each fruit is determined by the selling price minus the cost price, P_i - C_i. The profit can be negative.
Takahashi wants to maximize the total profit of the selected fruits while satisfying the above condition. Note that even if the profit of every fruit is negative, at least 1 fruit must be selected.
Find the maximum total profit.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 0 \leq D \leq 10^9
- 1 \leq C_i \leq 10^9
- 1 \leq P_i \leq 10^9
- All inputs are integers.
Input
N D C_1 P_1 C_2 P_2 \vdots C_N P_N
- The first line contains an integer N representing the number of types of fruits and an integer D representing the upper limit of the difference between the maximum and minimum selling prices, separated by a space.
- The (1 + i)-th line (1 \leq i \leq N) contains the cost price C_i and selling price P_i of the i-th fruit, separated by a space.
Output
Print in one line the maximum total profit when selecting 1 or more fruits while satisfying the condition. Note that the answer may be negative.
Sample Input 1
4 3 3 5 4 7 10 9 2 12
Sample Output 1
10
Sample Input 2
3 10 10 5 8 6 20 13
Sample Output 2
-2
Sample Input 3
10 5 8 10 5 12 20 15 1 17 9 20 25 22 7 23 30 26 10 27 15 30
Sample Output 3
33
Sample Input 4
25 100 1000 500 100 550 200 610 800 650 300 700 900 720 150 760 500 790 400 810 1200 850 350 900 600 940 100 980 1100 1020 700 1050 200 1100 1300 1150 250 1190 800 1230 300 1280 900 1320 100 1360 1500 1400 500 1450 200 1500
Sample Output 4
2660
Sample Input 5
1 0 1000000000 1
Sample Output 5
-999999999
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 466 点
問題文
高橋君は N 台の送信機を管理しています。それぞれの送信機には 1 から N までの番号がついています。
各送信機 i には2つの動作モードがあり、モード A では信号値 V_i を、モード B では信号値 W_i を出力します。ここで V_i , W_i はいずれも 0 以上の整数です。高橋君は最初に各送信機の動作モードを A か B のどちらかに設定します。一度設定したモードは以降変更できません。
送信機のうちいくつかを同時に稼働させると、それらの出力信号値の XOR(排他的論理和)が合成信号として得られます。稼働させる送信機の集合は自由に選べ、空集合を選んだ場合の合成信号は 0 とします。
高橋君は M 個の目標信号値 T_1, T_2, \ldots, T_M を持っています。高橋君は以下の手順で運用を行います:
- まず、各送信機の動作モードを A か B のどちらかに決定する(この決定は一度だけ行い、以降変更しない)。
- その後、 M 個の目標信号値それぞれについて、稼働させる送信機の部分集合を選び、その部分集合の合成信号が目標信号値と一致するようにする。目標信号値ごとに稼働させる部分集合は異なってよい。
高橋君は、 M 個の目標信号値の すべて を実現できるようにしたいです。すなわち、ステップ1で動作モードを適切に決めた上で、すべての目標信号値 T_j ( 1 \leq j \leq M ) に対して、合成信号がその値と一致するような送信機の部分集合が存在するようにしたいです。
このような動作モードの決定方法(各送信機が A か B かの 2^N 通りの割り当て)のうち、条件を満たすものの数を 10^9 + 7 で割った余りを求めてください。
制約
- 1 \leq N \leq 15
- 1 \leq M \leq 100
- 0 \leq V_i \leq 2^{60} - 1 ( 1 \leq i \leq N )
- 0 \leq W_i \leq 2^{60} - 1 ( 1 \leq i \leq N )
- 0 \leq T_j \leq 2^{60} - 1 ( 1 \leq j \leq M )
- 入力はすべて整数である。
入力
N M V_1 W_1 V_2 W_2 : V_N W_N T_1 T_2 \ldots T_M
- 1 行目には、送信機の数を表す N 、目標信号値の数を表す M が、スペース区切りで与えられる。
- 2 行目から N + 1 行目では、各送信機の信号値が与えられる。
- 1 + i 行目では、送信機 i のモード A での信号値 V_i とモード B での信号値 W_i が、スペース区切りで与えられる。
- N + 2 行目には、 M 個の目標信号値 T_1, T_2, \ldots, T_M がスペース区切りで与えられる。
出力
条件を満たす動作モードの決定方法の数を 10^9 + 7 で割った余りを 1 行で出力せよ。
入力例 1
2 2 1 2 2 3 1 3
出力例 1
3
入力例 2
1 2 1 2 1 3
出力例 2
0
入力例 3
8 12 5 9 3 6 10 12 7 1 15 8 4 14 2 11 13 0 0 1 2 3 5 8 13 21 31 6 10 15
出力例 3
0
入力例 4
15 25 1 1099511627776 2 1099511627777 4 281474976710656 8 281474976710664 16 1125899906842624 32 1125899906842656 64 72057594037927936 128 72057594037928064 256 1152921504606846975 512 1152921504606846463 1024 123456789012345 2048 98765432109876 4096 555555555555555 8192 333333333333333 16384 777777777777777 0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 1099511627776 281474976710656 1125899906842624 72057594037927936 1152921504606846975 123456789012345 98765432109876 555555555555555 777777777777777
出力例 4
0
入力例 5
1 1 0 1152921504606846975 0
出力例 5
2
Score : 466 pts
Problem Statement
Takahashi manages N transmitters. The transmitters are numbered from 1 to N.
Each transmitter i has two operating modes: in Mode A, it outputs a signal value V_i, and in Mode B, it outputs a signal value W_i. Here, both V_i and W_i are non-negative integers. Takahashi first sets the operating mode of each transmitter to either A or B. Once a mode is set, it cannot be changed afterwards.
If some of the transmitters are operated simultaneously, the XOR (bitwise exclusive OR) of their output signal values is obtained as the combined signal. The set of transmitters to operate can be chosen freely, and the combined signal when the empty set is chosen is 0.
Takahashi has M target signal values T_1, T_2, \ldots, T_M. He operates them according to the following procedure:
- First, decide the operating mode of each transmitter to be either A or B (this decision is made only once and cannot be changed afterwards).
- Then, for each of the M target signal values, choose a subset of transmitters to operate so that the combined signal of the subset matches the target signal value. The subset of transmitters to operate may differ for each target signal value.
Takahashi wants to be able to realize all M target signal values. That is, after appropriately deciding the operating modes in Step 1, he wants to ensure that for every target signal value T_j (1 \leq j \leq M), there exists a subset of transmitters whose combined signal is equal to that value.
Find the number of such operating mode decisions (among the 2^N possible assignments of A or B to each transmitter) that satisfy the condition, modulo 10^9 + 7.
Constraints
- 1 \leq N \leq 15
- 1 \leq M \leq 100
- 0 \leq V_i \leq 2^{60} - 1 (1 \leq i \leq N)
- 0 \leq W_i \leq 2^{60} - 1 (1 \leq i \leq N)
- 0 \leq T_j \leq 2^{60} - 1 (1 \leq j \leq M)
- All input values are integers.
Input
N M V_1 W_1 V_2 W_2 : V_N W_N T_1 T_2 \ldots T_M
- The first line contains N, the number of transmitters, and M, the number of target signal values, separated by a space.
- The next N lines, from the 2-nd to the (N + 1)-th line, give the signal values of each transmitter.
- The (1 + i)-th line contains V_i, the signal value of transmitter i in Mode A, and W_i, the signal value of transmitter i in Mode B, separated by a space.
- The (N + 2)-th line contains M target signal values T_1, T_2, \ldots, T_M separated by spaces.
Output
Print the number of valid operating mode decisions modulo 10^9 + 7 in a single line.
Sample Input 1
2 2 1 2 2 3 1 3
Sample Output 1
3
Sample Input 2
1 2 1 2 1 3
Sample Output 2
0
Sample Input 3
8 12 5 9 3 6 10 12 7 1 15 8 4 14 2 11 13 0 0 1 2 3 5 8 13 21 31 6 10 15
Sample Output 3
0
Sample Input 4
15 25 1 1099511627776 2 1099511627777 4 281474976710656 8 281474976710664 16 1125899906842624 32 1125899906842656 64 72057594037927936 128 72057594037928064 256 1152921504606846975 512 1152921504606846463 1024 123456789012345 2048 98765432109876 4096 555555555555555 8192 333333333333333 16384 777777777777777 0 1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 1099511627776 281474976710656 1125899906842624 72057594037927936 1152921504606846975 123456789012345 98765432109876 555555555555555 777777777777777
Sample Output 4
0
Sample Input 5
1 1 0 1152921504606846975 0
Sample Output 5
2