結果

問題 No.372 It's automatic
ユーザー face4face4
提出日時 2019-11-24 11:55:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,111 ms / 6,000 ms
コード長 594 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 72,288 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 09:26:50
合計ジャッジ時間 15,311 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1,088 ms
4,380 KB
testcase_05 AC 1,088 ms
4,376 KB
testcase_06 AC 1,084 ms
4,376 KB
testcase_07 AC 1,090 ms
4,380 KB
testcase_08 AC 1,089 ms
4,376 KB
testcase_09 AC 1,074 ms
4,376 KB
testcase_10 AC 1,087 ms
4,376 KB
testcase_11 AC 1,070 ms
4,376 KB
testcase_12 AC 1,105 ms
4,380 KB
testcase_13 AC 1,089 ms
4,376 KB
testcase_14 AC 1,080 ms
4,376 KB
testcase_15 AC 1,111 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 55 ms
4,376 KB
testcase_22 AC 55 ms
4,380 KB
testcase_23 AC 57 ms
4,380 KB
testcase_24 AC 57 ms
4,376 KB
testcase_25 AC 53 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

const int mod = 1000000007;

int main(){
    string s;
    int m;
    cin >> s >> m;
    int n = s.length();
    vector<int> dp(m+1, 0);
    dp[0] = 1;
    int zero = 0;
    for(int i = 0; i < n; i++){
        zero += s[i]=='0';
        vector<int> ndp = dp;
        for(int j = 0; j <= m; j++){
            if(j == 0 && s[i] == '0')   continue;
            int x = ((j==m ? 0 : j*10) + s[i]-'0')%m;
            (ndp[x == 0 ? m : x] += dp[j]) %= mod;
        }
        dp = ndp;
    }
    cout << zero+dp.back() << endl;
    return 0;
}
0