結果
問題 |
No.1111 コード進行
|
ユーザー |
|
提出日時 | 2020-07-10 22:38:30 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 852 bytes |
コンパイル時間 | 406 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 288,816 KB |
最終ジャッジ日時 | 2024-10-11 13:20:30 |
合計ジャッジ時間 | 12,694 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 TLE * 4 -- * 10 |
ソースコード
#!/usr/bin/env python3 MODULUS = 10**9+7 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, 301)) print(ret % MODULUS)