結果

問題 No.372 It's automatic
ユーザー pekempey
提出日時 2016-10-29 06:50:06
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 466 ms / 6,000 ms
コード長 716 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 169,864 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 07:22:29
合計ジャッジ時間 8,537 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |     scanf("%s %d", S, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;

char S[10001];
int M, dp0[20000], dp1[20000];

void upd(int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

int main() {
    scanf("%s %d", S, &M);
    int n = strlen(S), d = 10 % M;
    for (int i = 0; i < n; i++) S[i] -= '0';
    for (int i = 0; i < n; i++) {
        memcpy(dp1, dp0, sizeof(dp1));
        if (S[i] != 0) dp0[S[i] % M]++;
        short k = S[i] % M;
        for (int j = 0; j < M; j++) {
            upd(dp0[k], dp1[j]);
            k += d;
            if (k >= M) k -= M;
        }
    }
    dp0[0] += count(S, S + n, 0);
    cout << dp0[0] % mod << endl;
}

0