結果
問題 | No.963 門松列列(2) |
ユーザー | noshi91 |
提出日時 | 2019-12-12 22:12:52 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,579 bytes |
コンパイル時間 | 564 ms |
コンパイル使用メモリ | 118,656 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-11-30 15:56:56 |
合計ジャッジ時間 | 21,308 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | TLE | - |
testcase_06 | WA | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
ソースコード
#include <cstdint> namespace n91 { constexpr std::uint_fast64_t totient(std::uint_fast64_t x) noexcept { using u64 = std::uint_fast64_t; u64 ret = x; for (u64 i = static_cast<u64>(2); i * i <= x; ++i) { if (x % i == static_cast<u64>(0)) { ret -= ret / i; x /= i; while (x % i == static_cast<u64>(0)) { x /= i; } } } if (x != static_cast<u64>(1)) { ret -= ret / x; } return ret; } template <std::uint_fast64_t Modulus, std::uint_fast64_t InverseExp = totient(Modulus) - 1> class modint { using u64 = std::uint_fast64_t; static_assert(Modulus < static_cast<u64>(1) << 32, "Modulus must be less than 2**32"); u64 a; constexpr modint &negate() noexcept { if (a != 0) { a = mod - a; } return *this; } public: using value_type = u64; static constexpr u64 mod = Modulus; constexpr modint(const u64 x = 0) noexcept : a(x % mod) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+() const noexcept { return modint(*this); } constexpr modint operator-() const noexcept { return modint(*this).negate(); } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= mod) { a -= mod; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += mod; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % mod; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = InverseExp; while (exp) { if (exp % 2 != 0) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } constexpr bool operator==(const modint rhs) const noexcept { return a == rhs.a; } constexpr bool operator!=(const modint rhs) const noexcept { return a != rhs.a; } }; template <std::uint_fast64_t Modulus, std::uint_fast64_t InverseExp> constexpr typename modint<Modulus, InverseExp>::u64 modint<Modulus, InverseExp>::mod; template <class T, std::uint_fast64_t v> class modint_constant { public: static constexpr T value = static_cast<T>(v); using value_type = T; }; template <class T, std::uint_fast64_t v> constexpr T modint_constant<T, v>::value; } // namespace n91 #include <array> #include <cstddef> #include <iostream> int main() { using mint = n91::modint<1000000007>; using usize = std::size_t; constexpr usize N = 202020; constexpr usize base = N / 2; std::array<mint, N> dp = {}; dp[base] = 2; usize n; std::cin >> n; for (usize i = 1; i != n; ++i) { if (i % 2 == 0) { const usize end = base + i / 2; for (usize j = base - i / 2; j != end; ++j) { dp[j + 1] += dp[j]; } } else { const usize end = base - i / 2 - 1; for (usize j = base + i / 2; j != end; --j) { dp[j - 1] += dp[j]; } } } if (n % 2 == 0) { std::cout << dp[base - n / 2].value() << std::endl; } else { std::cout << dp[base + n / 2].value() << std::endl; } }