Universal Cup Judging System

Universal Cup

Limite de temps : 3.0 s Limite de mémoire : 768 MB Points totaux : 100 Hackable ✓
Statistiques

メモリ制限が特殊であることに注意してください。

整数 $N$ と整数列 $A = (A_1, A_2, \dots, A_N)$ が与えられます。

長さが $1$ になるまで、この列に対して繰り返し操作を行います。各ステップでは、現在の列において隣接する 2 つの要素を選び、1 つの要素に統合します。各統合の後、得られた列は自然な順序で番号が振り直されます。利用可能な操作は以下の 2 種類です:

  • 操作 AND:$A_i$ と $A_{i+1}$ を $(A_i \mathbin{\&} A_{i+1})$ に置き換える。
  • 操作 OR:$A_i$ と $A_{i+1}$ を $(A_i \mathbin{|} A_{i+1})$ に置き換える。

ここで、演算子 $\&$ と $|$ はそれぞれビットごとの AND 演算とビットごとの OR 演算を表します。

1 回の操作につき列の長さは $1$ 減るため、全体でちょうど $(N - 1)$ 回の操作が行われます。

最終的に残る要素が $0$ になるようなすべての可能な操作列の中で、操作 OR が行われる回数の最大値を求めてください。

入力

入力は複数のテストケースからなります。

T
testcase 1
testcase 2
:
testcase T

各テストケースは以下の形式で与えられます:

N
A_1 A_2 ... A_N

制約

  • $1 \le T \le 2^{12}$
  • $2 \le N \le 2^{13}$
  • $0 \le A_i < 2^{13}$
  • すべてのテストケースにおける $N$ の総和は $2^{13}$ を超えない。
  • 入力される値はすべて整数である。

出力

最終的に残る要素が $0$ になるという条件を満たすすべての操作列の中で、操作 OR を行うことができる最大回数を出力してください。条件を満たす操作列が存在しない場合は $-1$ を出力してください。

入出力例

入力例 1

4
6
3 0 1 4 1 5
2
0 1
8
2 0 1 6 1 2 0 3
10
1 7 6 7 5 7 5 3 2 7

出力例 1

3
0
5
6

注記

この入力には $4$ 個のテストケースが含まれています。

最初のテストケースでは、以下のように 2 種類目の操作(操作 OR)を $3$ 回行うことができます:

  • 最初、$A = (3, 0, 1, 4, 1, 5)$ である。
  • $(A_3, A_4)$ に OR 操作を適用する。操作後、$A = (3, 0, 5, 1, 5)$ となる。
  • $(A_1, A_2)$ に AND 操作を適用する。操作後、$A = (0, 5, 1, 5)$ となる。
  • $(A_3, A_4)$ に OR 操作を適用する。操作後、$A = (0, 5, 5)$ となる。
  • $(A_2, A_3)$ に OR 操作を適用する。操作後、$A = (0, 5)$ となる。
  • $(A_1, A_2)$ に AND 操作を適用する。操作後、$A = (0)$ となる。

最終状態が $A_1 = 0$ を満たしているため、条件は達成されています。

OR 操作を $4$ 回以上行って条件を満たすことは不可能であるため、答えは $3$ です。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1490EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.