結果
問題 | No.1085 桁和の桁和 |
ユーザー |
![]() |
提出日時 | 2020-06-19 22:37:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 1,095 bytes |
コンパイル時間 | 1,027 ms |
コンパイル使用メモリ | 90,420 KB |
最終ジャッジ日時 | 2025-01-11 07:11:40 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;using ll = long long;constexpr int P = 1000000007;int main() {ios::sync_with_stdio(false);cin.tie(0);string t;cin >> t;int n = t.size();for (int i = 0; i < n; i++) {t[i] = t[i] == '?' ? -1 : t[i] - '0';}int d;cin >> d;int b = 1;for (int i = 0; i < n; i++) {if (t[i] > 0) b = 0;}if (d == 0) {cout << b << endl;exit(0);}int k = 0;for (int i = 0; i < n; i++) {if (t[i] < 0) {k++;} else {d -= t[i];}}d %= 9;d += 9;d %= 9;ll dp[9] = { 1 };for (int i = 0; i < k; i++) {ll s = 0;for (int j = 0; j < 9; j++) {s += dp[j];}for (int j = 0; j < 9; j++) {(dp[j] += s) %= P;}}if (b) {(dp[0] += P - 1) %= P;}cout << dp[d] << endl;return 0;}