結果

問題 No.372 It's automatic
ユーザー kimiyukikimiyuki
提出日時 2016-05-24 22:00:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 903 ms / 6,000 ms
コード長 872 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 71,796 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 12:48:16
合計ジャッジ時間 11,941 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 870 ms
5,376 KB
testcase_05 AC 874 ms
5,376 KB
testcase_06 AC 868 ms
5,376 KB
testcase_07 AC 867 ms
5,376 KB
testcase_08 AC 873 ms
5,376 KB
testcase_09 AC 860 ms
5,376 KB
testcase_10 AC 863 ms
5,376 KB
testcase_11 AC 861 ms
5,376 KB
testcase_12 AC 870 ms
5,376 KB
testcase_13 AC 860 ms
5,376 KB
testcase_14 AC 874 ms
5,376 KB
testcase_15 AC 903 ms
5,376 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 44 ms
6,940 KB
testcase_22 AC 46 ms
6,944 KB
testcase_23 AC 48 ms
6,944 KB
testcase_24 AC 47 ms
6,944 KB
testcase_25 AC 49 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
typedef long long ll;
using namespace std;
const int mod = 1e9+7;
int main() {
    string s; int m; cin >> s >> m;
    vector<ll> cur(m);
    vector<ll> prv;
    ll ans = 0;
    for (char c : s) {
        int d = c - '0';
        cur.swap(prv);
        cur.clear();
        cur.resize(m);
        repeat (i,m) {
            cur[i] += prv[i];
            cur[(i * 10 + d) % m] += prv[i];
            if ((i * 10 + d) % m == 0) {
                ans += prv[i];
            }
        }
        if (d == 0) {
            ans += 1;
        } else {
            cur[d % m] += 1;
            if (d % m == 0) {
                ans += 1;
            }
        }
        repeat (i,m) {
            cur[i] %= mod;
        }
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
0