結果

問題 No.1085 桁和の桁和
ユーザー queeequeee
提出日時 2020-06-19 22:31:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,108 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 83,592 KB
実行使用メモリ 23,496 KB
最終ジャッジ日時 2024-07-23 00:17:34
合計ジャッジ時間 6,853 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 7 WA * 22 RE * 6
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0