結果

問題 No.1085 桁和の桁和
ユーザー koyoprokoyopro
提出日時 2020-06-19 22:04:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,793 bytes
コンパイル時間 2,867 ms
コンパイル使用メモリ 145,116 KB
実行使用メモリ 11,356 KB
最終ジャッジ日時 2023-09-30 06:07:24
合計ジャッジ時間 5,774 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 22 ms
4,940 KB
testcase_15 AC 49 ms
6,916 KB
testcase_16 AC 48 ms
6,772 KB
testcase_17 AC 23 ms
5,044 KB
testcase_18 AC 13 ms
4,376 KB
testcase_19 AC 43 ms
6,580 KB
testcase_20 WA -
testcase_21 AC 28 ms
5,416 KB
testcase_22 AC 40 ms
6,320 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 26 ms
5,132 KB
testcase_26 AC 49 ms
6,916 KB
testcase_27 AC 41 ms
6,308 KB
testcase_28 AC 57 ms
7,404 KB
testcase_29 AC 31 ms
5,560 KB
testcase_30 AC 29 ms
5,372 KB
testcase_31 AC 49 ms
6,796 KB
testcase_32 AC 33 ms
5,788 KB
testcase_33 AC 110 ms
11,356 KB
testcase_34 AC 108 ms
11,228 KB
testcase_35 AC 109 ms
11,224 KB
testcase_36 AC 109 ms
11,216 KB
testcase_37 AC 109 ms
11,256 KB
testcase_38 AC 108 ms
11,252 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 (!cntq) {
        cout << 0 << endl;
        return;
    }
    if (nz && !n) n=9;
    int r = D-n;
    while (r<0) r+=9;
    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