結果

問題 No.1500 Super Knight
ユーザー KoD
提出日時 2021-05-07 22:03:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 4,957 bytes
コンパイル時間 1,907 ms
コンパイル使用メモリ 194,216 KB
最終ジャッジ日時 2025-01-21 08:09:57
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;
class rep {
struct Iter {
usize itr;
constexpr Iter(const usize pos) noexcept : itr(pos) {}
constexpr void operator++() noexcept { ++itr; }
constexpr bool operator!=(const Iter& other) const noexcept {
return itr != other.itr;
}
constexpr usize operator*() const noexcept { return itr; }
};
const Iter first, last;
public:
explicit constexpr rep(const usize first, const usize last) noexcept
: first(first), last(std::max(first, last)) {}
constexpr Iter begin() const noexcept { return first; }
constexpr Iter end() const noexcept { return last; }
};
template <class T> constexpr T totient(T x) {
T ret = x;
for (T i = 2; i * i <= x; ++i) {
if (x % i == 0) {
ret /= i;
ret *= i - 1;
while (x % i == 0) x /= i;
}
}
if (x > 1) {
ret /= x;
ret *= x - 1;
}
return ret;
}
template <class T> constexpr T rem_euclid(T value, const T& mod) {
return (value %= mod) >= 0 ? value : value + mod;
}
template <u32 MOD,
std::enable_if_t<((u32)1 <= MOD and MOD <= ((u32)1 << 31))>* =
nullptr>
class StaticModint {
using Mint = StaticModint;
static inline constexpr u32 PHI = totient(MOD);
u32 v;
public:
static constexpr u32 mod() noexcept { return MOD; }
template <class T,
std::enable_if_t<std::is_signed_v<T> and std::is_integral_v<T>>* =
nullptr>
static constexpr T normalize(const T x) noexcept {
return rem_euclid<std::common_type_t<T, i64>>(x, MOD);
}
template <class T,
std::enable_if_t<std::is_unsigned_v<T> and
std::is_integral_v<T>>* = nullptr>
static constexpr T normalize(const T x) noexcept {
return x % MOD;
}
constexpr StaticModint() noexcept : v(0) {}
template <class T>
constexpr StaticModint(const T x) noexcept : v(normalize(x)) {}
template <class T> static constexpr Mint raw(const T x) noexcept {
Mint ret;
ret.v = x;
return ret;
}
constexpr u32 get() const noexcept { return v; }
constexpr Mint neg() const noexcept { return raw(v == 0 ? 0 : MOD - v); }
constexpr Mint inv() const noexcept { return pow(PHI - 1); }
constexpr Mint pow(u64 exp) const noexcept {
Mint ret(1), mult(*this);
for (; exp > 0; exp >>= 1) {
if (exp & 1) ret *= mult;
mult *= mult;
}
return ret;
}
constexpr Mint operator-() const noexcept { return neg(); }
constexpr Mint operator~() const noexcept { return inv(); }
constexpr Mint operator+(const Mint& rhs) const noexcept {
return Mint(*this) += rhs;
}
constexpr Mint& operator+=(const Mint& rhs) noexcept {
if ((v += rhs.v) >= MOD) v -= MOD;
return *this;
}
constexpr Mint operator-(const Mint& rhs) const noexcept {
return Mint(*this) -= rhs;
}
constexpr Mint& operator-=(const Mint& rhs) noexcept {
if (v < rhs.v) v += MOD;
v -= rhs.v;
return *this;
}
constexpr Mint operator*(const Mint& rhs) const noexcept {
return Mint(*this) *= rhs;
}
constexpr Mint& operator*=(const Mint& rhs) noexcept {
v = (u64)v * rhs.v % MOD;
return *this;
}
constexpr Mint operator/(const Mint& rhs) const noexcept {
return Mint(*this) /= rhs;
}
constexpr Mint& operator/=(const Mint& rhs) noexcept {
return *this *= rhs.inv();
}
constexpr bool operator==(const Mint& rhs) const noexcept {
return v == rhs.v;
}
constexpr bool operator!=(const Mint& rhs) const noexcept {
return v != rhs.v;
}
friend std::ostream& operator<<(std::ostream& stream, const Mint& rhs) {
return stream << rhs.v;
}
};
using Modint1000000007 = StaticModint<1000000007>;
using Modint998244353 = StaticModint<998244353>;
template <class T> using Vec = std::vector<T>;
constexpr u32 ANS[] = {1, 12, 65};
using Fp = Modint1000000007;
void B_main() {
u64 N;
std::cin >> N;
if (N <= 2) {
std::cout << ANS[N] << '\n';
} else {
if (N % 2 == 0) {
const auto L = (N - 4) / 2;
std::cout << Fp(297) + Fp(352) * Fp(L) + Fp(68) * Fp(L) * Fp(L - 1)
<< '\n';
} else {
const auto L = (N - 3) / 2;
std::cout << Fp(172) + Fp(284) * Fp(L) + Fp(68) * Fp(L) * Fp(L - 1)
<< '\n';
}
}
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
B_main();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0