結果
問題 |
No.801 エレベーター
|
ユーザー |
|
提出日時 | 2021-06-29 14:41:50 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,396 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 84,332 KB |
最終ジャッジ日時 | 2024-06-25 17:32:04 |
合計ジャッジ時間 | 34,732 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 TLE * 10 |
ソースコード
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)