結果

問題 No.372 It's automatic
ユーザー Min_25Min_25
提出日時 2016-05-14 21:41:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 389 ms / 6,000 ms
コード長 1,560 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 65,556 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 21:35:00
合計ジャッジ時間 6,200 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,948 KB
testcase_04 AC 386 ms
6,944 KB
testcase_05 AC 387 ms
6,940 KB
testcase_06 AC 386 ms
6,944 KB
testcase_07 AC 389 ms
6,944 KB
testcase_08 AC 389 ms
6,944 KB
testcase_09 AC 388 ms
6,944 KB
testcase_10 AC 386 ms
6,940 KB
testcase_11 AC 383 ms
6,940 KB
testcase_12 AC 386 ms
6,940 KB
testcase_13 AC 384 ms
6,944 KB
testcase_14 AC 388 ms
6,940 KB
testcase_15 AC 389 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 19 ms
6,940 KB
testcase_22 AC 19 ms
6,944 KB
testcase_23 AC 19 ms
6,940 KB
testcase_24 AC 20 ms
6,940 KB
testcase_25 AC 20 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstring>

#include <iostream>
#include <vector>

#define _fetch(_1, _2, _3, _4, name, ...) name
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c))
#define rep(...) _fetch(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__)

using namespace std;

using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using f80 = long double;

char S[10010];
u64 dp[2][20000];

struct fast_div {
  // < 2^31
  fast_div(u32 n) : m(n) {
    s = (n == 1) ? 0 : 63 - __builtin_clz(n - 1);
    x = ((u64(1) << s) + n - 1) / n;
  }
  friend u32 operator / (u32 n, fast_div d) { return (u64(n) * d.x) >> d.s; }
  friend u32 operator % (u32 n, fast_div d) { return n - n / d * d.m; }
  u32 x, s, m;
};

void solve() {
  const u32 MOD = 1e9 + 7;
  int M;
  while (~scanf("%s %d", S, &M)) {
    auto *curr = dp[0], *next = dp[1];
    auto D = fast_div(M);
    int len = strlen(S);
    u64 ans = 0;
    fill(curr, curr + M, 0);
    rep(i, len) {
      copy(curr, curr + M, next);
      int d = S[i] - '0';
      if (d > 0) next[d % D] += 1;
      else ans += 1;
      rep(j, M) next[(j * 10 + d) % D] += curr[j];
      swap(curr, next);
      if (i % 8 == 0) rep(j, M) curr[j] %= MOD;
    }
    ans = (ans + curr[0]) % MOD;
    printf("%llu\n", ans);
  }
}

int main() {
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC);
  return 0;
}
0