結果

問題 No.372 It's automatic
ユーザー kimiyukikimiyuki
提出日時 2016-05-24 22:00:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 978 ms / 6,000 ms
コード長 872 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 72,600 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-01 13:24:44
合計ジャッジ時間 13,929 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 971 ms
4,380 KB
testcase_05 AC 970 ms
4,380 KB
testcase_06 AC 966 ms
4,380 KB
testcase_07 AC 973 ms
4,376 KB
testcase_08 AC 976 ms
4,376 KB
testcase_09 AC 968 ms
4,380 KB
testcase_10 AC 970 ms
4,376 KB
testcase_11 AC 963 ms
4,380 KB
testcase_12 AC 977 ms
4,380 KB
testcase_13 AC 966 ms
4,376 KB
testcase_14 AC 975 ms
4,380 KB
testcase_15 AC 978 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 51 ms
4,376 KB
testcase_22 AC 51 ms
4,376 KB
testcase_23 AC 51 ms
4,376 KB
testcase_24 AC 51 ms
4,380 KB
testcase_25 AC 51 ms
4,376 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