No.2015 Stair Counter
タグ : / 解いたユーザー数 155
作問者 :
Problem Statement
There is a staircase consisting of $N$ steps. Initially, $M$ people are at step $0$, the entrance at the bottom. Each person went up to step $N$ by climbing $1$ or $2$ steps per $1$ stride.
You are given a sequence $A = (A_1, A_2, \dots, A_N)$ of length $N$. Determine whether there exists a way for the $M$ people to climb such that, for every $i$ $(1 \leq i \leq N)$, the number of people who stepped on step $i$ is equal to $A_i$.
You are given $T$ test cases; solve each of them.
Constraints
- All input values are integers
- $1 \leq T \leq 10^4$
- $1 \leq N \leq 2 \times 10^5$
- $1 \leq M \leq 10^9$
- $0 \leq A_i \leq M$ $(1 \leq i \leq N - 1)$
- $A_N = M$
- Within $1$ input file, the sum of $N$ is at most $2 \times 10^5$
Input
The input is given from standard input. Line $1$ is given in the following format.
$T$
Then, $T$ test cases follow, each given in the following format.
$N$ $M$ $A_1$ $A_2$ $\dots$ $A_N$
Output
Print over $T$ lines. On line $i$ $(1 \leq i \leq T)$, for the $i$-th test case, print Yes if there exists a way of climbing such that the number of people who stepped on each step matches $A$, and No otherwise.
Print a newline at the end.
Sample
Sample 1
Input
6 3 3 1 2 3 5 1 0 1 1 0 1 5 5 3 1 4 1 5 20 9 9 8 3 9 2 8 6 4 6 7 2 9 9 4 8 8 3 7 5 9 5 392594829 63454038 307305345 98813758 258579949 392594829 9 724640070 515364178 287107703 719086324 652644278 450996113 447939354 349844586 541137464 724640070
Output
Yes Yes No Yes No Yes
$6$ test cases are given.
In test case $1$, $3$ people climb a staircase consisting of $3$ steps. For example, if $1$ person climbs as $0 \rightarrow 1 \rightarrow 3$ and $2$ people climb as $0 \rightarrow 2 \rightarrow 3$, the number of people who stepped on each step matches $A$.
In test case $2$, $1$ person climbs a staircase consisting of $5$ steps. Climbing as $0 \rightarrow 2 \rightarrow 3 \rightarrow 5$ matches $A$.
In test case $3$, no matter how they climb, the number of people who stepped on each step cannot be made to match $A$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。