結果
問題 | No.1085 桁和の桁和 |
ユーザー | kcvlex |
提出日時 | 2020-06-19 22:24:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 8,821 bytes |
コンパイル時間 | 1,438 ms |
コンパイル使用メモリ | 146,244 KB |
実行使用メモリ | 19,756 KB |
最終ジャッジ日時 | 2024-07-23 00:16:41 |
合計ジャッジ時間 | 4,875 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
19,756 KB |
testcase_01 | AC | 12 ms
11,956 KB |
testcase_02 | AC | 12 ms
11,612 KB |
testcase_03 | AC | 12 ms
12,356 KB |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
ソースコード
#define CPP17 #include <limits> #include <initializer_list> #include <utility> #include <bitset> #include <tuple> #include <type_traits> #include <functional> #include <string> #include <array> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <iterator> #include <algorithm> #include <complex> #include <random> #include <numeric> #include <iostream> #include <iomanip> #include <sstream> #include <regex> #include <cassert> #include <cstddef> #ifdef CPP17 #include <variant> #endif // Yay!! #define endl codeforces // macros for iterator #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) // alias using ll = std::int64_t; using ull = std::uint64_t; using pii = std::pair<int, int>; using tii = std::tuple<int, int, int>; using pll = std::pair<ll, ll>; using tll = std::tuple<ll, ll, ll>; template <typename T> using vec = std::vector<T>; template <typename T> using vvec = vec<vec<T>>; // variadic min/max template <typename T> const T& var_min(const T &t) { return t; } template <typename T> const T& var_max(const T &t) { return t; } template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } // variadic chmin/chmax template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } // multi demension array template <typename T, std::size_t Head, std::size_t... Tail> struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; }; template <typename T, std::size_t Head> struct multi_dim_array<T, Head> { using type = std::array<T, Head>; }; template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type; #ifdef CPP17 // fill container template <typename T, typename F, typename... Args> void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable<F, Args...>::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } } #endif // make multi dimension vector template <typename T> vec<T> make_v(ssize_t sz) { return vec<T>(sz); } template <typename T, typename... Tail> auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); return vec<decltype(v)>(hs, v); } // init namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } namespace math { template <typename T> constexpr T pow(const T &n, ll k) { T ret = n.mul_id_ele(); T cur = n; while (k) { if (k & 1) ret *= cur; cur *= cur; k /= 2; } return ret; } } namespace math { template <ll Mod> struct Modint { constexpr Modint(ll x) noexcept : x((Mod + x % Mod) % Mod) { } constexpr Modint() noexcept : Modint(0) { } constexpr Modint<Mod> add_id_ele() const noexcept { return Modint<Mod>(0); } constexpr Modint<Mod> mul_id_ele() const noexcept { return Modint<Mod>(1); } constexpr ll& value() noexcept { return x; } constexpr ll value() const noexcept { return x; } constexpr Modint& operator +=(const Modint &oth) noexcept { x += oth.value(); if (Mod <= x) x -= Mod; return *this; } constexpr Modint& operator -=(const Modint &oth) noexcept { x += Mod - oth.value(); if (Mod <= x) x -= Mod; return *this; } constexpr Modint& operator *=(const Modint &oth) noexcept { x *= oth.value(); x %= Mod; return *this; } constexpr Modint& operator /=(const Modint &oth) noexcept { x *= oth.inv().value(); x %= Mod; return *this; } constexpr Modint operator +(const Modint &oth) const noexcept { return Modint(x) += oth; } constexpr Modint operator -(const Modint &oth) const noexcept { return Modint(x) -= oth; } constexpr Modint operator *(const Modint &oth) const noexcept { return Modint(x) *= oth; } constexpr Modint operator /(const Modint &oth) const noexcept { return Modint(x) /= oth; } constexpr Modint operator -() const noexcept { return Modint((x != 0) * (Mod - x)); } template <typename T> constexpr typename std::enable_if<std::is_integral<T>::value, const Modint&>::type operator =(T t) noexcept { (*this) = Modint(std::forward<T>(t)); return *this; } constexpr Modint inv() const noexcept { return ::math::pow(*this, Mod - 2); } constexpr ll mod() const noexcept { return Mod; } private: ll x; }; } ssize_t ceil_pow2(ssize_t s) { ssize_t ret = 1; while (ret < s) ret *= 2; return ret; } namespace segtree { template <typename T, typename Op> struct SegmentTree { vec<T> nodes; Op op; T id_ele; auto get_children_idx(ssize_t idx) const -> std::pair<ssize_t, ssize_t> { return std::make_pair(2 * idx + 1, 2 * idx + 2); } T get_merged(ssize_t idx) const { ssize_t a, b; std::tie(a, b) = get_children_idx(idx); return op(nodes[a], nodes[b]); } public: SegmentTree(const vec<T> &init_v, Op op, T id_ele) : op(op), id_ele(id_ele) { build(init_v); } void build(const vec<T> &v) { nodes.resize(ceil_pow2(v.size()) * 2 - 1, id_ele); ssize_t sz = size(); std::copy(ALL(v), nodes.begin() + sz - 1); build_parents(); } void build_parents() { ssize_t sz = size(); for (ssize_t i = sz - 2; 0 <= i; i--) nodes[i] = get_merged(i); } ssize_t size() const { return (nodes.size() + 1) / 2; } const T& operator [](ll idx) const { return nodes[idx + size() - 1]; } T get_query(ll ql, ll qr) const { return get_query(ql, qr, id_ele); } T get_query(ll ql, ll qr, T init) const { T ret = init; ssize_t lnode = ql + size(), rnode = qr + size(); while (lnode < rnode) { if (lnode & 1) { ret = std::move(op(nodes[lnode - 1], ret)); lnode++; } if (rnode & 1) { rnode--; ret = std::move(op(ret, nodes[rnode - 1])); } lnode /= 2; rnode /= 2; } return ret; } void update_query(ll idx, T val) { idx += size() - 1; nodes[idx] = val; while (idx) { ll pidx = (idx - 1) / 2; nodes[pidx] = get_merged(pidx); idx = pidx; } } template <typename F> ssize_t lower_bound(F f) const { T sum = id_ele; ssize_t l = 0, r = size(), idx = 0, bidx = 0; if (!f(nodes[0])) return -1; while (true) { if (r - l == 1) { if (!f(sum)) bidx++; break; } auto lidx = 2 * idx + 1; auto ridx = lidx + 1; T nsum = op(sum, nodes[lidx]); ssize_t m = (l + r) / 2; if (f(nsum)) { r = m; idx = lidx; } else { l = m; idx = ridx; bidx = m; sum = std::move(nsum); } } return bidx; } }; } const ll mod = 1e9 + 7; const ssize_t SIZE = 1e6; using mint = math::Modint<mod>; std::array<mint, SIZE> dp; std::array<ll, SIZE> dp2; int main() { std::string s; ll d; std::cin >> s >> d; ll sum = 0, cnt = 0; for (char c : s) { if ('0' <= c && c <= '9') sum += c - '0'; else cnt++; } dp[0] = 1; for (ll i = 0; i < 10; i++) dp2[i] = i; for (ll i = 0; i < cnt; i++) { ll maxv = i * 9; for (ll j = maxv; 0 <= j; j--) { for (ll k = 1; k <= 9; k++) dp[j + k] += dp[j]; } } auto to_digsum = [](ll n) { ll ret = 0; while (n) { ret += n % 10; n /= 10; } return ret; }; for (ll i = 10; i < SIZE; i++) dp2[i] = dp2[to_digsum(i)]; mint ans = 0; for (ll i = 0; i <= cnt * 9; i++) { ll v = sum + i; ll ds = dp2[v]; if (ds == d) ans += dp[i]; } std::cout << ans.value() << "\n"; return 0; }