結果
問題 | No.1085 桁和の桁和 |
ユーザー |
|
提出日時 | 2020-06-19 23:14:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 2,495 bytes |
コンパイル時間 | 1,911 ms |
コンパイル使用メモリ | 172,048 KB |
実行使用メモリ | 15,232 KB |
最終ジャッジ日時 | 2024-11-06 17:39:48 |
合計ジャッジ時間 | 3,608 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for (int i = 0; i < (n); i ++)using namespace std;using ll = long long;using PL = pair<ll,ll>;using P = pair<int,int>;constexpr int INF = 1000000000;constexpr long long HINF = 1000000000000000;constexpr long long MOD = 1000000007;constexpr double EPS = 1e-4;constexpr double PI = 3.14159265358979;struct Debug {template<class T> static void print_value(T value,const char* name) {cout << name << ": " << value << '\n';}template<class T> static void print_vector(vector<T> &vec,const char* name) {for (int i = 0;i < vec.size();++i) {cout << " " << name;printf("[%d]: ",i);cout << vec[i];}cout << '\n';}template<class T> static void print_2dvector(vector<vector<T>> &vec,const char* name) {for (int i = 0;i < vec.size();++i) {for (int j = 0;j < vec[i].size();++j) {cout << " " << name;printf("[%d][%d]: ",i,j);cout << vec[i][j];}cout << '\n';}}template<class T> static void print_set(set<T> &st,const char* name) {int i = 0;for (auto itr = st.begin();itr != st.end(); ++itr,++i) {cout << " " << name;printf("[%d]: ",i);cout << *itr;}cout << '\n';}template<class T1,class T2>static void print_map(map<T1,T2> &mp,const char* name) {for (auto p: mp) {cout << " " << name << '[' << p.first << ']' << ": " << p.second;}cout << '\n';}};int digit_sum(int x,int y) {x += y;while (x >= 10) {x = x/10 + x%10;}return x;cout << x << endl;}int main() {string T; cin >> T;int D; cin >> D;int N = T.size();//Debug::print_value(N,"N");vector<vector<ll>> dp(N + 1,vector<ll>(10,0));dp[0][0] = 1;rep(i,N) {if (T[i] != '?') {rep(j,10) {int x = digit_sum(j,(int)(T[i] - '0'));dp[i + 1][x] += dp[i][j];dp[i + 1][x] %= MOD;}}else {rep(j,10) {rep(k,10) {int x = digit_sum(j,k);dp[i + 1][x] += dp[i][j];dp[i + 1][x] %= MOD;}}}}ll ans = dp[N][D];cout << ans << endl;return 0;}