結果

問題 No.3789 Binary 0-count Sequence
コンテスト
ユーザー ooaiu
提出日時 2026-11-06 22:04:10
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 825 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 105 ms
コンパイル使用メモリ 64,748 KB
実行使用メモリ 154,084 KB
最終ジャッジ日時 2026-11-06 22:04:32
合計ジャッジ時間 21,938 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 7 WA * 1 TLE * 3 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code


for _ in range(int(input())):
    N = int(input())
    def count(x: int):
        x = bin(x)[2:]
        return x.count("0")
    A = list(map(int, input().split()))


    def check(L: int):
        B = [count(L + i) for i in range(N)]
        return A == B

    if N == 1:
        print(1 << A[0])
        continue
    if min(A) == 0:
        it = A.index(0)

        ok = False
        for i in range(61):
            x = 1 << i
            if check(x - 1 - it):
                print(x - 1 - it)
                ok = True
                break
        if not ok:
            print(-1)
    else:
        G = [A[i + 1] - A[i] + 1 for i in range(N - 1)]
        it = G.index(max(G))
        x = int("1" + "0" * A[it] + "1" * G[it], 2)
        if check(x - it):
            print(x - it)
        else:
            print(-1)

0