結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | mkawa2 |
提出日時 | 2021-12-09 09:15:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 598 ms / 2,000 ms |
コード長 | 2,034 bytes |
コンパイル時間 | 547 ms |
コンパイル使用メモリ | 87,184 KB |
実行使用メモリ | 79,156 KB |
最終ジャッジ日時 | 2023-09-23 19:36:45 |
合計ジャッジ時間 | 18,256 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 96 ms
76,468 KB |
testcase_01 | AC | 114 ms
77,304 KB |
testcase_02 | AC | 195 ms
77,932 KB |
testcase_03 | AC | 179 ms
77,556 KB |
testcase_04 | AC | 208 ms
77,992 KB |
testcase_05 | AC | 188 ms
78,120 KB |
testcase_06 | AC | 197 ms
78,096 KB |
testcase_07 | AC | 205 ms
78,072 KB |
testcase_08 | AC | 209 ms
78,212 KB |
testcase_09 | AC | 203 ms
78,328 KB |
testcase_10 | AC | 195 ms
77,872 KB |
testcase_11 | AC | 191 ms
78,100 KB |
testcase_12 | AC | 162 ms
77,828 KB |
testcase_13 | AC | 146 ms
77,268 KB |
testcase_14 | AC | 391 ms
78,740 KB |
testcase_15 | AC | 540 ms
78,964 KB |
testcase_16 | AC | 487 ms
78,644 KB |
testcase_17 | AC | 388 ms
78,672 KB |
testcase_18 | AC | 443 ms
78,656 KB |
testcase_19 | AC | 402 ms
78,828 KB |
testcase_20 | AC | 464 ms
78,808 KB |
testcase_21 | AC | 573 ms
78,692 KB |
testcase_22 | AC | 598 ms
78,944 KB |
testcase_23 | AC | 431 ms
78,652 KB |
testcase_24 | AC | 578 ms
78,800 KB |
testcase_25 | AC | 393 ms
78,848 KB |
testcase_26 | AC | 393 ms
78,456 KB |
testcase_27 | AC | 462 ms
78,696 KB |
testcase_28 | AC | 387 ms
78,780 KB |
testcase_29 | AC | 381 ms
78,784 KB |
testcase_30 | AC | 511 ms
79,044 KB |
testcase_31 | AC | 399 ms
79,156 KB |
testcase_32 | AC | 360 ms
78,508 KB |
testcase_33 | AC | 436 ms
78,828 KB |
testcase_34 | AC | 81 ms
75,600 KB |
testcase_35 | AC | 254 ms
77,672 KB |
testcase_36 | AC | 82 ms
75,604 KB |
testcase_37 | AC | 254 ms
77,840 KB |
testcase_38 | AC | 322 ms
78,488 KB |
testcase_39 | AC | 343 ms
78,296 KB |
testcase_40 | AC | 350 ms
78,500 KB |
testcase_41 | AC | 355 ms
78,440 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 18446744073709551615 # inf = 4294967295 # md = 10**9+7 # md = 998244353 md = 10**8+9 def dot(aa, bb): h = len(aa) w = len(bb[0]) res = [[0]*w for _ in range(h)] for i, row in enumerate(aa): for j, col in enumerate(zip(*bb)): v = -inf for a, b in zip(row, col): if a == -inf or b == -inf: continue cur = a+b if cur > v: v = cur res[i][j] = v return res def matpow(mat, e): n = len(mat) res = [[0 if i == j else -inf for j in range(n)] for i in range(n)] while e: if e & 1: res = dot(res, mat) mat = dot(mat, mat) e >>= 1 return res cc = LI1() kk = LI() n = II() ee = [[[-inf]*16 for _ in range(16)] for _ in range(26)] for f in range(26): for c in range(16): ee[f][c][c] = 0 for _ in range(n): s, a, b, e = SI().split() a = int1(a) b = int1(b) e = int(e) for f in s: f = ord(f)-65 ee[f][a][b] = ee[f][b][a] = max(ee[f][a][b], e) # p2D(ee) ss = [0]*16 for f in range(26): c = cc[f] eef = ee[f] eef = matpow(eef, kk[f]) # p2D(eef) for i, e in enumerate(eef[c]): if ss[i] == -inf: continue if e == -inf: ss[i] = -inf else: ss[i] += e # pDB(ss) ans = max(ss) if ans == -inf: ans = "Impossible" print(ans)