結果

問題 No.372 It's automatic
ユーザー masamasa
提出日時 2016-05-14 16:32:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 883 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 66,344 KB
実行使用メモリ 814,464 KB
最終ジャッジ日時 2024-04-15 21:29:26
合計ジャッジ時間 2,340 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int MOD = 1e9 + 7;

void show(vector<vector<long long>> &vv) {
	for (auto v : vv) {
		for (auto e : v) {
			printf("%3lld ", e);
		}
		cout << endl;
	}
}

int main() {
	int m;
	string s;

	cin >> s >> m;
	int n = s.size();
	vector<vector<long long>> dp(n + 1, vector<long long>(m, 0));
	vector<long long> dp1(m, 0), dp2(m, 0);

	int n_zero = 0;
	for (int i = 0; i < n; i++) {
		int num = s[i] - '0';
		if (num == 0) {
			n_zero++;
		} else {
			dp[i + 1][num % m] += 1;
		}

		for (int j = 0; j < m; j++) {
			dp[i + 1][(dp[i][j] * 10 + num) % m] += dp[i][j];
			dp[i + 1][dp[i][j] * 10 % m] += dp[i][j];
		}
	}

	// show(dp);
	// printf("zero %d\n", n_zero);

	long long ans = (dp[n][0] + n_zero) % MOD;
	cout << ans << endl;
	return 0;
}
0