結果

問題 No.1111 コード進行
ユーザー xuanji
提出日時 2020-07-10 22:33:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 82,080 KB
実行使用メモリ 288,908 KB
最終ジャッジ日時 2024-10-11 09:54:12
合計ジャッジ時間 16,360 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27 WA * 5 RE * 2 TLE * 4 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

from collections import defaultdict

from sys import stdin, stdout
 
def input():
    return stdin.readline().strip()

N, M, K = input().split(' ')
N = int(N)
M = int(M)
K = int(K)

from functools import lru_cache

@lru_cache(None)
def ans(length, last, target):
    # how many length-`length` progressions are there with last chord `last` and complexity `target`
    if length == 1:
        if target == 0: return 1
        return 0
    if target < 0: return 0

    ret = 0
    for (prev, cost) in neighbours[last]:
        ret += ans(length-1, prev, target-cost)
    return ret

neighbours = defaultdict(set)

for _ in range(M):
    P, Q, C = input().split(' ')
    P = int(P)
    Q = int(Q)
    C = int(C)

    neighbours[Q].add((P, C))

ret = sum(ans(N, v, K) for v in range(1, M+1))

MODULUS = 10**9+7
if ret >= MODULUS:
    assert(False)
else:
    print(ret)
0