結果

問題 No.372 It's automatic
ユーザー kenkooookenkoooo
提出日時 2016-05-13 23:31:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,065 ms / 6,000 ms
コード長 2,276 bytes
コンパイル時間 1,313 ms
コンパイル使用メモリ 151,356 KB
実行使用メモリ 5,004 KB
最終ジャッジ日時 2023-07-28 07:54:41
合計ジャッジ時間 15,152 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1,016 ms
4,896 KB
testcase_05 AC 1,030 ms
4,888 KB
testcase_06 AC 1,033 ms
4,888 KB
testcase_07 AC 1,032 ms
4,980 KB
testcase_08 AC 1,029 ms
4,900 KB
testcase_09 AC 1,036 ms
4,892 KB
testcase_10 AC 1,034 ms
4,860 KB
testcase_11 AC 1,016 ms
4,940 KB
testcase_12 AC 1,065 ms
4,940 KB
testcase_13 AC 1,025 ms
4,860 KB
testcase_14 AC 1,039 ms
4,896 KB
testcase_15 AC 1,040 ms
5,004 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 47 ms
4,380 KB
testcase_22 AC 47 ms
4,380 KB
testcase_23 AC 46 ms
4,384 KB
testcase_24 AC 47 ms
4,380 KB
testcase_25 AC 46 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            pass System Test!
*/
#include <bits/stdc++.h>
using namespace std;

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
  out << "[" << p.first << ", " << p.second << "]";
  return out;
}
template <class T, class U>
void chmin(T &t, U f) {
  if (t > f) t = f;
}
template <class T, class U>
void chmax(T &t, U f) {
  if (t < f) t = f;
}
template <typename T>
void uniq(vector<T> &v) {
  v.erase(unique(v.begin(), v.end()), v.end());
}

const int64_t MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string inS;
  cin >> inS;
  int N = inS.size();
  vector<int> S(N);
  for (int i = 0; i < N; ++i) S[i] = inS[i] - '0';
  int M;
  cin >> M;
  vector<vector<int>> remainer(M, vector<int>(10, 0));
  for (int i = 0; i < M; ++i)
    for (int j = 0; j < 10; ++j) remainer[i][j] = (i * 10 + j) % M;

  vector<int64_t> dp(M, 0);
  dp[0] = 1;
  int64_t zeros = 0;
  for (int i = 0; i < N; ++i) {
    vector<int64_t> next(M, 0);
    for (int m = 0; m < M; ++m) {
      next[m] += dp[m];
      next[m] %= MOD;

      int r = remainer[m][S[i]];
      next[r] += dp[m];
      if (m == 0 && S[i] == 0) {
        zeros++;
        next[r] = (next[r] - 1 + MOD) % MOD;
      } else {
        next[r] %= MOD;
      }
    }
    dp.swap(next);
  }
  cout << ((dp[0] + zeros - 1 + MOD) % MOD) << endl;
}
0