結果

問題 No.801 エレベーター
ユーザー aa
提出日時 2019-03-17 23:46:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,904 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 170,540 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 15:37:26
合計ジャッジ時間 3,675 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

template <int p>
struct Modint
{
	int value;

	Modint() : value(0) {}
	Modint(long x) : value(x >= 0 ? x % p : (p + x % p) % p) {}

	inline Modint &operator+=(const Modint &b)
	{
		if ((this->value += b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator-=(const Modint &b)
	{
		if ((this->value += p - b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator*=(const Modint &b)
	{
		this->value = (int)((1LL * this->value * b.value) % p);
		return (*this);
	}
	inline Modint &operator/=(const Modint &b)
	{
		(*this) *= b.inverse();
		return (*this);
	}

	Modint operator+(const Modint &b) const { return Modint(*this) += b; }
	Modint operator-(const Modint &b) const { return Modint(*this) -= b; }
	Modint operator*(const Modint &b) const { return Modint(*this) *= b; }
	Modint operator/(const Modint &b) const { return Modint(*this) /= b; }

	inline Modint &operator++(int) { return (*this) += 1; }
	inline Modint &operator--(int) { return (*this) -= 1; }

	inline bool operator==(const Modint &b) const { return this->value == b.value; }
	inline bool operator!=(const Modint &b) const { return this->value != b.value; }
	inline bool operator<(const Modint &b) const { return this->value < b.value; }
	inline bool operator<=(const Modint &b) const { return this->value <= b.value; }
	inline bool operator>(const Modint &b) const { return this->value > b.value; }
	inline bool operator>=(const Modint &b) const { return this->value >= b.value; }

	//requires that "this->value and p are co-prime"
	// a_i * v + a_(i+1) * p = r_i
	// r_i = r_(i+1) * q_(i+1) * r_(i+2)
	// q == 1 (i > 1)
	// reference: https://atcoder.jp/contests/agc026/submissions/2845729 (line:93)
	inline Modint inverse() const
	{
		assert(this->value != 0);
		int r0 = p, r1 = this->value, a0 = 0, a1 = 1;
		while (r1)
		{
			int q = r0 / r1;
			r0 -= q * r1;
			swap(r0, r1);
			a0 -= q * a1;
			swap(a0, a1);
		}
		return Modint(a0);
	}

	friend istream &operator>>(istream &is, Modint<p> &a)
	{
		long t;
		is >> t;
		a = Modint<p>(t);
		return is;
	}
	friend ostream &operator<<(ostream &os, const Modint<p> &a)
	{
		return os << a.value;
	}
};

const int MOD = 1e9 + 7;

using Int = Modint<MOD>;

void solve()
{
	int n, m, k;
	cin >> n >> m >> k;
	vector<Int> dp(n+1);
	vector<int> ls(m), rs(m);
	for (int i = 0; i < m; i++)
	{
		cin >> ls[i] >> rs[i];
		ls[i]--, rs[i]--;
	}
	dp[0] = 1;
	while (k--)
	{
		vector<Int> nx(n+1), acc(n+1);
		for (int i = 0; i < n; i++)
		{
			acc[i + 1] = acc[i] + dp[i];
		}
		for (int i = 0; i < m; i++)
		{
			int l = ls[i], r = rs[i];
			Int x = acc[r + 1] - acc[l];
			nx[r + 1] -= x;
			nx[l] += x;
		}
		for (int i = 0; i < n; i++)
		{
			nx[i + 1] += nx[i];
		}
		swap(dp, nx);
	}
	cout << dp[n-1] << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0