結果
問題 | No.1085 桁和の桁和 |
ユーザー | KKT89 |
提出日時 | 2020-06-19 22:16:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 1,253 bytes |
コンパイル時間 | 1,066 ms |
コンパイル使用メモリ | 98,004 KB |
最終ジャッジ日時 | 2025-01-11 06:44:27 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <map> #include <math.h> #include <deque> #include <cstdio> #include <queue> #include <numeric> using namespace std; typedef long long int ll; typedef unsigned long long int ull; const ll mx=1e9; constexpr ll mod=1e9+7; ll mod_pow(ll a,ll b){ a%=mod; if(b==0)return 1; if(b==1)return a; ll res=mod_pow(a,b/2)%mod; res*=res; res%=mod; if(b%2)res*=a; return res%mod; } int cal(int s){ if(s==0)return 0; s--; return s%9+1; } ll dp[100100][10]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); string t; cin >> t; int d; cin >> d; if(d==0){ bool ok=1; for(char c:t){ if(c=='?'||c=='0'){ } else{ ok=0; } } cout << ok << endl; return 0; } int cnt=0; int sum=0; for(char c:t){ if(c=='?')cnt++; else sum+=(c-'0'); } sum=cal(sum); dp[0][sum]=1LL; for(int i=0;i<cnt;i++){ for(int j=0;j<=9;j++){ for(int k=0;k<=9;k++){ (dp[i+1][cal(k+j)]+=dp[i][k])%=mod; } } } cout << dp[cnt][d] << endl; }