結果

問題 No.2152 [Cherry Anniversary 2] 19 Petals of Cherry
ユーザー tassei903tassei903
提出日時 2022-12-09 19:59:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,593 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 165,504 KB
最終ジャッジ日時 2024-10-14 18:49:18
合計ジャッジ時間 16,675 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
165,376 KB
testcase_01 AC 232 ms
164,096 KB
testcase_02 AC 220 ms
165,504 KB
testcase_03 AC 331 ms
129,280 KB
testcase_04 AC 270 ms
159,360 KB
testcase_05 AC 365 ms
125,128 KB
testcase_06 AC 276 ms
159,700 KB
testcase_07 AC 296 ms
145,152 KB
testcase_08 AC 344 ms
129,000 KB
testcase_09 AC 246 ms
162,176 KB
testcase_10 AC 349 ms
126,516 KB
testcase_11 AC 273 ms
157,920 KB
testcase_12 AC 235 ms
162,304 KB
testcase_13 AC 274 ms
159,232 KB
testcase_14 AC 294 ms
145,408 KB
testcase_15 AC 296 ms
141,056 KB
testcase_16 AC 298 ms
137,140 KB
testcase_17 AC 329 ms
128,672 KB
testcase_18 AC 326 ms
129,024 KB
testcase_19 AC 314 ms
132,748 KB
testcase_20 AC 234 ms
164,352 KB
testcase_21 AC 357 ms
126,136 KB
testcase_22 AC 282 ms
159,488 KB
testcase_23 AC 290 ms
158,848 KB
testcase_24 AC 364 ms
126,080 KB
testcase_25 AC 343 ms
128,928 KB
testcase_26 AC 300 ms
141,220 KB
testcase_27 AC 281 ms
158,336 KB
testcase_28 AC 225 ms
165,120 KB
testcase_29 AC 227 ms
164,224 KB
testcase_30 AC 232 ms
164,276 KB
testcase_31 AC 231 ms
164,224 KB
testcase_32 AC 231 ms
163,968 KB
testcase_33 AC 244 ms
162,304 KB
testcase_34 AC 257 ms
161,024 KB
testcase_35 AC 282 ms
158,592 KB
testcase_36 AC 295 ms
157,808 KB
testcase_37 AC 329 ms
132,864 KB
testcase_38 AC 349 ms
128,768 KB
testcase_39 AC 369 ms
124,728 KB
testcase_40 AC 375 ms
124,928 KB
testcase_41 AC 380 ms
125,056 KB
testcase_42 AC 379 ms
124,672 KB
testcase_43 AC 376 ms
124,672 KB
testcase_44 WA -
testcase_45 AC 377 ms
124,928 KB
testcase_46 WA -
testcase_47 AC 218 ms
164,992 KB
testcase_48 AC 344 ms
128,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
n = 19
c = [0] * n
for i in range(n):
    que = na()
    for j in que[1:]:
        c[i] += 1<<j-1

dp = [0] * (1<<n)
dp[0] = 1
for i in range(n):
    ndp = [0] * (1<<n)
    ndp, dp = dp, ndp
    for j in range(1<<n):
        if ndp[j]==0:
            continue
        for k in range(n):
            if j >> k & 1:
                continue
            dp[j+(1<<k)] += ndp[j] * (c[i] >> k & 1)
from fractions import Fraction
#2D matrix

def add(x,y):
    return x + y

def mul(x, y):
    return x * y


def mat_add(A, B, replace=False):
    assert len(A)==len(B) and len(A[0]) == len(B[0])
    if not replace:
        A = [a.copy() for a in A]
    n = len(A)
    m = len(A[0])
    for i in range(n):
        for j in range(m):
            A[i][j] = add(A[i][j], B[i][j])
    return A


def mat_mul(A,B):
    assert len(A[0]) == len(B)
    n = len(A)
    m = len(B[0])
    p = len(A[0])
    R = [[0 for j in range(m)]for i in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(p):
                R[i][j] = add(R[i][j],mul(A[i][k],B[k][j]))
    return R

def mat_pow(A, x):
    assert len(A)==len(A[0])
    n = len(A)
    R = [[0 for j in range(n)]for i in range(n)]
    while x > 0:
        if x&1:
            R = mat_mul(R, A)
        A = mat_mul(A,A)
        x >>= 1
    return R


def determinant(A, replace=False):
    if not replace:
        A = [a.copy() for a in A]
    n = len(A)
    res = 1
    for i, a_i in enumerate(A):
        if a_i[i] == 0:
            for j in range(i+1, n):
                if A[j][i]:
                    break
            else:
                return 0
            A[i], A[j] = A[j], A[i]
            a_i = A[i]
            res = -res
        inv = 1/a_i[i]
        for j in range(i+1, n):
            a_j = A[j]
            t = a_j[i] * inv 
            for k in range(i+1, n):
                a_j[k] -= t * a_i[k]
    for i in range(n):
        res *= A[i][i]
    return res

def mat_pri(A):
    for i in A:
        print(*i)

def fractionize(A):
    for i in range(len(A)):
        for j in range(len(A[0])):
            A[i][j] = Fraction(A[i][j])

A = [[c[i]>>j&1 for j in range(n)]for i in range(n)]

D = determinant(A)
C = dp[-1]
print(int(C+D)//2,int(C-D)//2)
0