問題一覧 > 通常問題

No.74 The Piggy Bank's Boredom

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 112
作問者 : kroton
お気に入りにしたユーザー ProblemId : 127 / 自分の提出
問題文最終更新日: 2026-06-25 09:06:55
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 55 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。