結果

問題 No.801 エレベーター
ユーザー terasaterasa
提出日時 2022-06-03 10:30:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,029 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 81,976 KB
最終ジャッジ日時 2023-10-21 01:26:16
合計ジャッジ時間 4,578 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,848 KB
testcase_01 AC 59 ms
66,188 KB
testcase_02 AC 60 ms
66,224 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


class Matpow:
    def __init__(self, N, A, p):
        self.N = N
        self.A = A
        self.p = p
        self.digit = 60
        self.doubling = [None] * self.digit

        self.doubling[0] = A
        for i in range(1, self.digit):
            self.doubling[i] = self.mul(self.doubling[i - 1], self.doubling[i - 1])

    def pow(self, n):
        E = [[1 if i == j else 0 for j in range(self.N)] for i in range(self.N)]
        acc = E
        for k in range(self.digit):
            if n & (1 << k):
                acc = self.mul(acc, self.doubling[k])
        return acc

    def mul(self, A, B):
        C = [[0 for _ in range(self.N)] for _ in range(self.N)]
        for i in range(self.N):
            for j in range(self.N):
                for k in range(self.N):
                    C[i][j] += A[i][k] * B[k][j]
                    C[i][j] %= self.p
        return C


N, M, K = map(int, input().split())
mod = 10 ** 9 + 7

A = [[0 for _ in range(N)] for _ in range(N)]
for _ in range(M):
    l, r = map(int, input().split())
    l -= 1
    for i in range(l, r):
        A[i][l] += 1
        if r < N:
            A[i][r] -= 1
for i in range(N):
    for j in range(1, N):
        A[i][j] += A[i][j - 1]

Ak = Matpow(N, A, mod).pow(K)
print(Ak[0][N - 1])
0