結果

問題 No.30 たこやき工場
ユーザー roarisroaris
提出日時 2019-08-25 22:23:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 8,360 KB
最終ジャッジ日時 2023-08-23 05:21:18
合計ジャッジ時間 1,360 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,776 KB
testcase_01 AC 17 ms
7,832 KB
testcase_02 AC 17 ms
7,948 KB
testcase_03 AC 16 ms
7,848 KB
testcase_04 AC 16 ms
7,856 KB
testcase_05 AC 16 ms
7,860 KB
testcase_06 AC 17 ms
7,788 KB
testcase_07 AC 17 ms
7,772 KB
testcase_08 AC 17 ms
7,804 KB
testcase_09 AC 20 ms
8,288 KB
testcase_10 AC 37 ms
8,280 KB
testcase_11 AC 17 ms
7,892 KB
testcase_12 AC 16 ms
7,792 KB
testcase_13 AC 16 ms
7,808 KB
testcase_14 AC 17 ms
8,360 KB
testcase_15 AC 17 ms
7,856 KB
testcase_16 AC 17 ms
8,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

#iを1個作るのに必要なjの数
def rec(i, j):
    if memo[i][j] != -1:
        return memo[i][j]
    
    if len(adj_list[i]) == 0:
        if i == j:
            memo[i][j] = 1
            return 1
        else:
            memo[i][j] = 0
            return 0
    
    res = 0
    
    for next_node, w in adj_list[i]:
        res += w * rec(next_node, j)
    
    memo[i][j] = res
    
    return res

N = int(input())
M = int(input())
adj_list = [[] for _ in range(N)]

for _ in range(M):
    Pi, Qi, Ri = map(int, input().split())
    adj_list[Ri-1].append((Pi-1, Qi))

memo = [[-1 for _ in range(N)] for _ in range(N)]

for i in range(N-1):
    print(rec(N-1, i))
0