結果

問題 No.372 It's automatic
ユーザー simansiman
提出日時 2023-07-12 06:12:14
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 1,102 ms / 6,000 ms
コード長 848 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 139,640 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-13 19:06:44
合計ジャッジ時間 16,454 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main() {
  string S;
  cin >> S;
  int L = S.size();
  int M;
  cin >> M;

  ll dp[M];
  memset(dp, 0, sizeof(dp));
  int zero_cnt = 0;

  for (int i = 0; i < L; ++i) {
    int d = S[i] - '0';
    ll temp[M];
    memcpy(temp, dp, sizeof(dp));

    if (d != 0) {
      temp[d % M] += 1;
      temp[d % M] %= MOD;
    } else {
      ++zero_cnt;
    }

    for (int m = 0; m < M; ++m) {
      int nm = (10 * m + d) % M;
      temp[nm] += dp[m];
      temp[nm] %= MOD;
    }

    memcpy(dp, temp, sizeof(temp));
  }

  cout << (dp[0] + zero_cnt) % MOD << endl;

  return 0;
}
0