結果

問題 No.1085 桁和の桁和
ユーザー queeequeee
提出日時 2020-06-19 22:31:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,108 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 23,048 KB
最終ジャッジ日時 2023-09-30 06:18:23
合計ジャッジ時間 7,104 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
21,656 KB
testcase_01 AC 25 ms
21,900 KB
testcase_02 AC 25 ms
22,052 KB
testcase_03 WA -
testcase_04 RE -
testcase_05 WA -
testcase_06 AC 26 ms
21,688 KB
testcase_07 AC 25 ms
21,836 KB
testcase_08 AC 26 ms
22,136 KB
testcase_09 AC 24 ms
21,936 KB
testcase_10 WA -
testcase_11 AC 25 ms
21,876 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 48 ms
22,148 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#include <map>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7, mx = 1000000;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; void chmax(ll& x, ll y) {if (x<y) x=y;}; void chmin(ll& x, ll y) {if (x>y) x=y;};

ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
vector<ll> sm(700005), inv(700005);
void sm_build() {
	sm[0]=1;for(ll i=1;i<700005;i++) sm[i]=sm[i-1]*i%M;
	inv[700004]=mod_pow(sm[700004],M-2);for(ll i=700003;i>=0;i--) inv[i]=inv[i+1]*(i+1)%M;
}
ll ncr(ll n, ll r) {
  if (n < r) return 1;
  return sm[n] * inv[n-r] % M * inv[r] % M;
}
ll ncr2(ll n, ll r) {return sm[n] * mod_pow(sm[n-r], M-2) % M * mod_pow(sm[r], M-2) % M;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}

int main() {
  sm_build();
  string s; cin>>s;
  int n=s.size();
  int d; cin>>d;
  int qu = 0, mp = 0;
  for(int i=0;i<n;i++) {
    if (s[i]=='?') {
      qu++;
    } else {
      mp+=s[i]-'0';
    }
  }
  cerr<<mx<<endl;
  ll dp[mx]={};
  for(int i=qu;i<=10*qu;i++) {
    ll su = 0;
    for(int j=0, k=1;j<=(i-qu)%10;j++, k*=-1) {
      if (i-10*j-1<qu-1||i-10*j-1<0) break;
      //cout<<i<<" "<<j<<" "<<i-10*j-1<<" "<<qu-1<<" "<<su<<endl;
      su += k * (ncr(qu, j) * ncr(i - 10 * j - 1, qu - 1) % M);
      su += M; su %= M;
    }
    dp[mp+i-qu]=su;
  }
  for(int i=mx-1;i>=10;i--) {
    add(dp[keta(i)],dp[i]);
  }
  /*
  for(int i=0;i<100;i++) {
    cout<<dp[i]<<" ";
  } cout<<endl;*/
  cout<<dp[d]<<endl;
}
0