結果
問題 | No.1085 桁和の桁和 |
ユーザー |
|
提出日時 | 2020-06-19 22:03:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 736 bytes |
コンパイル時間 | 1,656 ms |
コンパイル使用メモリ | 167,624 KB |
実行使用メモリ | 27,252 KB |
最終ジャッジ日時 | 2024-07-23 00:03:48 |
合計ジャッジ時間 | 3,992 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 WA * 6 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define MOD 1000000007 string s; int d; int memo[100010][20]; int dp(int i, int num){ if(i == s.size()) return (num == 0 ? 9 : num) == d ? 1 : 0; if(memo[i][num] != -1) return memo[i][num]; int ans = 0; if(s[i] != '?') ans = dp(i+1, (num*10+s[i]-'0') % 9); else{ for(int k = 0;k < 10;k++){ ans = (ans + dp(i+1, (num*10+k)% 9))%MOD; } } return memo[i][num] = ans; } signed main(){ cin >> s >> d; memset(memo, -1, sizeof(memo)); cout << dp(0, 0) << endl; return 0; }