結果
| 問題 | No.770 Median Sequence | 
| コンテスト | |
| ユーザー |  square1001 | 
| 提出日時 | 2019-03-27 19:13:57 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 218 ms / 2,000 ms | 
| コード長 | 2,105 bytes | 
| コンパイル時間 | 697 ms | 
| コンパイル使用メモリ | 74,976 KB | 
| 実行使用メモリ | 109,056 KB | 
| 最終ジャッジ日時 | 2024-10-11 02:24:35 | 
| 合計ジャッジ時間 | 2,806 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 | 
ソースコード
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT
#include <cstdint>
template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};
#endif // ___CLASS_MODINT
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
using modulo = modint<1000000007>;
int main() {
	int N;
	cin >> N;
	vector<vector<modulo> > dp1(N, vector<modulo>(N));
	vector<vector<modulo> > dp2(N, vector<modulo>(N));
	vector<vector<modulo> > st1(N + 1, vector<modulo>(N + 1));
	for (int i = 0; i < N; ++i) dp1[0][i] = 1, st1[1][i + 1] = i + 1;
	for (int i = 1; i < N; ++i) {
		modulo sum = 0;
		for (int j = 0; j < N; ++j) {
			dp1[i][j] = st1[i][j] + sum;
			dp2[i][j] += dp2[i - 1][j];
			if (j + 1 < N) {
				dp2[i][j] += dp2[i - 1][j + 1];
				if (i + j + 2 >= N) dp2[i][j] += st1[i + j - N + 2][j + 2] - st1[i + j - N + 2][j + 1];
			}
			st1[i + 1][j + 1] = st1[i + 1][j] + st1[i][j + 1] - st1[i][j] + dp1[i][j];
			sum += dp2[i - 1][j];
		}
	}
	modulo ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			ans += dp1[i][j];
		}
	}
	for (int i = 0; i < N; ++i) {
		ans += dp2[N - 1][i];
	}
	cout << ans.get() << endl;
	return 0;
}
            
            
            
        