結果

問題 No.372 It's automatic
コンテスト
ユーザー siman
提出日時 2023-07-12 06:12:14
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 594 ms / 6,000 ms
コード長 848 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,839 ms
コンパイル使用メモリ 149,248 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-04 07:13:00
合計ジャッジ時間 13,475 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:25:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   25 |   ll dp[M];
      |         ^
main.cpp:25:9: note: read of non-const variable 'M' is not allowed in a constant expression
main.cpp:22:7: note: declared here
   22 |   int M;
      |       ^
main.cpp:31:13: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   31 |     ll temp[M];
      |             ^
main.cpp:31:13: note: read of non-const variable 'M' is not allowed in a constant expression
main.cpp:22:7: note: declared here
   22 |   int M;
      |       ^
2 warnings generated.

ソースコード

diff #
raw source code

#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