結果

問題 No.372 It's automatic
ユーザー btkbtk
提出日時 2016-05-13 23:08:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 6,000 ms
コード長 713 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 167,484 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 08:01:09
合計ジャッジ時間 7,741 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 426 ms
6,944 KB
testcase_05 AC 429 ms
6,944 KB
testcase_06 AC 425 ms
6,940 KB
testcase_07 AC 426 ms
6,940 KB
testcase_08 AC 428 ms
6,944 KB
testcase_09 AC 425 ms
6,940 KB
testcase_10 AC 425 ms
6,944 KB
testcase_11 AC 423 ms
6,944 KB
testcase_12 AC 428 ms
6,940 KB
testcase_13 AC 424 ms
6,944 KB
testcase_14 AC 428 ms
6,940 KB
testcase_15 AC 433 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 22 ms
6,940 KB
testcase_22 AC 23 ms
6,940 KB
testcase_23 AC 22 ms
6,940 KB
testcase_24 AC 22 ms
6,940 KB
testcase_25 AC 22 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;
const int mod=1e9+7;
int main() {
    string S;
    int M;
    cin >> S >> M;
    int n = S.size();
    vector<int> dp(M,0);
    int ten=10%M;
    int res=0;
    for(int i = 0; i < n; i++){
        auto nxt=dp;
        int np=(S[i]-'0');
        if(np!=0)nxt[np%M]++;
        else res++;
        np%=M;
        for(int j = 0; j < M; j++){
            nxt[np]+=dp[j];
            if(nxt[np]>=mod)nxt[np]-=mod;
            np+=ten;
            if(np>=M)np-=M;
            //cout << np << " " << nxt[np] << endl;
        }
        swap(dp,nxt);
    }
    cout << (res+dp[0])%mod << endl;
    return 0;
}
0