No.74 The Piggy Bank's Boredom
Problem Statement
Chokinbako-kun was very bored.
So he decided to play with the coins he owns.
First, he scatters his coins on the floor, then picks \(N\) coins from them and arranges them in a circle.
Next, he picks any one of the \(N\) coins. Letting \(D\) yen be the face value of the chosen coin, he flips the coin \(D\) positions ahead clockwise from the chosen coin and the coin \(D\) positions ahead counterclockwise from the chosen coin.
However, if the clockwise and counterclockwise coins are the same coin, he flips that coin only once.
Chokinbako-kun wants to repeat this operation to make all the coins face up.
Given the arrangement of the coins, their face values, and their initial sides, determine whether all the coins can be made face up.
Note that the same coin may be chosen multiple times.
Input
\(N\)
\(D_{1}\) \(D_{2}\) \(D_{3}\) \(\ldots\) \(D_{N}\)
\(W_{1}\) \(W_{2}\) \(W_{3}\) \(\ldots\) \(W_{N}\)
All input values are integers.
- \(3 \leq N \leq 100\) denotes the number of coins.
- \(1 \leq D_{k} \leq 1000\) denotes the face value of the \(k\)-th coin.
- \(0 \leq W_{k} \leq 1\) denotes the side of the \(k\)-th coin: \(W_{k}=0\) means "face down" and \(W_{k}=1\) means "face up".
- The coins are given in clockwise order.
Output
Print "Yes" if all the coins can be made face up, and "No" otherwise.
Sample
Sample 1
Input
3 1 2 3 1 1 1
Output
Yes
All the coins are face up in the initial state, so no coin needs to be chosen.
Sample 2
Input
3 1 2 3 0 1 1
Output
Yes
First, choose the \(2\)-yen coin, and flip the \(1\)-yen coin located \(2\) positions ahead clockwise and the \(3\)-yen coin located \(2\) positions ahead counterclockwise.
Next, choosing the \(3\)-yen coin gives the \(3\)-yen coin both clockwise and counterclockwise, so flip the \(3\)-yen coin, and all the coins become face up.
Figure: The process, with face up shown in blue and face down shown in pink
Sample 3
Input
3 1 1 1 0 0 0
Output
No
No matter how the coins are chosen, it is impossible to make all the coins face up.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。