結果

問題 No.983 Convolution
ユーザー 👑 rin204rin204
提出日時 2022-03-25 19:47:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 164,584 KB
最終ジャッジ日時 2024-04-22 04:44:03
合計ジャッジ時間 8,773 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,352 KB
testcase_01 AC 38 ms
52,224 KB
testcase_02 AC 39 ms
52,608 KB
testcase_03 AC 270 ms
117,164 KB
testcase_04 AC 238 ms
109,512 KB
testcase_05 AC 221 ms
104,812 KB
testcase_06 AC 381 ms
145,992 KB
testcase_07 AC 388 ms
144,432 KB
testcase_08 AC 98 ms
82,944 KB
testcase_09 AC 139 ms
91,008 KB
testcase_10 AC 80 ms
77,952 KB
testcase_11 AC 100 ms
83,456 KB
testcase_12 AC 436 ms
159,536 KB
testcase_13 AC 132 ms
91,008 KB
testcase_14 AC 148 ms
92,604 KB
testcase_15 AC 273 ms
117,860 KB
testcase_16 AC 228 ms
104,936 KB
testcase_17 AC 405 ms
149,872 KB
testcase_18 AC 96 ms
82,208 KB
testcase_19 AC 219 ms
104,824 KB
testcase_20 AC 441 ms
164,584 KB
testcase_21 AC 259 ms
116,668 KB
testcase_22 AC 105 ms
83,732 KB
testcase_23 AC 116 ms
100,992 KB
testcase_24 AC 64 ms
71,296 KB
testcase_25 AC 62 ms
70,132 KB
testcase_26 AC 107 ms
91,904 KB
testcase_27 AC 81 ms
81,408 KB
testcase_28 AC 216 ms
104,960 KB
testcase_29 AC 420 ms
162,912 KB
testcase_30 AC 216 ms
104,876 KB
testcase_31 AC 137 ms
92,288 KB
testcase_32 AC 227 ms
106,976 KB
testcase_33 AC 39 ms
52,656 KB
testcase_34 AC 39 ms
52,608 KB
testcase_35 AC 38 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def convolve_and(A, B):
    n = max(len(A), len(B))
    l = ((n - 1).bit_length())
    n = 1 << l
    A += [0] * (n - len(A))
    B += [0] * (n - len(B))
    
    def f(A):
        for i in range(l):
            for bit in range(n):
                if not bit >> i & 1:
                    A[bit] += A[bit ^ (1 << i)]
    
    def invf(A):
        for i in range(l):
            for bit in range(n):
                if not bit >> i & 1:
                    A[bit] -= A[bit ^ (1 << i)]
    
    f(A)
    f(B)
    C = [a * b for a, b in zip(A, B)]
    invf(C)
    return C

from math import gcd

n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    if A[i] == -1:
        A[i] = 0
C = convolve_and(A[:], A[:])
g = 0
for c in C:
    g = gcd(c, g)
if g == 0:
    g = -1
print(g)
0