結果

問題 No.1085 桁和の桁和
ユーザー koyoprokoyopro
提出日時 2020-06-19 22:17:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,113 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 146,004 KB
実行使用メモリ 11,356 KB
最終ジャッジ日時 2023-08-06 14:30:35
合計ジャッジ時間 4,344 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 23 ms
5,112 KB
testcase_15 AC 49 ms
6,908 KB
testcase_16 AC 49 ms
6,800 KB
testcase_17 AC 23 ms
5,008 KB
testcase_18 AC 13 ms
4,376 KB
testcase_19 AC 44 ms
6,452 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 29 ms
5,452 KB
testcase_22 AC 41 ms
6,196 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 26 ms
5,168 KB
testcase_26 AC 51 ms
6,964 KB
testcase_27 AC 41 ms
6,388 KB
testcase_28 AC 57 ms
7,484 KB
testcase_29 AC 31 ms
5,564 KB
testcase_30 AC 28 ms
5,340 KB
testcase_31 AC 49 ms
6,864 KB
testcase_32 AC 34 ms
6,000 KB
testcase_33 AC 109 ms
11,256 KB
testcase_34 AC 109 ms
11,320 KB
testcase_35 AC 110 ms
11,356 KB
testcase_36 AC 110 ms
11,288 KB
testcase_37 AC 110 ms
11,248 KB
testcase_38 AC 108 ms
11,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 11
#else
#define SIZE 123450
#endif

int D;
string T;
// i番目までみたときの余りがj
int DP[SIZE][10];
int MOD=1e9+7;

void solve() {
    cin>>T>>D;
    int n = 0;
    int cntq = 0;
    int nz = 0;
    REP(i,T.size()) {
        if (T[i]=='?') {
            cntq++;
        } else {
            (n += T[i]-'0')%=9;
            if (T[i]!='0') nz++;
        }
    }
    if (D==0) {
        if (nz==0) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }
    if (nz && !n) n=9;
    if (!cntq) {
        if (n == D) {
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }
    int r = D-n;
    while (r<0) r+=9;
    if (r == 9) r = 0;
    REP(i,cntq)REP(j,10) {
        if (!i) {
            DP[i][j%9]+=1;
        } else {
            REP(k,9) {
                (DP[i][(k+j)%9] += DP[i-1][k])%=MOD;
            }
        }
    }
    int ans = DP[cntq-1][r];
    if (nz==0 && D==9) {
        ans--;
    }
    cout << ans << endl;
}

0