結果

問題 No.801 エレベーター
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-29 14:41:50
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,396 bytes
コンパイル時間 454 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 86,064 KB
最終ジャッジ日時 2023-09-08 00:16:29
合計ジャッジ時間 36,193 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,504 KB
testcase_01 AC 66 ms
71,256 KB
testcase_02 AC 67 ms
71,464 KB
testcase_03 AC 135 ms
77,648 KB
testcase_04 AC 124 ms
77,420 KB
testcase_05 AC 123 ms
77,720 KB
testcase_06 AC 123 ms
77,208 KB
testcase_07 AC 133 ms
77,776 KB
testcase_08 AC 130 ms
77,728 KB
testcase_09 AC 123 ms
77,412 KB
testcase_10 AC 131 ms
77,824 KB
testcase_11 AC 134 ms
77,708 KB
testcase_12 AC 123 ms
77,336 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,710 ms
84,056 KB
testcase_24 AC 1,772 ms
84,224 KB
testcase_25 AC 1,785 ms
84,204 KB
testcase_26 AC 1,872 ms
84,092 KB
testcase_27 AC 1,746 ms
84,404 KB
testcase_28 AC 1,762 ms
84,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def main2(n,m,k,lr):
  mod=10**9+7
  lr.sort(key=lambda x:x[0])
  lrr=[[l,r] for l,r in lr]
  lrr.sort(key=lambda x:x[1],reverse=True)
  dp=[0]*(n+1)
  dp[1]=1
  mat=[[0,0] for _ in range(n+1)]
  for _ in range(k):
    ndp=[0]*(n+1)
    sdp=[0]
    for x in dp:sdp.append((sdp[-1]+x)%mod)
    # 下からの遷移。同じ階の移動も含む
    idx=0
    now=0
    cnt=0
    for j in range(1,n+1):
      # j階への遷移
      while idx<m and lr[idx][0]==j:
        l,r=lr[idx]
        idx+=1
        cnt+=1
        mat[r][0]+=sdp[r+1]-sdp[l]
        mat[r][1]+=1
      now+=cnt*dp[j]
      now%=mod
      ndp[j]+=now
      ndp[j]%=mod
      now-=mat[j][0]
      now%=mod
      cnt-=mat[j][1]
      mat[j][0]=0
      mat[j][1]=0
    # 上からの遷移。同じ階の移動は含まない
    now=0
    cnt=0
    idx=0
    for j in reversed(range(1,n+1)):
      # j階への遷移
      while idx<m and lrr[idx][1]==j:
        l,r=lrr[idx]
        idx+=1
        cnt+=1
        mat[l][0]+=sdp[r+1]-sdp[l]
        mat[l][1]+=1
      ndp[j]+=now
      ndp[j]%=mod
      now+=cnt*dp[j]
      now-=mat[j][0]
      now%=mod
      cnt-=mat[j][1]
      mat[j][0]=0
      mat[j][1]=0
    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