結果

問題 No.1085 桁和の桁和
ユーザー koyoprokoyopro
提出日時 2020-06-19 22:09:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,900 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 145,376 KB
実行使用メモリ 11,472 KB
最終ジャッジ日時 2023-09-30 06:12:32
合計ジャッジ時間 4,084 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 22 ms
4,936 KB
testcase_15 AC 48 ms
6,840 KB
testcase_16 AC 48 ms
6,892 KB
testcase_17 AC 23 ms
4,956 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 43 ms
6,560 KB
testcase_20 WA -
testcase_21 AC 29 ms
5,404 KB
testcase_22 AC 39 ms
6,312 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 25 ms
5,168 KB
testcase_26 AC 50 ms
6,888 KB
testcase_27 AC 40 ms
6,196 KB
testcase_28 AC 56 ms
7,368 KB
testcase_29 AC 31 ms
5,496 KB
testcase_30 AC 28 ms
5,372 KB
testcase_31 AC 48 ms
6,748 KB
testcase_32 AC 33 ms
5,724 KB
testcase_33 AC 108 ms
11,260 KB
testcase_34 AC 108 ms
11,472 KB
testcase_35 AC 108 ms
11,192 KB
testcase_36 AC 108 ms
11,220 KB
testcase_37 AC 107 ms
11,212 KB
testcase_38 AC 108 ms
11,188 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 (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;
            }
        }
    }
    cout << DP[cntq-1][r] << endl;
}

0