結果
問題 | No.2152 [Cherry Anniversary 2] 19 Petals of Cherry |
ユーザー | tassei903 |
提出日時 | 2022-12-09 20:00:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 411 ms / 1,000 ms |
コード長 | 2,603 bytes |
コンパイル時間 | 345 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 165,616 KB |
最終ジャッジ日時 | 2024-10-14 18:49:45 |
合計ジャッジ時間 | 18,629 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 223 ms
165,124 KB |
testcase_01 | AC | 249 ms
164,416 KB |
testcase_02 | AC | 218 ms
165,616 KB |
testcase_03 | AC | 361 ms
129,004 KB |
testcase_04 | AC | 309 ms
159,184 KB |
testcase_05 | AC | 396 ms
125,248 KB |
testcase_06 | AC | 319 ms
160,128 KB |
testcase_07 | AC | 329 ms
145,524 KB |
testcase_08 | AC | 361 ms
128,640 KB |
testcase_09 | AC | 278 ms
162,588 KB |
testcase_10 | AC | 373 ms
126,904 KB |
testcase_11 | AC | 305 ms
157,824 KB |
testcase_12 | AC | 268 ms
162,776 KB |
testcase_13 | AC | 312 ms
158,976 KB |
testcase_14 | AC | 331 ms
145,152 KB |
testcase_15 | AC | 335 ms
140,928 KB |
testcase_16 | AC | 328 ms
137,148 KB |
testcase_17 | AC | 361 ms
129,152 KB |
testcase_18 | AC | 355 ms
128,640 KB |
testcase_19 | AC | 345 ms
132,608 KB |
testcase_20 | AC | 258 ms
164,476 KB |
testcase_21 | AC | 390 ms
126,648 KB |
testcase_22 | AC | 315 ms
159,688 KB |
testcase_23 | AC | 312 ms
158,592 KB |
testcase_24 | AC | 387 ms
125,664 KB |
testcase_25 | AC | 361 ms
128,640 KB |
testcase_26 | AC | 335 ms
141,344 KB |
testcase_27 | AC | 309 ms
157,872 KB |
testcase_28 | AC | 241 ms
164,988 KB |
testcase_29 | AC | 248 ms
164,300 KB |
testcase_30 | AC | 250 ms
164,596 KB |
testcase_31 | AC | 251 ms
164,552 KB |
testcase_32 | AC | 254 ms
164,052 KB |
testcase_33 | AC | 260 ms
162,464 KB |
testcase_34 | AC | 283 ms
161,220 KB |
testcase_35 | AC | 300 ms
159,032 KB |
testcase_36 | AC | 324 ms
157,780 KB |
testcase_37 | AC | 356 ms
132,788 KB |
testcase_38 | AC | 372 ms
128,876 KB |
testcase_39 | AC | 385 ms
124,836 KB |
testcase_40 | AC | 394 ms
124,944 KB |
testcase_41 | AC | 398 ms
124,696 KB |
testcase_42 | AC | 406 ms
124,836 KB |
testcase_43 | AC | 411 ms
124,864 KB |
testcase_44 | AC | 403 ms
125,172 KB |
testcase_45 | AC | 376 ms
124,516 KB |
testcase_46 | AC | 401 ms
124,640 KB |
testcase_47 | AC | 217 ms
165,428 KB |
testcase_48 | AC | 371 ms
128,768 KB |
ソースコード
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 = [[Fraction(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)