結果

問題 No.801 エレベーター
ユーザー TiramisterTiramister
提出日時 2019-03-18 02:42:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 861 ms / 2,000 ms
コード長 3,608 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 74,964 KB
実行使用メモリ 38,708 KB
最終ジャッジ日時 2023-09-22 16:39:06
合計ジャッジ時間 15,214 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 10 ms
4,376 KB
testcase_04 AC 10 ms
4,380 KB
testcase_05 AC 10 ms
4,380 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 10 ms
4,380 KB
testcase_13 AC 857 ms
38,708 KB
testcase_14 AC 859 ms
38,400 KB
testcase_15 AC 858 ms
38,160 KB
testcase_16 AC 861 ms
38,100 KB
testcase_17 AC 859 ms
38,140 KB
testcase_18 AC 857 ms
38,160 KB
testcase_19 AC 856 ms
38,148 KB
testcase_20 AC 856 ms
38,216 KB
testcase_21 AC 857 ms
38,456 KB
testcase_22 AC 860 ms
38,084 KB
testcase_23 AC 797 ms
38,148 KB
testcase_24 AC 796 ms
38,084 KB
testcase_25 AC 796 ms
38,100 KB
testcase_26 AC 798 ms
38,412 KB
testcase_27 AC 796 ms
38,220 KB
testcase_28 AC 668 ms
38,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

template <class T>
vector<T> Vec(size_t l, T v) { return vector<T>(l, v); }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

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;
    }

    template <class T>
    ModInt operator+=(const T& x) {
        int sum = this->value + int(x);
        return *this = (sum < MOD ? sum : sum - MOD);
    }
    template <class T>
    ModInt operator-=(const T& x) {
        int diff = this->value - int(x);
        return *this = (diff >= 0 ? diff : diff + MOD);
    }
    template <class T>
    ModInt operator*=(const T& x) { return *this = ll(this->value) * ll(int(x)) % MOD; }
    template <class T>
    ModInt operator/=(const T& x) { return *this = (this->value % int(x) == 0 ? ModInt(this->value / int(x)) : *this * ~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];

    // dp[i][j] = i回移動した時点で、j階にいるようなパターン数
    auto dp = Vec<ModInt>(K + 1, N + 2, ModInt(0));
    dp[0][1] = 1;

    for (int i = 0; i < K; ++i) {
        // 累積和
        for (int j = 1; j <= N; ++j) {
            dp[i][j] += dp[i][j - 1];
        }

        for (int k = 0; k < M; ++k) {
            ModInt add = dp[i][R[k]] - dp[i][L[k] - 1];
            dp[i + 1][L[k]] += add;
            dp[i + 1][R[k] + 1] -= add;
        }

        // imos法の精算
        for (int j = 1; j <= N; ++j) {
            dp[i + 1][j] += dp[i + 1][j - 1];
        }
    }

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