結果
問題 | No.1683 Robot Guidance |
ユーザー | KoD |
提出日時 | 2021-09-17 21:53:16 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 7,023 bytes |
コンパイル時間 | 2,575 ms |
コンパイル使用メモリ | 252,332 KB |
実行使用メモリ | 19,660 KB |
最終ジャッジ日時 | 2024-06-29 20:19:48 |
合計ジャッジ時間 | 4,371 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 10 ms
5,900 KB |
testcase_04 | AC | 4 ms
5,376 KB |
testcase_05 | AC | 7 ms
5,376 KB |
testcase_06 | AC | 14 ms
5,860 KB |
testcase_07 | AC | 11 ms
5,860 KB |
testcase_08 | AC | 45 ms
12,612 KB |
testcase_09 | AC | 16 ms
6,888 KB |
testcase_10 | AC | 35 ms
11,496 KB |
testcase_11 | AC | 32 ms
11,376 KB |
testcase_12 | AC | 46 ms
13,536 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 58 ms
19,660 KB |
testcase_15 | AC | 41 ms
15,748 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 11 ms
6,500 KB |
testcase_23 | AC | 40 ms
15,556 KB |
testcase_24 | AC | 45 ms
12,312 KB |
testcase_25 | AC | 40 ms
15,592 KB |
testcase_26 | AC | 3 ms
5,376 KB |
testcase_27 | AC | 25 ms
11,576 KB |
testcase_28 | AC | 40 ms
15,588 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 39 ms
15,588 KB |
testcase_31 | AC | 12 ms
6,372 KB |
testcase_32 | AC | 43 ms
16,744 KB |
testcase_33 | AC | 25 ms
9,576 KB |
testcase_34 | AC | 26 ms
9,408 KB |
testcase_35 | AC | 44 ms
16,104 KB |
testcase_36 | AC | 45 ms
16,104 KB |
testcase_37 | AC | 8 ms
5,376 KB |
testcase_38 | AC | 42 ms
16,052 KB |
testcase_39 | AC | 22 ms
9,448 KB |
testcase_40 | AC | 1 ms
5,376 KB |
ソースコード
#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 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>; __attribute__((target("avx2"))) constexpr u64 ceil_log2(const u64 x) { u64 e = 0; while (((u64)1 << e) < x) ++e; return e; } template <class F> class AutoReallocation { using R = typename decltype(std::declval<F>()((usize)0))::value_type; F func; mutable std::vector<R> data; public: explicit AutoReallocation(F&& f) : func(std::forward<F>(f)), data() {} void reserve(const usize size) const { if (data.size() < size) data = func(((usize)1 << ceil_log2(size))); } R operator[](const usize i) const { reserve(i + 1); return data[i]; } }; template <class F> decltype(auto) auto_realloc(F&& f) { using G = std::decay_t<F>; return AutoReallocation<G>(std::forward<G>(f)); } template <class M> struct ModintUtil { static inline const auto fact = auto_realloc([](const usize n) { std::vector<M> ret(n); ret[0] = M(1); for (const usize i : rep(1, n)) { ret[i] = ret[i - 1] * M(i); } return ret; }); static inline const auto inv = auto_realloc([](const usize n) { std::vector<M> ret(n); if (n == 1) return ret; ret[1] = M(1); for (const usize i : rep(2, n)) { ret[i] = -M(M::mod() / i) * ret[M::mod() % i]; } return ret; }); static inline const auto inv_fact = auto_realloc([](const usize n) { std::vector<M> ret(n); ret[0] = M(1); for (const usize i : rep(1, n)) { ret[i] = ret[i - 1] * inv[i]; } return ret; }); static M binom(const usize n, const usize k) { assert(k <= n); return fact[n] * inv_fact[n - k] * inv_fact[k]; } static M factpow(const usize n, const usize k) { assert(k <= n); return fact[n] * inv_fact[n - k]; } static M homo(const usize n, const usize k) { if (n == 0 and k == 0) return M(1); return binom(n + k - 1, k); } }; template <class T> using Vec = std::vector<T>; using Fp = Modint1000000007; using Util = ModintUtil<Fp>; Fp coeff(const usize a, const usize b) { if (b == 0) return a == 0; return Util::binom(a + b - 1, a); } void main_() { i64 A, B, X, Y; std::cin >> A >> B >> X >> Y; Fp ans; for (const i64 a : rep(0, A + 1)) { const i64 c = a - X; if (c < 0) continue; if (a + c > A) continue; if ((A - a - c) % 2 != ((Y % 2) + 2) % 2) continue; const i64 b = ((A - a - c) + Y) / 2; const i64 d = b - Y; if (b < 0 or d < 0) continue; assert(a + b + c + d == A); assert(a - c == X); assert(b - d == Y); Fp add = 1; add *= coeff(a, B / 4 + (B % 4 >= 0)); add *= coeff(b, B / 4 + (B % 4 >= 1)); add *= coeff(c, B / 4 + (B % 4 >= 2)); add *= coeff(d, B / 4 + (B % 4 >= 3)); ans += add; } std::cout << ans << '\n'; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); main_(); return 0; }