結果

問題 No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木
ユーザー 👑 tamatotamato
提出日時 2021-12-09 00:51:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 458 ms / 2,000 ms
コード長 1,596 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 87,660 KB
実行使用メモリ 81,972 KB
最終ジャッジ日時 2023-09-23 12:11:26
合計ジャッジ時間 16,390 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 273 ms
78,956 KB
testcase_01 AC 271 ms
78,472 KB
testcase_02 AC 331 ms
79,124 KB
testcase_03 AC 292 ms
79,864 KB
testcase_04 AC 373 ms
79,508 KB
testcase_05 AC 341 ms
80,968 KB
testcase_06 AC 364 ms
79,936 KB
testcase_07 AC 302 ms
79,940 KB
testcase_08 AC 342 ms
79,428 KB
testcase_09 AC 363 ms
80,332 KB
testcase_10 AC 308 ms
80,320 KB
testcase_11 AC 327 ms
79,584 KB
testcase_12 AC 344 ms
81,972 KB
testcase_13 AC 278 ms
79,124 KB
testcase_14 AC 251 ms
79,136 KB
testcase_15 AC 392 ms
79,476 KB
testcase_16 AC 383 ms
79,136 KB
testcase_17 AC 271 ms
79,288 KB
testcase_18 AC 297 ms
79,108 KB
testcase_19 AC 248 ms
79,568 KB
testcase_20 AC 318 ms
79,036 KB
testcase_21 AC 433 ms
79,348 KB
testcase_22 AC 458 ms
79,224 KB
testcase_23 AC 279 ms
79,888 KB
testcase_24 AC 442 ms
79,448 KB
testcase_25 AC 254 ms
79,180 KB
testcase_26 AC 250 ms
79,348 KB
testcase_27 AC 303 ms
79,412 KB
testcase_28 AC 243 ms
78,880 KB
testcase_29 AC 231 ms
79,048 KB
testcase_30 AC 378 ms
79,200 KB
testcase_31 AC 234 ms
79,084 KB
testcase_32 AC 235 ms
78,980 KB
testcase_33 AC 291 ms
78,972 KB
testcase_34 AC 253 ms
78,452 KB
testcase_35 AC 272 ms
78,816 KB
testcase_36 AC 253 ms
78,164 KB
testcase_37 AC 274 ms
78,632 KB
testcase_38 AC 314 ms
79,244 KB
testcase_39 AC 365 ms
78,812 KB
testcase_40 AC 297 ms
78,832 KB
testcase_41 AC 304 ms
78,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9
inf = 10 ** 30


def main():
    import sys
    input = sys.stdin.readline

    C = list(map(int, input().split()))
    K = list(map(int, input().split()))
    N = int(input())
    D_list = [[[-inf] * 17 for _ in range(17)] for _ in range(26)]
    for i in range(26):
        for v in range(17):
            D_list[i][v][v] = 0
    for _ in range(N):
        S, A, B, E = input().split()
        A = int(A)
        B = int(B)
        E = int(E)
        for s in S:
            i = ord(s) - 65
            D_list[i][A][B] = max(D_list[i][A][B], E)
            D_list[i][B][A] = max(D_list[i][B][A], E)

    cost = [0] * 17
    cost[0] = -inf
    for i in range(26):
        D = D_list[i]
        DD = [None] * 25
        DD[0] = D
        for lv in range(1, 25):
            DD[lv] = [[-inf] * 17 for _ in range(17)]
            for u in range(1, 17):
                for v in range(1, 17):
                    for w in range(1, 17):
                        DD[lv][u][v] = max(DD[lv][u][v], DD[lv - 1][u][w] + DD[lv - 1][w][v])
        dist = [-inf] * 17
        dist[C[i]] = 0
        for lv in range(25):
            if K[i] >> lv & 1:
                dist_new = [-inf] * 17
                for u in range(17):
                    for v in range(17):
                        dist_new[v] = max(dist_new[v], dist[u] + DD[lv][u][v])
                dist = dist_new
        for j in range(1, 17):
            cost[j] += dist[j]
    ans = max(cost)
    if ans < -10 ** 20:
        print("Impossible")
    else:
        print(ans)


if __name__ == '__main__':
    main()
0