結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー 👑 KazunKazun
提出日時 2022-11-27 17:20:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 366 ms / 1,000 ms
コード長 917 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 88,836 KB
最終ジャッジ日時 2024-04-22 18:35:40
合計ジャッジ時間 18,480 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
88,704 KB
testcase_01 AC 310 ms
88,804 KB
testcase_02 AC 250 ms
88,196 KB
testcase_03 AC 345 ms
88,680 KB
testcase_04 AC 361 ms
88,576 KB
testcase_05 AC 357 ms
88,404 KB
testcase_06 AC 330 ms
88,660 KB
testcase_07 AC 344 ms
88,448 KB
testcase_08 AC 343 ms
88,448 KB
testcase_09 AC 366 ms
88,576 KB
testcase_10 AC 328 ms
88,448 KB
testcase_11 AC 357 ms
88,576 KB
testcase_12 AC 354 ms
88,528 KB
testcase_13 AC 314 ms
88,320 KB
testcase_14 AC 355 ms
88,464 KB
testcase_15 AC 359 ms
88,132 KB
testcase_16 AC 357 ms
88,692 KB
testcase_17 AC 324 ms
88,308 KB
testcase_18 AC 347 ms
88,832 KB
testcase_19 AC 364 ms
88,704 KB
testcase_20 AC 308 ms
88,576 KB
testcase_21 AC 322 ms
88,560 KB
testcase_22 AC 354 ms
88,552 KB
testcase_23 AC 330 ms
88,316 KB
testcase_24 AC 355 ms
88,412 KB
testcase_25 AC 343 ms
88,832 KB
testcase_26 AC 362 ms
88,524 KB
testcase_27 AC 310 ms
88,248 KB
testcase_28 AC 269 ms
88,320 KB
testcase_29 AC 274 ms
88,448 KB
testcase_30 AC 282 ms
88,116 KB
testcase_31 AC 300 ms
88,256 KB
testcase_32 AC 298 ms
88,348 KB
testcase_33 AC 303 ms
88,448 KB
testcase_34 AC 316 ms
88,132 KB
testcase_35 AC 319 ms
88,448 KB
testcase_36 AC 323 ms
88,528 KB
testcase_37 AC 338 ms
88,320 KB
testcase_38 AC 350 ms
88,312 KB
testcase_39 AC 348 ms
88,572 KB
testcase_40 AC 347 ms
88,576 KB
testcase_41 AC 345 ms
88,836 KB
testcase_42 AC 351 ms
88,444 KB
testcase_43 AC 350 ms
88,448 KB
testcase_44 AC 339 ms
88,704 KB
testcase_45 AC 331 ms
88,252 KB
testcase_46 AC 333 ms
88,388 KB
testcase_47 AC 253 ms
88,704 KB
testcase_48 AC 349 ms
88,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    N=19

    B=[[0]*N for _ in range(N)]
    for i in range(N):
        _,*Ai=map(int,input().split())
        for a in Ai:
            B[i][a-1]=1

    popcount=[0]*(1<<N)
    for S in range(1,1<<N):
        popcount[S]=popcount[S>>1]+(S&1)

    bit=lambda S,k:(S>>k)&1

    DP0=[0]*(1<<N); DP1=[0]*(1<<N)
    for S in range((1<<N)-1, -1, -1):
        if popcount[S]==N:
            DP0[S]=1
            continue

        unused=[i for i in range(N) if not bit(S,i)]
        for t in range(len(unused)):
            if B[popcount[S]][unused[t]]==1:
                T=S|(1<<unused[t])
                if t%2:
                    DP0[S]+=DP1[T]
                    DP1[S]+=DP0[T]
                else:
                    DP0[S]+=DP0[T]
                    DP1[S]+=DP1[T]

    return DP0[0], DP1[0]

#==================================================
print(*solve())
0