A11707 | Cutting Rectangle
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A rectangle with sides $A$ and $B$ is cut into rectangles with cuts parallel to its sides. For example, if $p$ horizontal and $q$ vertical cuts were made, $(p + 1) \cdot (q + 1)$ rectangles were left after the cutting. After the cutting, rectangles were of $n$ different types. Two rectangles are different if at least one side of one rectangle isn't equal to the corresponding side of the other. Note that the rectangle can't be rotated, this means that rectangles $a \times b$ and $b \times a$ are considered different if $a \neq b$ .
For each type of rectangles, lengths of the sides of rectangles are given along with the amount of the rectangles of this type that were left after cutting the initial rectangle.
Calculate the amount of pairs $(A; B)$ such as the given rectangles could be created by cutting the rectangle with sides of lengths $A$ and $B$ . Note that pairs $(A; B)$ and $(B; A)$ are considered different when $A \neq B$ .
For each type of rectangles, lengths of the sides of rectangles are given along with the amount of the rectangles of this type that were left after cutting the initial rectangle.
Calculate the amount of pairs $(A; B)$ such as the given rectangles could be created by cutting the rectangle with sides of lengths $A$ and $B$ . Note that pairs $(A; B)$ and $(B; A)$ are considered different when $A \neq B$ .
输入格式
The first line consists of a single integer $n$ ( $1 \leq n \leq 2 \cdot 10^{5}$ ) — amount of different types of rectangles left after cutting the initial rectangle.
The next $n$ lines each consist of three integers $w_{i}, h_{i}, c_{i}$ $(1 \leq w_{i}, h_{i}, c_{i} \leq 10^{12})$ — the lengths of the sides of the rectangles of this type and the amount of the rectangles of this type.
It is guaranteed that the rectangles of the different types are different.
The next $n$ lines each consist of three integers $w_{i}, h_{i}, c_{i}$ $(1 \leq w_{i}, h_{i}, c_{i} \leq 10^{12})$ — the lengths of the sides of the rectangles of this type and the amount of the rectangles of this type.
It is guaranteed that the rectangles of the different types are different.
输出格式
Output one integer — the answer to the problem.
输入输出样例
输入 #1
1 1 1 9
输出 #1
3
输入 #2
2 2 3 20 2 4 40
输出 #2
6
输入 #3
2 1 2 5 2 3 5
输出 #3
0
In the first sample there are three suitable pairs: $(1; 9)$ , $(3; 3)$ and $(9; 1)$ .
In the second sample case there are 6 suitable pairs: $(2; 220)$ , $(4; 110)$ , $(8; 55)$ , $(10; 44)$ , $(20; 22)$ and $(40; 11)$ .
Here the sample of cut for $(20; 22)$ .
The third sample has no suitable pairs.
In the second sample case there are 6 suitable pairs: $(2; 220)$ , $(4; 110)$ , $(8; 55)$ , $(10; 44)$ , $(20; 22)$ and $(40; 11)$ .
Here the sample of cut for $(20; 22)$ .
The third sample has no suitable pairs.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted