Universal Cup Judging System

Universal Cup

시간 제한: 6 s 메모리 제한: 512 MB 총점: 100 난이도: [표시] 해킹 가능 ✓
통계

Yuki は一列に並んだ $n$ 本の棒を持っており、$i$ 番目の棒の長さは $a_i$ です。

Yuki は 1 回の操作を以下のように定義します: - 棒を 1 本選び、それを 2 つの部分に切断する。切断された 2 つの部分の長さはどちらも整数でなければならない(一方の部分の長さが 0 であってもよい)。 - 切断された棒の左側の部分を、そのすぐ左隣にある棒と結合する。左隣に棒がない場合、左側の部分は新しい独立した棒になる。 - 切断された棒の右側の部分を、そのすぐ右隣にある棒と結合する。右隣に棒がない場合、右側の部分は新しい独立した棒になる。 - 長さが 0 の棒をすべて取り除く。

今、Yuki は何回かの操作を行って、すべての棒の長さを等しくしたいと考えています。すべての棒の長さを等しくするために必要な最小の操作回数を求めてください。

すべての棒の長さを等しくできる操作手順が少なくとも 1 つ常に存在することが証明できます。

入力

この問題には複数のテストケースが含まれます。

1 行目には、テストケースの数を表す正の整数 $t$ ($1 \le t \le 10^5$) が与えられます。

各テストケースについて: - 1 行目には正の整数 $n$ ($1 \le n \le 10^6$) が与えられます。 - 2 行目には $n$ 個の正の整数 $a_1, \dots, a_n$ ($1 \le a_i \le 10^6$) が与えられます。

すべてのテストケースにおける $n$ の総和は $10^6$ を超えないことが保証されます。

出力

各テストケースについて、すべての棒の長さを等しくするために必要な最小の操作回数を表す整数を 1 行に出力してください。

サンプル 1

入力 1

3
3
1 5 4
4
1 4 2 5
5
3 3 3 3 3

出力 1

1
2
0

注記

1 つ目のテストケースについて: - 1 回目の操作で 2 番目の棒を選び、長さ 4 と 1 の 2 つの部分に切断します。左から右への棒の長さは 5, 5 となり、すべての棒の長さが等しくなります。 - 必要な最小の操作回数は 1 回であることが証明できます。

2 つ目のテストケースについて: - 1 回目の操作で 1 番目の棒を選び、長さ 0 と 1 の 2 つの部分に切断します。左から右への棒の長さは 5, 2, 5 となります。 - 2 回目の操作で 2 番目の棒を選び、長さ 1 と 1 の 2 つの部分に切断します。左から右への棒の長さは 6, 6 となり、すべての棒の長さが等しくなります。 - 必要な最小の操作回数は 2 回であることが証明できます。

3 つ目のテストケースについて: - 最初からすべての棒の長さが等しいため、必要な最小の操作回数は 0 回です。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1873EditorialOpenNew Editorial for Problem #17347wangmaruiView

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.