No.3560 Giant Salamander
タグ : / 解いたユーザー数 34
作問者 :
jastaway
yaaya
butsurizuki
Problem Statement
There are $N$ cells arranged in a circle. The cells are numbered from $1$ to $N$ in clockwise order. Cell $i$ and cell $i+1 ( 1 \le i \le N-1 )$ are adjacent, and cell $N$ and cell $1$ are also adjacent.
Initially, each cell contains $1$ giant salamander. You may perform the following operation any number of times (possibly $0$).
- Choose $2$ adjacent cells such that both cells contain at least $1$ giant salamander.
- Choose one of these cells and move all giant salamanders in that cell to the other cell.
Output Yes if it is possible to reach a state where, when you finish performing operations, giant salamanders remain only in cells $A_1, A_2, \dots, A_M$ and cell $A_i$ contains $B_i$ giant salamanders; otherwise, output No.
You are given $T$ test cases; solve each of them.
Input
The input is given from Standard Input in the following format.
$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$
Here, $\text{case}_i$ denotes the input for the $i$-th test case. Each test case is given in the following format.
$N$ $M$ $A_1$ $B_1$ $A_2$ $B_2$ $\vdots$ $A_M$ $B_M$
- $1 \le T \le 2 \times 10^5$
- $3 \le N \le 10^9$
- $1 \le M \le \min (N, 2 \times 10^5)$
- $1 \le A_1 < A_2 < \dots < A_M \le N$
- $1 \le B_i$
- $\sum_{1 \le i \le M} B_i = N$
- All input values are integers.
- The sum of $M$ over all test cases is at most $2 \times 10^5$.
Partial Score
This problem has partial scoring based on subtasks.
| Subtask | Score | Constraints |
|---|---|---|
| 部分点1 | 5% (12 pts) | $M=1$ または $M=N$ |
| 部分点2 | 20% (50 pts) | $T \le 10, N \le 7$ |
| 部分点3 | 15% (37 pts) | すべてのテストケースにおける $N$ の総和は $2 \times 10^3$ 以下である |
| 部分点4 | 40% (100 pts) | すべてのテストケースにおける $N$ の総和は $2 \times 10^5$ 以下である |
| 満点 | 20% (50 pts) | 追加の制約はない |
Output
Output $T$ lines.
On the $i$-th line, for the $i$-th test case, output Yes if the condition can be satisfied, and No otherwise.
Sample
Sample 1
Input
3 4 2 1 2 3 2 3 3 1 1 2 1 3 1 6 3 1 1 3 1 5 4
Output
Yes Yes No
For test case $1$, the condition can be satisfied, for example, by performing the following operations.
- Choose cell $4$ and cell $1$, and move the giant salamanders in cell $4$ to cell $1$. Cell $1$ now contains $2$ giant salamanders.
- Choose cell $2$ and cell $3$, and move the giant salamanders in cell $2$ to cell $3$. Cell $3$ now contains $2$ giant salamanders.
For test case $2$, the condition can be satisfied by performing no operations.
For test case $3$, it is impossible to perform operations so that the condition is satisfied.
This input satisfies the constraints of all subtasks except subtask $1$.
Sample 2
Input
2 1000000000 3 2025 999999998 2026 1 2027 1 1000000000 3 2025 999999997 2026 2 2027 1
Output
Yes No
This input satisfies the constraints for the full score.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。