結果

問題 No.1085 桁和の桁和
ユーザー tanon710
提出日時 2020-06-19 23:05:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 714 bytes
コンパイル時間 3,097 ms
コンパイル使用メモリ 82,100 KB
実行使用メモリ 820,496 KB
最終ジャッジ日時 2024-07-23 00:39:15
合計ジャッジ時間 7,957 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 9 WA * 1 TLE * 1 MLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
t=input()
d=int(input())
tmp=0
cnt=0
for c in t:
    if c=='?':
        cnt+=1
    else:
        tmp+=int(c)
if d!=0:
    if tmp!=0 and tmp%9==0:
        tmp=9
    dp=[[0]*10 for _ in range(cnt+1)]
    dp[0][0]=1
    for i in range(1,cnt+1):
        for j in range(10):
            for k in range(10):
                if j+k==0:
                    dp[i][0]+=dp[i-1][j]
                elif j+k==9 or j+k==18:
                    dp[i][9]+=dp[i-1][j]
                else:
                    dp[i][(j+k)%9]+=dp[i-1][j]
    ans=0
    for i in range(10):
        if tmp+i==d or tmp+i==d+9:
            ans+=dp[-1][i]
    print(ans%mod)
if d==0:
    if tmp!=0:
        print(0)
    else:
        print(1)
0