結果

問題 No.801 エレベーター
ユーザー TiramisterTiramister
提出日時 2019-03-17 23:29:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 736 ms / 2,000 ms
コード長 3,679 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 75,184 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-08 03:29:43
合計ジャッジ時間 12,699 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 9 ms
6,940 KB
testcase_04 AC 9 ms
6,940 KB
testcase_05 AC 8 ms
6,940 KB
testcase_06 AC 8 ms
6,944 KB
testcase_07 AC 9 ms
6,940 KB
testcase_08 AC 9 ms
6,940 KB
testcase_09 AC 9 ms
6,944 KB
testcase_10 AC 9 ms
6,940 KB
testcase_11 AC 9 ms
6,940 KB
testcase_12 AC 9 ms
6,940 KB
testcase_13 AC 736 ms
6,944 KB
testcase_14 AC 716 ms
6,940 KB
testcase_15 AC 714 ms
6,944 KB
testcase_16 AC 710 ms
6,944 KB
testcase_17 AC 711 ms
6,940 KB
testcase_18 AC 729 ms
6,940 KB
testcase_19 AC 722 ms
6,940 KB
testcase_20 AC 714 ms
6,944 KB
testcase_21 AC 721 ms
6,940 KB
testcase_22 AC 716 ms
6,944 KB
testcase_23 AC 666 ms
6,940 KB
testcase_24 AC 670 ms
6,940 KB
testcase_25 AC 719 ms
6,940 KB
testcase_26 AC 698 ms
6,940 KB
testcase_27 AC 675 ms
6,944 KB
testcase_28 AC 574 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

class ModInt {
    using ll = long long;

public:
    int value;
    static int MOD;

    ModInt(ll value = 0) {
        this->value = value % MOD;
        if (this->value < 0) this->value += MOD;
    }

    operator int() const noexcept { return this->value; }

    ModInt& operator=(const ModInt& x) {
        if (this != &x) { this->value = x.value; }
        return *this;
    }

    bool operator==(const ModInt& x) const { return this->value == x.value; }
    bool operator!=(const ModInt& x) const { return !(*this == x); }

    ModInt operator+() const { return value; }
    ModInt operator-() const { return MOD - value; }
    ModInt operator~() const { return (*this) ^ ModInt(MOD - 2); }

    ModInt operator++() { return *this += 1; }
    ModInt operator--() { return *this -= 1; }

    ModInt operator++(int) {
        ModInt before = *this;
        ++(*this);
        return before;
    }
    ModInt operator--(int) {
        ModInt before = *this;
        --(*this);
        return before;
    }

    ModInt operator+=(const ModInt& x) {
        int sum = this->value + x.value;
        return *this = (sum < MOD ? sum : sum - MOD);
    }
    ModInt operator-=(const ModInt& x) {
        int diff = this->value - x.value;
        return *this = (diff >= 0 ? diff : diff + MOD);
    }
    ModInt operator*=(const ModInt& x) { return *this = ll(this->value) * ll(x.value) % MOD; }
    ModInt operator/=(const ModInt& x) { return *this = (this->value % x.value == 0 ? ModInt(this->value / x.value) : *this * ~x); }

    ModInt operator+=(const int& x) {
        int sum = this->value + x;
        return *this = (sum < MOD ? sum : sum - MOD);
    }
    ModInt operator-=(const int& x) {
        int diff = this->value - x;
        return *this = (diff >= 0 ? diff : diff + MOD);
    }
    ModInt operator*=(const int& x) { return *this = ll(this->value) * ll(x) % MOD; }
    ModInt operator/=(const int& x) { return *this = (this->value % x == 0 ? ModInt(this->value / x) : *this * ~ModInt(x)); }

    template <class T>
    ModInt operator^=(const T& x) {
        int n = int(x);
        if (n == 0) return ModInt(1);
        if (n & 1) {
            return (*this) = ((*this) ^ ModInt(n - 1)) * (*this);
        } else {
            return (*this) = ((*this) * (*this)) ^ ModInt(n / 2);
        }
    }

    template <class T>
    ModInt operator+(const T& b) const { return ModInt(*this) += b; }
    template <class T>
    ModInt operator-(const T& b) const { return ModInt(*this) -= b; }
    template <class T>
    ModInt operator*(const T& b) const { return ModInt(*this) *= b; }
    template <class T>
    ModInt operator/(const T& b) const { return ModInt(*this) /= b; }
    template <class T>
    ModInt operator^(const T& b) const { return ModInt(*this) ^= b; }
};

int ModInt::MOD = 1000000007;

ostream& operator<<(ostream& os, const ModInt& x) { return os << x.value; }
istream& operator>>(istream& is, ModInt& x) { return is >> x.value; }

int main() {
    int N, M, K;
    cin >> N >> M >> K;

    vector<int> L(M), R(M);
    for (int i = 0; i < M; ++i) cin >> L[i] >> R[i];

    vector<ModInt> dp(N + 2, 0);
    dp[1] = 1;

    for (int k = 0; k < K; ++k) {
        for (int i = 1; i <= N; ++i) {
            dp[i] += dp[i - 1];
        }

        vector<ModInt> ndp(N + 2, 0);
        for (int i = 0; i < M; ++i) {
            ModInt add = dp[R[i]] - dp[L[i] - 1];
            ndp[L[i]] += add;
            ndp[R[i] + 1] -= add;
        }
        for (int i = 1; i <= N; ++i) {
            ndp[i] += ndp[i - 1];
        }
        dp = ndp;
    }

    cout << dp[N] << endl;
    return 0;
}
0