結果

問題 No.2310 [Cherry 5th Tune A] Against Regret
ユーザー miho-4
提出日時 2023-05-19 23:51:12
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 657 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 1,686,768 KB
最終ジャッジ日時 2024-12-20 02:59:49
合計ジャッジ時間 195,085 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 1 TLE * 8 MLE * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import heapq
mod=998244353
n=int(input())
E=[list(map(int,input().split())) for _ in range(n+1)]
Q=int(input())
for _ in range(Q):
  K=int(input())
  d=dict()
  for _ in range(K):
    a,b,c=map(int,input().split())
    if (a,b) not in d:
      d[(a,b)]=c
    else:
      d[(a,b)]+=c
#  print("d=",d)
  tmp=[0]*(n+1)
  tmp[0]=1
  q=[]
  heapq.heappush(q,0)
  while q:
    x=heapq.heappop(q)
    for i in range(x,n+1):
      if (x,i) in d:
        tmp[i]+=tmp[x]*d[(x,i)]
        tmp[i]%=mod
        heapq.heappush(q,i)
      if E[x][i]:
        tmp[i]+=tmp[x]
        tmp[i]%=mod
        heapq.heappush(q,i)
  print(tmp[-1]%mod)
0