結果
問題 | No.372 It's automatic |
ユーザー |
![]() |
提出日時 | 2016-05-14 21:41:57 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 374 ms / 6,000 ms |
コード長 | 1,560 bytes |
コンパイル時間 | 744 ms |
コンパイル使用メモリ | 65,524 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-06 02:49:27 |
合計ジャッジ時間 | 5,573 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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^31fast_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;}