結果

問題 No.1017 Reiwa Sequence
ユーザー mkawa2mkawa2
提出日時 2020-04-06 07:52:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 826 ms / 2,000 ms
コード長 1,474 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 107,684 KB
最終ジャッジ日時 2023-09-16 06:50:33
合計ジャッジ時間 27,113 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
34,248 KB
testcase_01 AC 35 ms
34,128 KB
testcase_02 AC 35 ms
34,188 KB
testcase_03 AC 53 ms
34,432 KB
testcase_04 AC 34 ms
34,188 KB
testcase_05 AC 35 ms
34,256 KB
testcase_06 AC 34 ms
34,264 KB
testcase_07 AC 34 ms
34,160 KB
testcase_08 AC 34 ms
34,148 KB
testcase_09 AC 53 ms
34,264 KB
testcase_10 AC 79 ms
34,984 KB
testcase_11 AC 54 ms
34,388 KB
testcase_12 AC 79 ms
34,996 KB
testcase_13 AC 54 ms
34,512 KB
testcase_14 AC 56 ms
34,504 KB
testcase_15 AC 76 ms
34,704 KB
testcase_16 AC 55 ms
34,512 KB
testcase_17 AC 88 ms
35,284 KB
testcase_18 AC 54 ms
34,392 KB
testcase_19 AC 662 ms
69,328 KB
testcase_20 AC 651 ms
69,312 KB
testcase_21 AC 656 ms
69,376 KB
testcase_22 AC 640 ms
69,200 KB
testcase_23 AC 632 ms
69,420 KB
testcase_24 AC 636 ms
69,472 KB
testcase_25 AC 629 ms
69,352 KB
testcase_26 AC 582 ms
69,376 KB
testcase_27 AC 484 ms
69,352 KB
testcase_28 AC 482 ms
69,236 KB
testcase_29 AC 82 ms
35,420 KB
testcase_30 AC 94 ms
36,508 KB
testcase_31 AC 163 ms
44,420 KB
testcase_32 AC 437 ms
69,208 KB
testcase_33 AC 82 ms
35,248 KB
testcase_34 AC 380 ms
69,304 KB
testcase_35 AC 35 ms
34,356 KB
testcase_36 AC 52 ms
34,420 KB
testcase_37 AC 400 ms
69,212 KB
testcase_38 AC 36 ms
34,132 KB
testcase_39 AC 426 ms
69,336 KB
testcase_40 AC 821 ms
107,360 KB
testcase_41 AC 826 ms
107,684 KB
testcase_42 AC 821 ms
107,408 KB
testcase_43 AC 826 ms
107,320 KB
testcase_44 AC 95 ms
40,276 KB
testcase_45 AC 806 ms
107,492 KB
testcase_46 AC 790 ms
107,532 KB
testcase_47 AC 746 ms
107,352 KB
testcase_48 AC 173 ms
42,508 KB
testcase_49 AC 133 ms
42,480 KB
testcase_50 AC 131 ms
41,596 KB
testcase_51 AC 34 ms
34,268 KB
testcase_52 AC 393 ms
69,116 KB
testcase_53 AC 391 ms
69,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# N=22のとき、Aの部分集合の選び方は2**22=4194304通り
# それに対して、部分集合の和は150000*22=3300000通り(正確には0も入れて+1通り)
# 選び方のパターン>和のパターンということは、同じ和になる選び方が必ず存在するということ
# よって、Nが22以上のときは初めから22項だけで考え、あとは0にする
def main():
    n=II()
    aa=LI()
    if len(aa)>22:aa=aa[:22]
    mx=3300000
    dp=[-1]*(mx+1)
    q=deque()
    q.append((0,0))
    dp[0]=0
    while q:
        i,s=q.popleft()
        if i+1<len(aa):q.append((i+1,s))
        ndp=dp[s]|1<<i
        ns=s+aa[i]
        if dp[ns]!=-1:break
        dp[ns]=ndp
        if i+1<len(aa):q.append((i+1,ns))
    else:
        print("No")
        exit()
    coe=[0]*len(aa)
    for i in range(len(aa)):
        if dp[ns]>>i&1:coe[i]=1
    for i in range(len(aa)):
        if ndp>>i&1:coe[i]=-1
    for i in range(len(aa)):
        aa[i]*=coe[i]
    if n-len(aa)>0:aa+=[0]*(n-len(aa))
    print("Yes")
    print(*aa)

main()
0