結果
問題 | No.1085 桁和の桁和 |
ユーザー | kibuna |
提出日時 | 2020-06-19 22:41:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,550 bytes |
コンパイル時間 | 1,757 ms |
コンパイル使用メモリ | 169,844 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-23 00:18:53 |
合計ジャッジ時間 | 2,700 ms |
ジャッジサーバーID (参考情報) |
judge3 / 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 | 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 | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 3 ms
5,376 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; template <int mod> struct modint { lint v; modint() : v(0) {} modint(signed v) : v(v) {} modint(lint t) { v = t % mod; if (v < 0) v += mod; } modint pow(lint k) { modint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } static modint add_identity() { return modint(0); } static modint mul_identity() { return modint(1); } modint inv() { return pow(mod - 2); } modint &operator+=(modint a) { v += a.v; if (v >= mod) v -= mod; return *this; } modint &operator-=(modint a) { v += mod - a.v; if (v >= mod) v -= mod; return *this; } modint &operator*=(modint a) { v = v * a.v % mod; return *this; } modint &operator/=(modint a) { return (*this) *= a.inv(); } modint operator+(modint a) const { return modint(v) += a; }; modint operator-(modint a) const { return modint(v) -= a; }; modint operator*(modint a) const { return modint(v) *= a; }; modint operator/(modint a) const { return modint(v) /= a; }; modint operator-() const { return v ? modint(mod - v) : modint(v); } bool operator==(const modint a) const { return v == a.v; } bool operator!=(const modint a) const { return v != a.v; } bool operator<(const modint a) const { return v < a.v; } }; using mint = modint<mod>; ostream &operator<<(ostream &os, mint m) { return os << m.v; } struct Combination { vector<lint> fac, finv, inv; Combination(lint maxN) : fac(maxN + 100), finv(maxN + 100), inv(maxN + 100) { maxN += 100; // for safety fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (lint i = 2; i <= maxN; ++i) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } lint operator()(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } }; int digsum(lint d) { while (d / 10 != 0) { lint t = 0; while (d) { t += d % 10; d /= 10; } d = t; } return d; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string t; cin >> t; int d; cin >> d; lint q = 0; lint dig = 0; // for (lint i = 12390875213; i < 12390875213 + 1000; ++i) { // cout << digsum(i) << "\n"; // } for (int i = 0; i < (int)t.size(); ++i) { if (t[i] == '?') q++; else dig += t[i] - '0'; } if (q == 0) { if (digsum(dig) == d) cout << 1 << "\n"; else cout << 0 << "\n"; return 0; } if (d == 0) { if (dig == 0) cout << 1 << "\n"; else cout << 0 << "\n"; return 0; } // 0 - 99999... (9 * q) lint rem = 1; mint ret = 0; mint one = 1; for (int i = 0; i < q; ++i) { rem *= 10; rem %= 9; ret += one; one *= 10; } if ((d + 10 - dig) % 10 < rem) ret += 1; cout << ret << "\n"; return 0; }