結果

問題 No.801 エレベーター
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-29 15:11:55
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,192 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 86,936 KB
実行使用メモリ 83,456 KB
最終ジャッジ日時 2023-09-08 00:49:37
合計ジャッジ時間 22,148 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,076 KB
testcase_01 AC 69 ms
71,228 KB
testcase_02 AC 69 ms
71,232 KB
testcase_03 AC 98 ms
77,224 KB
testcase_04 AC 98 ms
77,068 KB
testcase_05 AC 98 ms
77,160 KB
testcase_06 AC 97 ms
77,284 KB
testcase_07 AC 97 ms
77,316 KB
testcase_08 AC 97 ms
77,108 KB
testcase_09 AC 99 ms
77,160 KB
testcase_10 AC 96 ms
77,052 KB
testcase_11 AC 97 ms
77,248 KB
testcase_12 AC 98 ms
77,424 KB
testcase_13 AC 1,184 ms
83,064 KB
testcase_14 AC 1,184 ms
83,240 KB
testcase_15 AC 1,184 ms
83,308 KB
testcase_16 AC 1,179 ms
83,456 KB
testcase_17 AC 1,183 ms
83,284 KB
testcase_18 AC 1,183 ms
83,148 KB
testcase_19 AC 1,189 ms
83,276 KB
testcase_20 AC 1,181 ms
83,176 KB
testcase_21 AC 1,186 ms
82,872 KB
testcase_22 AC 1,188 ms
82,880 KB
testcase_23 AC 1,192 ms
83,268 KB
testcase_24 AC 1,177 ms
83,248 KB
testcase_25 AC 1,174 ms
83,284 KB
testcase_26 AC 1,181 ms
83,196 KB
testcase_27 AC 1,184 ms
83,072 KB
testcase_28 AC 1,176 ms
83,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def main2(n,m,k,lr):
  mod=10**9+7
  dp=[0]*(n+1)
  dp[1]=1
  now=0
  cnt_ary=[0]*(n+1)
  for l,r in lr:
    cnt_ary[l]+=1
    if r!=n:cnt_ary[r+1]-=1
  for i in range(n):cnt_ary[i+1]+=cnt_ary[i]
  for _ in range(k):
    ndp=[0]*(n+1)
    sdp=[0]
    for x in dp:sdp.append((sdp[-1]+x)%mod)
    mat0=[0]*(n+1)
    mat1=[0]*(n+1)
    for l,r in lr:
      mat0[r]+=sdp[r+1]-sdp[l]
      mat1[l]+=sdp[r+1]-sdp[l]

    # 下からの遷移。同じ階の移動も含む
    for j in range(1,n+1):
      # j階への遷移
      now+=cnt_ary[j]*dp[j]
      now%=mod
      ndp[j]+=now
      ndp[j]%=mod
      now-=mat0[j]
      now%=mod
    # 上からの遷移。同じ階の移動は含まない
    for j in reversed(range(1,n+1)):
      # j階への遷移
      ndp[j]+=now
      ndp[j]%=mod
      now+=cnt_ary[j]*dp[j]
      now-=mat1[j]
      now%=mod
    dp=ndp
  return dp[n]

if __name__=='__main__':
  n,m,k=map(int,input().split())
  lr=[list(map(int,input().split())) for _ in range(m)]
  ret2=main2(n,m,k,lr)
  print(ret2)
0