結果

問題 No.372 It's automatic
ユーザー rpy3cpprpy3cpp
提出日時 2016-05-14 01:27:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,062 ms / 6,000 ms
コード長 601 bytes
コンパイル時間 1,014 ms
コンパイル使用メモリ 65,648 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 08:11:23
合計ジャッジ時間 14,892 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1,018 ms
5,376 KB
testcase_05 AC 1,026 ms
5,376 KB
testcase_06 AC 1,016 ms
5,376 KB
testcase_07 AC 1,022 ms
5,376 KB
testcase_08 AC 1,032 ms
5,376 KB
testcase_09 AC 1,031 ms
5,376 KB
testcase_10 AC 1,021 ms
5,376 KB
testcase_11 AC 1,017 ms
5,376 KB
testcase_12 AC 1,020 ms
5,376 KB
testcase_13 AC 1,011 ms
5,376 KB
testcase_14 AC 1,027 ms
5,376 KB
testcase_15 AC 1,062 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 100 ms
5,376 KB
testcase_22 AC 95 ms
5,376 KB
testcase_23 AC 91 ms
5,376 KB
testcase_24 AC 92 ms
5,376 KB
testcase_25 AC 92 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <string>
using namespace std;

constexpr int mod = 1000000007;

int dp1[20000] = { 0 };
int dp2[20000] = { 0 };

int main()
{
	string S;
	cin >> S;
	int M = 0;
	int zero = 0;
	cin >> M;
	for (auto c : S) {
		int v = c - '0';
		if (v == 0) {
			++zero;
		} else {
			dp2[v % M] = 1;
		}
		for	(int i = 0; i != M; ++i) {
			dp2[i] = (dp2[i] + dp1[i]) % mod;
			int j = (i * 10 + v) % M;
			dp2[j] = (dp2[j] + dp1[i]) % mod;
		}
		swap(dp1, dp2);
		for (int i = 0; i != M; ++i) dp2[i] = 0;
	}
	cout << (dp1[0] + zero) % mod << endl;
	cin >> M;
	return 0;
}
0