結果
問題 | No.1327 グラフの数え上げ |
ユーザー | Pachicobue |
提出日時 | 2020-12-24 02:33:35 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 14,307 bytes |
コンパイル時間 | 2,207 ms |
コンパイル使用メモリ | 205,908 KB |
実行使用メモリ | 22,892 KB |
最終ジャッジ日時 | 2024-09-21 16:46:01 |
合計ジャッジ時間 | 3,035 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 4 ms
5,376 KB |
testcase_02 | AC | 2 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 | 2 ms
5,376 KB |
testcase_09 | AC | 51 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 5 ms
5,376 KB |
testcase_16 | AC | 40 ms
22,892 KB |
ソースコード
#include <bits/stdc++.h> using ll = long long; using uint = unsigned int; using ull = unsigned long long; using ld = long double; template<typename T> using max_heap = std::priority_queue<T>; template<typename T> using min_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; constexpr int popcount(const ull v) { return v ? __builtin_popcountll(v) : 0; } constexpr int log2p1(const ull v) { return v ? 64 - __builtin_clzll(v) : 0; } constexpr int lsbp1(const ull v) { return __builtin_ffsll(v); } constexpr int clog(const ull v) { return v ? log2p1(v - 1) : 0; } constexpr ull ceil2(const ull v) { return 1ULL << clog(v); } constexpr ull floor2(const ull v) { return v ? (1ULL << (log2p1(v) - 1)) : 0ULL; } constexpr bool btest(const ull mask, const int ind) { return (mask >> ind) & 1ULL; } template<typename T> bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template<typename T> bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } template<typename T> constexpr T inf_v = std::numeric_limits<T>::max() / 4; template<typename Real> constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; template<typename T> constexpr T TEN(const int n) { return n == 0 ? T{1} : TEN<T>(n - 1) * T{10}; } template<typename F> struct fix : F { fix(F&& f) : F{std::forward<F>(f)} {} template<typename... Args> auto operator()(Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); } }; template<typename T, int n, int i = 0> auto nd_array(int const (&szs)[n], const T x = T{}) { if constexpr (i == n) { return x; } else { return std::vector(szs[i], nd_array<T, n, i + 1>(szs, x)); } } class printer { public: printer(std::ostream& os_ = std::cout) : m_os{os_} { m_os << std::fixed << std::setprecision(15); } template<typename... Args> int ln(const Args&... args) { return dump(args...), m_os << '\n', 0; } template<typename... Args> int el(const Args&... args) { return dump(args...), m_os << std::endl, 0; } private: template<typename T> void dump(const T& v) { m_os << v; } template<typename T> void dump(const std::vector<T>& vs) { for (int i = 0; i < (int)vs.size(); i++) { m_os << (i ? " " : ""), dump(vs[i]); } } template<typename T> void dump(const std::vector<std::vector<T>>& vss) { for (int i = 0; i < (int)vss.size(); i++) { m_os << (0 <= i or i + 1 < (int)vss.size() ? "\n" : ""), dump(vss[i]); } } template<typename T, typename... Args> int dump(const T& v, const Args&... args) { return dump(v), m_os << ' ', dump(args...), 0; } std::ostream& m_os; }; printer out; class range { private: struct itr { itr(const int start = 0, const int step = 1) : m_cnt{start}, m_step{step} {} bool operator!=(const itr& it) const { return m_cnt != it.m_cnt; } int& operator*() { return m_cnt; } itr& operator++() { return m_cnt += m_step, *this; } int m_cnt, m_step; }; int m_start, m_end, m_step; public: range(const int start, const int end, const int step = 1) : m_start{start}, m_end{end}, m_step{step} { assert(m_step != 0); if (m_step > 0) { m_end = m_start + std::max(m_step - 1, m_end - m_start + m_step - 1) / m_step * m_step; } if (m_step < 0) { m_end = m_start - std::max(-m_step - 1, m_start - m_end - m_step - 1) / (-m_step) * (-m_step); } } itr begin() const { return itr{m_start, m_step}; } itr end() const { return itr{m_end, m_step}; } }; range rep(const int end, const int step = 1) { return range(0, end, step); } range per(const int rend, const int step = -1) { return range(rend - 1, -1, step); } class scanner { public: scanner(std::istream& is_ = std::cin) : m_is{is_} { m_is.tie(nullptr), std::ios::sync_with_stdio(false); } template<typename T> T val() { T v; return m_is >> v, v; } template<typename T> T val(const T offset) { return val<T>() - offset; } template<typename T> std::vector<T> vec(const int n) { return make_v<T>(n, [this]() { return val<T>(); }); } template<typename T> std::vector<T> vec(const int n, const T offset) { return make_v<T>(n, [this, offset]() { return val<T>(offset); }); } template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1) { return make_v<std::vector<T>>(n0, [this, n1]() { return vec<T>(n1); }); } template<typename T> std::vector<std::vector<T>> vvec(const int n0, const int n1, const T offset) { return make_v<std::vector<T>>(n0, [this, n1, offset]() { return vec<T>(n1, offset); }); } template<typename... Args> auto tup() { return std::tuple<std::decay_t<Args>...>{val<Args>()...}; } template<typename... Args> auto tup(const Args&... offsets) { return std::tuple<std::decay_t<Args>...>{val<Args>(offsets)...}; } private: template<typename T, typename F> std::vector<T> make_v(const int n, F f) { std::vector<T> ans; for (int i = 0; i < n; i++) { ans.push_back(f()); } return ans; } std::istream& m_is; }; scanner in; struct modinfo { const uint mod, root, max2p; }; template<const modinfo& info> class modint { public: static constexpr const uint& mod = info.mod; static constexpr const uint& root = info.root; static constexpr const uint& max2p = info.max2p; constexpr modint() : m_val{0} {} constexpr modint(const ll v) : m_val{normll(v)} {} constexpr modint(const modint& m) = default; constexpr modint& operator =(const modint& m) { return m_val = m(), (*this); } constexpr modint& operator =(const ll v) { return m_val = normll(v), (*this); } constexpr modint operator+() const { return *this; } constexpr modint operator-() const { return modint{0} - (*this); } constexpr modint& operator+=(const modint& m) { return m_val = norm(m_val + m()), *this; } constexpr modint& operator-=(const modint& m) { return m_val = norm(m_val + mod - m()), *this; } constexpr modint& operator*=(const modint& m) { return m_val = normll((ll)m_val * (ll)m() % (ll)mod), *this; } constexpr modint& operator/=(const modint& m) { return *this *= m.inv(); } constexpr modint& operator+=(const ll val) { return *this += modint{val}; } constexpr modint& operator-=(const ll val) { return *this -= modint{val}; } constexpr modint& operator*=(const ll val) { return *this *= modint{val}; } constexpr modint& operator/=(const ll val) { return *this /= modint{val}; } constexpr modint operator+(const modint& m) const { return modint{*this} += m; } constexpr modint operator-(const modint& m) const { return modint{*this} -= m; } constexpr modint operator*(const modint& m) const { return modint{*this} *= m; } constexpr modint operator/(const modint& m) const { return modint{*this} /= m; } constexpr modint operator+(const ll v) const { return *this + modint{v}; } constexpr modint operator-(const ll v) const { return *this - modint{v}; } constexpr modint operator*(const ll v) const { return *this * modint{v}; } constexpr modint operator/(const ll v) const { return *this / modint{v}; } constexpr bool operator==(const modint& m) const { return m_val == m(); } constexpr bool operator!=(const modint& m) const { return not(*this == m); } constexpr friend modint operator+(const ll v, const modint& m) { return modint{v} + m; } constexpr friend modint operator-(const ll v, const modint& m) { return modint{v} - m; } constexpr friend modint operator*(const ll v, const modint& m) { return modint{v} * m; } constexpr friend modint operator/(const ll v, const modint& m) { return modint{v} / m; } friend std::istream& operator>>(std::istream& is, modint& m) { ll v; return is >> v, m = v, is; } friend std::ostream& operator<<(std::ostream& os, const modint& m) { return os << m(); } constexpr uint operator()() const { return m_val; } constexpr modint pow(ull n) const { modint ans = 1; for (modint x = *this; n > 0; n >>= 1, x *= x) { if (n & 1ULL) { ans *= x; } } return ans; } constexpr modint inv() const { return pow(mod - 2); } modint sinv() const { return sinv(m_val); } static modint fact(const uint n) { static std::vector<modint> fs{1, 1}; for (uint i = (uint)fs.size(); i <= n; i++) { fs.push_back(fs.back() * i); } return fs[n]; } static modint ifact(const uint n) { static std::vector<modint> ifs{1, 1}; for (uint i = (uint)ifs.size(); i <= n; i++) { ifs.push_back(ifs.back() * sinv(i)); } return ifs[n]; } static modint perm(const int n, const int k) { return k > n or k < 0 ? modint{0} : fact(n) * ifact(n - k); } static modint comb(const int n, const int k) { return k > n or k < 0 ? modint{0} : fact(n) * ifact(n - k) * ifact(k); } private: static constexpr uint norm(const uint x) { return x < mod ? x : x - mod; } static constexpr uint normll(const ll x) { return norm(uint(x % (ll)mod + (ll)mod)); } static modint sinv(const uint n) { static std::vector<modint> is{1, 1}; for (uint i = (uint)is.size(); i <= n; i++) { is.push_back(-is[mod % i] * (mod / i)); } return is[n]; } uint m_val; }; constexpr modinfo modinfo_1000000007 = {1000000007, 5, 1}; constexpr modinfo modinfo_998244353 = {998244353, 3, 23}; using modint_1000000007 = modint<modinfo_1000000007>; using modint_998244353 = modint<modinfo_998244353>; int main() { using mint = modint_1000000007; const std::vector<mint> fs{1, 682498929, 491101308, 76479948, 723816384, 67347853, 27368307, 625544428, 199888908, 888050723, 927880474, 281863274, 661224977, 623534362, 970055531, 261384175, 195888993, 66404266, 547665832, 109838563, 933245637, 724691727, 368925948, 268838846, 136026497, 112390913, 135498044, 217544623, 419363534, 500780548, 668123525, 128487469, 30977140, 522049725, 309058615, 386027524, 189239124, 148528617, 940567523, 917084264, 429277690, 996164327, 358655417, 568392357, 780072518, 462639908, 275105629, 909210595, 99199382, 703397904, 733333339, 97830135, 608823837, 256141983, 141827977, 696628828, 637939935, 811575797, 848924691, 131772368, 724464507, 272814771, 326159309, 456152084, 903466878, 92255682, 769795511, 373745190, 606241871, 825871994, 957939114, 435887178, 852304035, 663307737, 375297772, 217598709, 624148346, 671734977, 624500515, 748510389, 203191898, 423951674, 629786193, 672850561, 814362881, 823845496, 116667533, 256473217, 627655552, 245795606, 586445753, 172114298, 193781724, 778983779, 83868974, 315103615, 965785236, 492741665, 377329025, 847549272, 698611116}; const auto S = in.val<std::string>(); if (S.size() >= 11) { return out.ln(0); } else { const auto N = std::stoll(S) - 1; if (N >= 1000000007) { return out.ln(0); } constexpr int B = 10000000; const int bi = N / B; mint ans = (N % 2 == 0 ? 1 : -1) * fs[bi]; for (int i = bi * B + 1; i <= N; i++) { ans *= i; } out.ln(ans); } return 0; }