結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | mkawa2 |
提出日時 | 2021-12-09 09:15:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 496 ms / 2,000 ms |
コード長 | 2,034 bytes |
コンパイル時間 | 382 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 77,576 KB |
最終ジャッジ日時 | 2024-07-16 19:26:02 |
合計ジャッジ時間 | 12,976 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
67,800 KB |
testcase_01 | AC | 78 ms
75,848 KB |
testcase_02 | AC | 150 ms
76,828 KB |
testcase_03 | AC | 141 ms
76,416 KB |
testcase_04 | AC | 159 ms
76,728 KB |
testcase_05 | AC | 142 ms
76,672 KB |
testcase_06 | AC | 149 ms
77,056 KB |
testcase_07 | AC | 154 ms
76,700 KB |
testcase_08 | AC | 153 ms
76,756 KB |
testcase_09 | AC | 152 ms
77,576 KB |
testcase_10 | AC | 146 ms
77,012 KB |
testcase_11 | AC | 141 ms
76,692 KB |
testcase_12 | AC | 123 ms
76,272 KB |
testcase_13 | AC | 107 ms
76,116 KB |
testcase_14 | AC | 297 ms
77,284 KB |
testcase_15 | AC | 426 ms
76,868 KB |
testcase_16 | AC | 385 ms
77,344 KB |
testcase_17 | AC | 271 ms
76,944 KB |
testcase_18 | AC | 338 ms
77,172 KB |
testcase_19 | AC | 290 ms
76,892 KB |
testcase_20 | AC | 355 ms
77,264 KB |
testcase_21 | AC | 473 ms
77,244 KB |
testcase_22 | AC | 496 ms
77,184 KB |
testcase_23 | AC | 319 ms
77,204 KB |
testcase_24 | AC | 472 ms
76,996 KB |
testcase_25 | AC | 297 ms
76,964 KB |
testcase_26 | AC | 295 ms
76,748 KB |
testcase_27 | AC | 352 ms
77,020 KB |
testcase_28 | AC | 284 ms
76,868 KB |
testcase_29 | AC | 280 ms
76,984 KB |
testcase_30 | AC | 413 ms
76,948 KB |
testcase_31 | AC | 297 ms
77,036 KB |
testcase_32 | AC | 269 ms
76,812 KB |
testcase_33 | AC | 340 ms
76,696 KB |
testcase_34 | AC | 42 ms
61,400 KB |
testcase_35 | AC | 211 ms
76,852 KB |
testcase_36 | AC | 42 ms
60,496 KB |
testcase_37 | AC | 211 ms
76,300 KB |
testcase_38 | AC | 241 ms
76,492 KB |
testcase_39 | AC | 256 ms
76,748 KB |
testcase_40 | AC | 256 ms
77,156 KB |
testcase_41 | AC | 268 ms
76,668 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)