結果

問題 No.770 Median Sequence
ユーザー square1001square1001
提出日時 2019-03-27 19:07:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,122 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 76,328 KB
実行使用メモリ 106,400 KB
最終ジャッジ日時 2024-04-19 10:03:26
合計ジャッジ時間 5,801 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 151 ms
6,912 KB
testcase_09 AC 920 ms
14,848 KB
testcase_10 AC 174 ms
7,296 KB
testcase_11 AC 33 ms
5,376 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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) {
		for (int j = 0; j < N; ++j) {
			dp1[i][j] = st1[i][j];
			for (int k = 0; k < j; ++k) {
				dp1[i][j] += dp2[i - 1][k];
			}
			dp2[i][j] += dp2[i - 1][j];
			if (j + 1 < N) {
				dp2[i][j] += dp2[i - 1][j + 1];
				for (int k = 0; k <= i - (N - j - 1); ++k) {
					dp2[i][j] += dp1[k][j + 1];
				}
			}
			st1[i + 1][j + 1] = st1[i + 1][j] + st1[i][j + 1] - st1[i][j] + dp1[i][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;
}
0