結果

問題 No.1017 Reiwa Sequence
ユーザー tktk_snsntktk_snsn
提出日時 2021-09-20 19:33:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 642 ms / 2,000 ms
コード長 755 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 86,816 KB
実行使用メモリ 180,412 KB
最終ジャッジ日時 2023-09-15 15:23:12
合計ジャッジ時間 30,629 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,564 KB
testcase_01 AC 94 ms
71,432 KB
testcase_02 AC 94 ms
71,828 KB
testcase_03 AC 101 ms
77,264 KB
testcase_04 AC 93 ms
71,668 KB
testcase_05 AC 92 ms
71,644 KB
testcase_06 AC 93 ms
71,652 KB
testcase_07 AC 93 ms
71,536 KB
testcase_08 AC 93 ms
71,724 KB
testcase_09 AC 103 ms
77,960 KB
testcase_10 AC 196 ms
81,896 KB
testcase_11 AC 105 ms
77,728 KB
testcase_12 AC 438 ms
85,876 KB
testcase_13 AC 435 ms
85,388 KB
testcase_14 AC 101 ms
77,428 KB
testcase_15 AC 104 ms
77,524 KB
testcase_16 AC 106 ms
77,660 KB
testcase_17 AC 108 ms
79,232 KB
testcase_18 AC 104 ms
77,820 KB
testcase_19 AC 365 ms
180,072 KB
testcase_20 AC 363 ms
179,972 KB
testcase_21 AC 364 ms
179,932 KB
testcase_22 AC 373 ms
179,864 KB
testcase_23 AC 365 ms
180,064 KB
testcase_24 AC 364 ms
179,864 KB
testcase_25 AC 365 ms
179,988 KB
testcase_26 AC 358 ms
179,756 KB
testcase_27 AC 300 ms
146,484 KB
testcase_28 AC 314 ms
146,316 KB
testcase_29 AC 200 ms
83,536 KB
testcase_30 AC 202 ms
85,356 KB
testcase_31 AC 211 ms
92,924 KB
testcase_32 AC 284 ms
146,392 KB
testcase_33 AC 198 ms
82,032 KB
testcase_34 AC 290 ms
146,320 KB
testcase_35 AC 195 ms
81,128 KB
testcase_36 AC 192 ms
81,440 KB
testcase_37 AC 284 ms
146,440 KB
testcase_38 AC 193 ms
81,440 KB
testcase_39 AC 283 ms
146,512 KB
testcase_40 AC 640 ms
180,108 KB
testcase_41 AC 642 ms
180,264 KB
testcase_42 AC 637 ms
180,412 KB
testcase_43 AC 635 ms
179,964 KB
testcase_44 AC 464 ms
98,628 KB
testcase_45 AC 636 ms
180,128 KB
testcase_46 AC 634 ms
180,196 KB
testcase_47 AC 629 ms
180,228 KB
testcase_48 AC 488 ms
109,036 KB
testcase_49 AC 480 ms
109,020 KB
testcase_50 AC 478 ms
109,292 KB
testcase_51 AC 91 ms
71,804 KB
testcase_52 AC 361 ms
180,136 KB
testcase_53 AC 230 ms
103,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict


def search(N, A):
    N = min(20, N)
    dp = [0] * (1 << N)
    for S in range(1, 1 << N):
        for i in range(N):
            if (S >> i) & 1:
                dp[S] += A[i]

    memo = defaultdict(list)
    for S in range(1, 1 << N):
        if not memo[dp[S]]:
            memo[dp[S]].append(S)
            continue
        for T in memo[dp[S]]:
            if S & T == 0:
                return S, T
        memo[dp[S]].append(S)
    return -1, -1


N = int(input())
A = list(map(int, input().split()))
S, T = search(N, A)

if S == -1:
    print("No")
    exit()

ans = [0] * N
for i in range(20):
    if (S >> i) & 1:
        ans[i] = A[i]
    if (T >> i) & 1:
        ans[i] = -A[i]

print("Yes")
print(*ans)
0