Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君は、ある会社のネットワーク管理者です。彼は社内ネットワークのセキュリティ診断を行っています。
社内ネットワークは N 行 M 列のグリッド状に配置されたサーバールームで構成されています。各部屋にはサーバーが設置されているか、空き部屋になっています。サーバーが設置された部屋は # 、空き部屋は . で表されます。
サーバーが設置された部屋について、グリッド内に存在する上下左右に隣接する部屋のうち、サーバーが設置されている部屋の数を「隣接サーバー数」と呼びます。グリッドの外側には部屋は存在しないため、隣接サーバー数を数える際にはグリッドの外側は考慮しません。
隣接サーバー数が 0 のサーバーは孤立しており障害時の冗長性がなく、隣接サーバー数が 4 のサーバーは負荷が集中しすぎるため、いずれもセキュリティ上問題があるとされています。そこでセキュリティポリシーでは、以下の条件を定めています:
- すべてのサーバーについて、隣接サーバー数が 1 以上 3 以下である。
高橋君は現在のネットワーク配置図を渡され、この配置がセキュリティポリシーを満たしているかどうかを判定することになりました。
与えられたネットワーク配置がセキュリティポリシーの条件を満たしているかどうかを判定してください。なお、サーバーが 1 つも設置されていない場合は、条件に違反するサーバーが存在しないため、セキュリティポリシーを満たしているものとします。
制約
- 1 \leq N \leq 1000
- 1 \leq M \leq 1000
- S_i(1 \leq i \leq N)は
#と.のみからなる長さ M の文字列である
入力
N M S_1 S_2 \vdots S_N
- 1 行目には、グリッドの行数を表す整数 N と列数を表す整数 M が、スペース区切りで与えられる。
- 続く N 行のうち i 行目(1 \leq i \leq N)には、グリッドの上から i 行目の状態を表す長さ M の文字列 S_i が与えられる。各文字は
#(サーバー)または.(空き部屋)である。
出力
ネットワーク配置がセキュリティポリシーの条件を満たしている場合は Yes を、満たしていない場合は No を 1 行で出力せよ。
入力例 1
3 3 .#. ### .#.
出力例 1
No
入力例 2
4 5 ..... .#.#. .###. .....
出力例 2
Yes
入力例 3
5 8 ........ .##.###. .##.#.#. ....###. ........
出力例 3
Yes
Score : 266 pts
Problem Statement
Takahashi is a network administrator at a company. He is conducting a security assessment of the company's internal network.
The internal network consists of server rooms arranged in a grid of N rows and M columns. Each room either contains a server or is empty. A room with a server is represented by #, and an empty room is represented by ..
For each room containing a server, the number of adjacent rooms (up, down, left, right) within the grid that also contain servers is called the "adjacent server count". Since no rooms exist outside the grid, rooms outside the grid are not considered when counting adjacent servers.
A server with an adjacent server count of 0 is isolated and lacks redundancy in case of failure, while a server with an adjacent server count of 4 has too much load concentrated on it. Both cases are considered security risks. Therefore, the security policy defines the following condition:
- For every server, the adjacent server count must be at least 1 and at most 3.
Takahashi has been given the current network layout and must determine whether this layout satisfies the security policy.
Determine whether the given network layout satisfies the security policy condition. Note that if no servers are installed at all, there are no servers violating the condition, so the security policy is considered satisfied.
Constraints
- 1 \leq N \leq 1000
- 1 \leq M \leq 1000
- S_i (1 \leq i \leq N) is a string of length M consisting only of
#and.
Input
N M S_1 S_2 \vdots S_N
- The first line contains an integer N representing the number of rows and an integer M representing the number of columns of the grid, separated by a space.
- The following N lines each contain a string S_i of length M (1 \leq i \leq N), representing the state of the i-th row from the top of the grid. Each character is either
#(server) or.(empty room).
Output
If the network layout satisfies the security policy condition, output Yes; otherwise, output No, on a single line.
Sample Input 1
3 3 .#. ### .#.
Sample Output 1
No
Sample Input 2
4 5 ..... .#.#. .###. .....
Sample Output 2
Yes
Sample Input 3
5 8 ........ .##.###. .##.#.#. ....###. ........
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 333 点
問題文
高橋君はスーパーマーケットで N 個の商品を買おうとしています。j 番目の商品の定価は C_j 円です。高橋君は N 個の商品をすべて購入しなければなりません。
このスーパーでは、1回の会計での合計金額に応じてティア制の割引サービスを実施しています。ティアは 1 から K までの K 段階あり、各ティア i には適用下限金額 T_i 円と割引率 P_i %が設定されています。ティアの適用下限金額は T_1 < T_2 < \cdots < T_K を満たし、特に T_1 = 0 です。また、割引率は P_1 \leq P_2 \leq \cdots \leq P_K を満たします。
会計時の合計金額を X 円とします。X に適用されるティアは、T_i \leq X を満たす最大の i です。そのティアの割引率 P_i %が適用され、割引額は \lfloor X \times P_i / 100 \rfloor 円(小数点以下切り捨て)となります。したがって、スーパーでの支払金額は X - \lfloor X \times P_i / 100 \rfloor 円です。
高橋君はこのスーパーでの会計を1回だけ行います。レジに持っていく前に、カートから任意の商品を棚に戻すことができます。棚に戻した商品は別の店で定価のまま(割引なしで)購入します。
具体的には、高橋君は N 個の商品から部分集合 A(空集合でもよい)を選んでスーパーのレジに持っていきます。A に含まれる商品の定価の合計を X とすると、高橋君が支払う総額は以下の合計です:
- スーパーでの支払金額:X - \lfloor X \times P_i / 100 \rfloor 円(X に対応するティア i の割引率 P_i を適用)
- 別の店での支払金額:A に含まれない商品の定価の合計
高橋君が部分集合 A の選び方を最適にしたとき、支払う総額の最小値を求めてください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 2 \times 10^5
- 0 = T_1 < T_2 < \cdots < T_K \leq 2 \times 10^{14}
- 0 \leq P_1 \leq P_2 \leq \cdots \leq P_K \leq 100
- 1 \leq C_j \leq 10^9(1 \leq j \leq N)
- 入力はすべて整数
入力
入力は以下の形式で与えられる。
N K T_1 P_1 T_2 P_2 \ldots T_K P_K C_1 C_2 \ldots C_N
- 1 行目には、商品の個数 N とティアの段階数 K がスペース区切りで与えられる。
- 2 行目には、各ティアの適用下限金額 T_i と割引率 P_i の組が K 個、T_1, P_1, T_2, P_2, \ldots, T_K, P_K の順にスペース区切りで与えられる。
- 3 行目には、N 個の整数 C_1, C_2, \ldots, C_N がスペース区切りで与えられる。
出力
高橋君が支払う総額の最小値を1行で出力してください。
入力例 1
3 3 0 0 10 10 20 20 6 8 15
出力例 1
24
入力例 2
4 4 0 0 30 10 60 10 61 50 10 20 31 5
出力例 2
33
入力例 3
7 5 0 0 50 5 120 12 200 20 350 25 17 33 45 60 88 120 150
出力例 3
385
入力例 4
12 8 0 0 500000000 2 1000000000 3 2000000000 5 3000000000 7 4000000000 10 5500000000 15 200000000000000 17 999999999 850000000 760000000 640000000 530000000 470000000 390000000 310000000 280000000 220000000 150000000 90000000
出力例 4
4836500000
入力例 5
1 1 0 100 1000000000
出力例 5
0
Score : 333 pts
Problem Statement
Takahashi is trying to buy N items at a supermarket. The regular price of the j-th item is C_j yen. Takahashi must purchase all N items.
This supermarket offers a tiered discount service based on the total amount in a single checkout. There are K tiers, numbered from 1 to K. Each tier i has a minimum threshold amount T_i yen and a discount rate P_i%. The tier thresholds satisfy T_1 < T_2 < \cdots < T_K, and in particular T_1 = 0. The discount rates satisfy P_1 \leq P_2 \leq \cdots \leq P_K.
Let X yen be the total amount at checkout. The tier applied to X is the largest i such that T_i \leq X. The discount rate P_i% of that tier is applied, and the discount amount is \lfloor X \times P_i / 100 \rfloor yen (rounded down). Therefore, the payment at the supermarket is X - \lfloor X \times P_i / 100 \rfloor yen.
Takahashi will check out at this supermarket exactly once. Before going to the register, he can return any items from his cart to the shelves. Items returned to the shelves will be purchased at another store at their regular price (without any discount).
Specifically, Takahashi selects a subset A (possibly empty) of the N items to bring to the supermarket register. Let X be the sum of the regular prices of the items in A. The total amount Takahashi pays is the sum of:
- Payment at the supermarket: X - \lfloor X \times P_i / 100 \rfloor yen (applying the discount rate P_i of the tier i corresponding to X)
- Payment at the other store: the sum of the regular prices of the items not in A
Find the minimum total amount Takahashi pays when he optimally chooses the subset A.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 2 \times 10^5
- 0 = T_1 < T_2 < \cdots < T_K \leq 2 \times 10^{14}
- 0 \leq P_1 \leq P_2 \leq \cdots \leq P_K \leq 100
- 1 \leq C_j \leq 10^9 (1 \leq j \leq N)
- All inputs are integers
Input
The input is given in the following format.
N K T_1 P_1 T_2 P_2 \ldots T_K P_K C_1 C_2 \ldots C_N
- The first line contains the number of items N and the number of tiers K, separated by a space.
- The second line contains K pairs of the minimum threshold amount T_i and the discount rate P_i for each tier, given in the order T_1, P_1, T_2, P_2, \ldots, T_K, P_K, separated by spaces.
- The third line contains N integers C_1, C_2, \ldots, C_N, separated by spaces.
Output
Print the minimum total amount Takahashi pays, on a single line.
Sample Input 1
3 3 0 0 10 10 20 20 6 8 15
Sample Output 1
24
Sample Input 2
4 4 0 0 30 10 60 10 61 50 10 20 31 5
Sample Output 2
33
Sample Input 3
7 5 0 0 50 5 120 12 200 20 350 25 17 33 45 60 88 120 150
Sample Output 3
385
Sample Input 4
12 8 0 0 500000000 2 1000000000 3 2000000000 5 3000000000 7 4000000000 10 5500000000 15 200000000000000 17 999999999 850000000 760000000 640000000 530000000 470000000 390000000 310000000 280000000 220000000 150000000 90000000
Sample Output 4
4836500000
Sample Input 5
1 1 0 100 1000000000
Sample Output 5
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 366 点
問題文
数直線上で、高橋君と青木君が追いかけっこをします。青木君は正の方向へ逃げ、高橋君はそれを追いかけます。
二人の速さは N 秒周期で変化します。はじめに長さ N の速さの表が与えられ、その i 番目 (1 \leq i \leq N) には青木君の速さ A_i と高橋君の速さ B_i が定められています。
時刻は 0 から始まります。各非負整数 s について、時刻 s から時刻 s + 1 までの 1 秒間には、速さの表の i = (s \bmod N) + 1 番目が使われます。すなわち、この 1 秒間で青木君は A_i、高橋君は B_i だけ正の方向へ進みます。この対応は N 秒ごとに同じ順序で繰り返されます。
あなたは Q 個の指示を順に処理します。指示には次の 2 種類があります。
1 i a b:速さの表の i 番目を変更し、青木君の速さを a、高橋君の速さを b にする。2 d:現在の速さの表に基づき、以下の問いに答える。時刻 0 に高橋君が座標 0、青木君が座標 d にいるとして、高橋君が青木君に追い付く最小の非負整数時刻を求めよ。追い付けない場合は -1 を出力せよ。
ここで、追い付くとは、ある非負整数時刻 t において高橋君の座標が青木君の座標以上になることを意味します。判定は整数時刻のみで行い、二人の途中の位置は考慮しません。
各 2 の指示は独立であり、二人の位置は次の指示に引き継がれません。一方、1 の指示による速さの表の変更は、それ以降のすべての指示に引き継がれます。
制約
- 1 \leq N \leq 3000
- 1 \leq Q \leq 10^5
- NQ \leq 10^7
- 0 \leq A_i \leq 10^9
- 0 \leq B_i \leq 10^9
1の指示について:1 \leq i \leq N、0 \leq a \leq 10^9、0 \leq b \leq 10^92の指示について:1 \leq d \leq 10^{15}2の指示は 1 つ以上存在する- 入力はすべて整数である
入力
N Q A_1 B_1 A_2 B_2 \vdots A_N B_N query_1 query_2 \vdots query_Q
1 行目に周期 N と指示の個数 Q が与えられる。続く N 行の i 行目に A_i と B_i が与えられる。続く Q 行に指示が 1 i a b または 2 d の形式で与えられる。各行の値はスペース区切りである。
出力
各 2 の指示に対して、高橋君が青木君に追い付く最小の非負整数時刻を 1 行に出力してください。永遠に追い付けない場合は -1 を出力してください。
入力例 1
3 5 2 5 4 3 1 2 2 1 2 4 1 2 0 6 2 8 2 20
出力例 1
1 4 2 6
入力例 2
3 5 2 1 0 2 1 0 2 2 2 1 1 2 5 5 2 1 2 100
出力例 2
-1 2 -1 -1
入力例 3
8 14 5 8 7 4 3 6 10 2 0 5 4 4 6 9 2 1 2 3 2 10 1 4 1 12 2 15 1 8 5 20 2 30 1 2 10 10 2 7 2 100 1 5 8 0 2 12 1 4 0 0 2 25 2 1
出力例 3
1 33 5 8 4 21 4 16 1
入力例 4
20 30 100 150 80 60 0 200 300 100 50 50 20 70 90 30 10 110 400 0 0 0 15 45 60 90 120 80 5 205 700 900 1000 500 30 31 45 40 200 250 75 125 2 1000 2 100000 1 9 0 1000 2 5000 1 16 100 1000 2 20000 1 4 0 0 1 7 0 300 2 12345 2 999999999999999 1 1 1000 0 2 100 1 10 0 1000000000 2 1000000000 1 10 1000000000 0 2 1000000000 1 15 900 700 1 20 125 75 2 7777 2 42 1 2 0 0 1 3 500 100 2 314159 1 18 0 100 2 271828 1 5 0 0 2 1000000000000000 1 12 1000000000 1000000000 2 600 2 600000
出力例 4
-1 -1 89 156 80 6459948320415 9 10 -1 -1 9 -1 -1 -1 -1 -1
入力例 5
1 8 1000000000 0 2 1 1 1 0 0 2 1 1 1 0 1000000000 2 1000000000000000 2 1 1 1 1000000000 1000000000 2 1
出力例 5
-1 -1 1000000 1 -1
Score : 366 pts
Problem Statement
On a number line, Takahashi and Aoki are playing a game of chase. Aoki runs in the positive direction, and Takahashi chases after him.
Their speeds change with a period of N seconds. Initially, a speed table of length N is given, where the i-th entry (1 \leq i \leq N) specifies Aoki's speed A_i and Takahashi's speed B_i.
Time starts from 0. For each non-negative integer s, during the 1-second interval from time s to time s + 1, the i = (s \bmod N) + 1-th entry of the speed table is used. That is, during this 1 second, Aoki moves A_i and Takahashi moves B_i in the positive direction. This correspondence repeats in the same order every N seconds.
You process Q queries in order. There are two types of queries:
1 i a b: Change the i-th entry of the speed table so that Aoki's speed becomes a and Takahashi's speed becomes b.2 d: Based on the current speed table, answer the following question. Assuming that at time 0, Takahashi is at coordinate 0 and Aoki is at coordinate d, find the minimum non-negative integer time at which Takahashi catches up to Aoki. If he can never catch up, output -1.
Here, catching up means that at some non-negative integer time t, Takahashi's coordinate is greater than or equal to Aoki's coordinate. The check is performed only at integer times; the positions of the two in between are not considered.
Each 2 query is independent, and the positions of the two are not carried over to the next query. On the other hand, changes to the speed table made by 1 queries are carried over to all subsequent queries.
Constraints
- 1 \leq N \leq 3000
- 1 \leq Q \leq 10^5
- NQ \leq 10^7
- 0 \leq A_i \leq 10^9
- 0 \leq B_i \leq 10^9
- For
1queries: 1 \leq i \leq N, 0 \leq a \leq 10^9, 0 \leq b \leq 10^9 - For
2queries: 1 \leq d \leq 10^{15} - There is at least one
2query - All input values are integers
Input
N Q A_1 B_1 A_2 B_2 \vdots A_N B_N query_1 query_2 \vdots query_Q
The first line gives the period N and the number of queries Q. The following N lines give A_i and B_i on the i-th line. The following Q lines give queries in the format 1 i a b or 2 d. Values on each line are separated by spaces.
Output
For each 2 query, output on one line the minimum non-negative integer time at which Takahashi catches up to Aoki. If he can never catch up, output -1.
Sample Input 1
3 5 2 5 4 3 1 2 2 1 2 4 1 2 0 6 2 8 2 20
Sample Output 1
1 4 2 6
Sample Input 2
3 5 2 1 0 2 1 0 2 2 2 1 1 2 5 5 2 1 2 100
Sample Output 2
-1 2 -1 -1
Sample Input 3
8 14 5 8 7 4 3 6 10 2 0 5 4 4 6 9 2 1 2 3 2 10 1 4 1 12 2 15 1 8 5 20 2 30 1 2 10 10 2 7 2 100 1 5 8 0 2 12 1 4 0 0 2 25 2 1
Sample Output 3
1 33 5 8 4 21 4 16 1
Sample Input 4
20 30 100 150 80 60 0 200 300 100 50 50 20 70 90 30 10 110 400 0 0 0 15 45 60 90 120 80 5 205 700 900 1000 500 30 31 45 40 200 250 75 125 2 1000 2 100000 1 9 0 1000 2 5000 1 16 100 1000 2 20000 1 4 0 0 1 7 0 300 2 12345 2 999999999999999 1 1 1000 0 2 100 1 10 0 1000000000 2 1000000000 1 10 1000000000 0 2 1000000000 1 15 900 700 1 20 125 75 2 7777 2 42 1 2 0 0 1 3 500 100 2 314159 1 18 0 100 2 271828 1 5 0 0 2 1000000000000000 1 12 1000000000 1000000000 2 600 2 600000
Sample Output 4
-1 -1 89 156 80 6459948320415 9 10 -1 -1 9 -1 -1 -1 -1 -1
Sample Input 5
1 8 1000000000 0 2 1 1 1 0 0 2 1 1 1 0 1000000000 2 1000000000000000 2 1 1 1 1000000000 1000000000 2 1
Sample Output 5
-1 -1 1000000 1 -1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
高橋君は修学旅行の班長を務めています。班には高橋君を含めて N 人のメンバーがおり、高橋君はお土産屋で M 種類のお菓子を購入しました。i 番目の種類のお菓子は C_i 個あります。
高橋君はこれらのお菓子を班のメンバー全員(高橋君自身を含む N 人)に配ろうとしています。配り方のルールは以下の通りです:
- 各メンバーにはちょうど K 個のお菓子を配る。
- お菓子の各個体は 1 人のメンバーにのみ配ることができる。すなわち、i 番目の種類のお菓子は合計で C_i 個までしか配ることができない。
- 同じ種類のお菓子を同じメンバーに 2 個以上配ってはならない。すなわち、各メンバーが受け取る K 個のお菓子はすべて異なる種類でなければならない。ただし、異なるメンバーが同じ種類のお菓子をそれぞれ受け取ることは許される。
- お菓子を余らせても構わない。
すべてのメンバーにちょうど K 個ずつお菓子を配ることが可能かどうかを判定してください。可能であれば Yes を、不可能であれば No を出力してください。
制約
- 1 \leq N \leq 10^9
- 1 \leq M \leq 2 \times 10^5
- 1 \leq K \leq M
- 1 \leq C_i \leq 10^9 (1 \leq i \leq M)
- 入力はすべて整数である。
入力
N M K C_1 C_2 \ldots C_M
- 1 行目には、班のメンバーの人数を表す N 、お菓子の種類数を表す M 、各メンバーに配るお菓子の個数を表す K が、スペース区切りで与えられる。
- 2 行目には、各種類のお菓子の個数を表す C_1, C_2, \ldots, C_M が、スペース区切りで与えられる。
出力
すべてのメンバーにちょうど K 個ずつお菓子を配ることが可能であれば Yes を、不可能であれば No を 1 行で出力せよ。
入力例 1
3 4 2 3 3 3 3
出力例 1
Yes
入力例 2
5 3 3 2 2 2
出力例 2
No
入力例 3
1000000000 5 3 1000000000 1000000000 500000000 500000000 999999999
出力例 3
Yes
Score : 400 pts
Problem Statement
Takahashi is the group leader for a school trip. The group has N members including Takahashi, and Takahashi purchased M types of sweets at a souvenir shop. There are C_i pieces of the i-th type of sweet.
Takahashi wants to distribute these sweets to all members of the group (N people including himself). The rules for distribution are as follows:
- Each member receives exactly K sweets.
- Each individual sweet can be given to only one member. That is, at most C_i pieces of the i-th type of sweet can be distributed in total.
- No member may receive 2 or more sweets of the same type. That is, the K sweets each member receives must all be of different types. However, different members are allowed to each receive sweets of the same type.
- It is acceptable to have leftover sweets.
Determine whether it is possible to distribute exactly K sweets to every member. If it is possible, output Yes; otherwise, output No.
Constraints
- 1 \leq N \leq 10^9
- 1 \leq M \leq 2 \times 10^5
- 1 \leq K \leq M
- 1 \leq C_i \leq 10^9 (1 \leq i \leq M)
- All input values are integers.
Input
N M K C_1 C_2 \ldots C_M
- The first line contains N representing the number of group members, M representing the number of types of sweets, and K representing the number of sweets to give to each member, separated by spaces.
- The second line contains C_1, C_2, \ldots, C_M representing the number of pieces of each type of sweet, separated by spaces.
Output
If it is possible to distribute exactly K sweets to every member, output Yes; otherwise, output No on a single line.
Sample Input 1
3 4 2 3 3 3 3
Sample Output 1
Yes
Sample Input 2
5 3 3 2 2 2
Sample Output 2
No
Sample Input 3
1000000000 5 3 1000000000 1000000000 500000000 500000000 999999999
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 466 点
問題文
この問題では、凸図形とは以下のいずれかを指します。
- 点:平面上の 1 点からなる集合
- 線分:平面上の異なる 2 点を結ぶ線分(両端点および内部の点すべてからなる集合)
- 凸多角形:3 個以上の頂点からなり、すべての頂点が同一直線上にはない凸多角形(頂点・辺上・内部の点すべてからなる集合)。このとき面積は正です。
高橋君は N 個の凸図形を持っています。i 番目の凸図形 P_i は K_i 個の頂点で表され、以下の規則に従います。
- K_i = 1 のとき、P_i は点 (x_{i,1}, y_{i,1}) です。
- K_i = 2 のとき、P_i は 2 点 (x_{i,1}, y_{i,1}), (x_{i,2}, y_{i,2}) を結ぶ線分です。
- K_i \geq 3 のとき、K_i 個の頂点がすべて同一直線上にない場合、P_i はそれらを頂点とする凸多角形です。K_i 個の頂点がすべて同一直線上にある場合、P_i はそれらすべてを含む最短の線分(すなわち、全頂点の凸包)です。
2 つの凸図形 A, B のミンコフスキー和 A \oplus B は次のように定義されます。
A \oplus B = \{ \mathbf{a} + \mathbf{b} \mid \mathbf{a} \in A,\ \mathbf{b} \in B \}
ここで \mathbf{a} + \mathbf{b} は座標ごとの和を表します。凸図形同士のミンコフスキー和は再び凸図形となることが知られています。
N 個の凸図形から 1 個以上を選ぶ方法を考えます。各凸図形は最大 1 回しか選べません。すなわち、空でない部分集合 S \subseteq \{P_1, P_2, \ldots, P_N\} を 1 つ選びます。S に含まれるすべての図形のミンコフスキー和を
\bigoplus_{P \in S} P
と書きます。S がちょうど 1 つの図形からなる場合、この値はその図形自身です。ミンコフスキー和は結合的かつ可換であるため、二項演算を適用する順序によらず結果は一意に定まります。
空でない部分集合 S の選び方は 2^N - 1 通りあります。このうち、\bigoplus_{P \in S} P が凸多角形(すなわち、点でも線分でもなく、面積が正の凸多角形)となるものの個数を 10^9 + 7 で割った余りを求めてください。
制約
- 1 \leq N \leq 5 \times 10^4
- 1 \leq K_i \leq 50
- \sum_{i=1}^{N} K_i \leq 10^5
- |x_{i,j}| \leq 10^9,\ |y_{i,j}| \leq 10^9
- 各凸図形について、与えられる K_i 個の頂点はすべて相異なる
- K_i \geq 3 かつすべての頂点が同一直線上にない場合、頂点は反時計回りの順に与えられ、巡回的に連続する 3 頂点が同一直線上にあることはない(すなわち内角が 0° や 180° の頂点は存在しない)
- K_i \geq 3 かつすべての頂点が同一直線上にある場合、頂点は全頂点を含む線分の一方の端点から他方の端点へ向かって順に並んでいる(すなわち、最初の頂点と最後の頂点がこの線分の両端点である)
- すべての入力値は整数である
入力
入力は以下の形式で与えられます。
N
K_1
x_{1,1} y_{1,1}
x_{1,2} y_{1,2}
\vdots
x_{1,K_1} y_{1,K_1}
K_2
x_{2,1} y_{2,1}
x_{2,2} y_{2,2}
\vdots
x_{2,K_2} y_{2,K_2}
\vdots
K_N
x_{N,1} y_{N,1}
x_{N,2} y_{N,2}
\vdots
x_{N,K_N} y_{N,K_N}
- 1 行目には、凸図形の個数 N が与えられます。
- 続いて N 個の凸図形の情報が順に与えられます。
- 各凸図形について、最初の 1 行に頂点数 K_i が与えられ、続く K_i 行のそれぞれに j 番目の頂点の x 座標 x_{i,j} と y 座標 y_{i,j} が空白区切りで与えられます。
出力
条件を満たす部分集合の個数を 10^9 + 7 で割った余りを 1 行に出力してください。
入力例 1
3 1 0 0 2 1 0 1 2 3 0 0 2 0 0 2
出力例 1
4
入力例 2
3 1 2 3 3 0 0 2 0 5 0 2 -1 0 4 0
出力例 2
0
入力例 3
6 1 1 -1 2 0 0 2 1 3 -2 -1 0 -1 3 -1 4 -1 0 2 0 2 2 -1 2 5 0 0 2 -1 4 0 3 2 1 2 2 -3 1 -1 4
出力例 3
56
入力例 4
10 1 0 0 1 5 -3 2 0 0 2 0 4 -3 -3 -1 -1 1 1 4 4 3 0 0 3 0 1 2 4 -2 1 2 1 2 4 -2 4 5 -3 0 -1 -2 2 -1 3 2 0 3 3 -5 -1 -3 -4 -1 -2 3 7 -1 7 0 7 3 6 0 0 2 -1 4 0 5 2 3 4 1 3
出力例 4
1008
入力例 5
1 50 0 1 1 3 2 5 3 7 4 9 5 11 6 13 7 15 8 17 9 19 10 21 11 23 12 25 13 27 14 29 15 31 16 33 17 35 18 37 19 39 20 41 21 43 22 45 23 47 24 49 25 51 26 53 27 55 28 57 29 59 30 61 31 63 32 65 33 67 34 69 35 71 36 73 37 75 38 77 39 79 40 81 41 83 42 85 43 87 44 89 45 91 46 93 47 95 48 97 49 99
出力例 5
0
Score : 466 pts
Problem Statement
In this problem, a convex figure refers to one of the following:
- Point: A set consisting of a single point on the plane.
- Line segment: A line segment connecting two distinct points on the plane (the set consisting of both endpoints and all interior points).
- Convex polygon: A convex polygon with 3 or more vertices where not all vertices are collinear (the set consisting of all vertices, points on edges, and interior points). In this case, the area is positive.
Takahashi has N convex figures. The i-th convex figure P_i is represented by K_i vertices, following these rules:
- If K_i = 1, then P_i is the point (x_{i,1}, y_{i,1}).
- If K_i = 2, then P_i is the line segment connecting the two points (x_{i,1}, y_{i,1}) and (x_{i,2}, y_{i,2}).
- If K_i \geq 3 and not all K_i vertices are collinear, then P_i is the convex polygon with those vertices. If K_i \geq 3 and all K_i vertices are collinear, then P_i is the shortest line segment containing all of them (i.e., the convex hull of all vertices).
The Minkowski sum A \oplus B of two convex figures A, B is defined as follows:
A \oplus B = \{ \mathbf{a} + \mathbf{b} \mid \mathbf{a} \in A,\ \mathbf{b} \in B \}
Here, \mathbf{a} + \mathbf{b} denotes the coordinate-wise sum. It is known that the Minkowski sum of two convex figures is again a convex figure.
Consider ways to select one or more of the N convex figures. Each convex figure can be selected at most once. That is, we choose a non-empty subset S \subseteq \{P_1, P_2, \ldots, P_N\}. We write the Minkowski sum of all figures in S as
\bigoplus_{P \in S} P
If S consists of exactly one figure, this value is that figure itself. Since the Minkowski sum is associative and commutative, the result is uniquely determined regardless of the order in which the binary operation is applied.
There are 2^N - 1 ways to choose a non-empty subset S. Among these, find the number of subsets for which \bigoplus_{P \in S} P is a convex polygon (i.e., not a point or a line segment, but a convex polygon with positive area), modulo 10^9 + 7.
Constraints
- 1 \leq N \leq 5 \times 10^4
- 1 \leq K_i \leq 50
- \sum_{i=1}^{N} K_i \leq 10^5
- |x_{i,j}| \leq 10^9,\ |y_{i,j}| \leq 10^9
- For each convex figure, the given K_i vertices are all distinct.
- If K_i \geq 3 and not all vertices are collinear, the vertices are given in counterclockwise order, and no three cyclically consecutive vertices are collinear (i.e., there are no vertices with interior angle 0° or 180°).
- If K_i \geq 3 and all vertices are collinear, the vertices are ordered from one endpoint of the line segment containing all vertices to the other endpoint (i.e., the first and last vertices are the two endpoints of this line segment).
- All input values are integers.
Input
The input is given in the following format:
N
K_1
x_{1,1} y_{1,1}
x_{1,2} y_{1,2}
\vdots
x_{1,K_1} y_{1,K_1}
K_2
x_{2,1} y_{2,1}
x_{2,2} y_{2,2}
\vdots
x_{2,K_2} y_{2,K_2}
\vdots
K_N
x_{N,1} y_{N,1}
x_{N,2} y_{N,2}
\vdots
x_{N,K_N} y_{N,K_N}
- The first line gives the number of convex figures N.
- Then the information for N convex figures is given in order.
- For each convex figure, the first line gives the number of vertices K_i, followed by K_i lines each containing the x-coordinate x_{i,j} and y-coordinate y_{i,j} of the j-th vertex, separated by a space.
Output
Print the number of subsets satisfying the condition, modulo 10^9 + 7, on a single line.
Sample Input 1
3 1 0 0 2 1 0 1 2 3 0 0 2 0 0 2
Sample Output 1
4
Sample Input 2
3 1 2 3 3 0 0 2 0 5 0 2 -1 0 4 0
Sample Output 2
0
Sample Input 3
6 1 1 -1 2 0 0 2 1 3 -2 -1 0 -1 3 -1 4 -1 0 2 0 2 2 -1 2 5 0 0 2 -1 4 0 3 2 1 2 2 -3 1 -1 4
Sample Output 3
56
Sample Input 4
10 1 0 0 1 5 -3 2 0 0 2 0 4 -3 -3 -1 -1 1 1 4 4 3 0 0 3 0 1 2 4 -2 1 2 1 2 4 -2 4 5 -3 0 -1 -2 2 -1 3 2 0 3 3 -5 -1 -3 -4 -1 -2 3 7 -1 7 0 7 3 6 0 0 2 -1 4 0 5 2 3 4 1 3
Sample Output 4
1008
Sample Input 5
1 50 0 1 1 3 2 5 3 7 4 9 5 11 6 13 7 15 8 17 9 19 10 21 11 23 12 25 13 27 14 29 15 31 16 33 17 35 18 37 19 39 20 41 21 43 22 45 23 47 24 49 25 51 26 53 27 55 28 57 29 59 30 61 31 63 32 65 33 67 34 69 35 71 36 73 37 75 38 77 39 79 40 81 41 83 42 85 43 87 44 89 45 91 46 93 47 95 48 97 49 99
Sample Output 5
0