結果

問題 No.1085 桁和の桁和
ユーザー QCFiumQCFium
提出日時 2020-01-09 22:28:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 719 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 166,008 KB
実行使用メモリ 7,272 KB
最終ジャッジ日時 2023-09-30 06:00:17
合計ジャッジ時間 2,845 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 6 ms
4,976 KB
testcase_15 AC 12 ms
6,628 KB
testcase_16 AC 12 ms
6,616 KB
testcase_17 AC 7 ms
5,028 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 11 ms
6,336 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 8 ms
5,368 KB
testcase_22 AC 9 ms
6,360 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 7 ms
5,168 KB
testcase_26 AC 12 ms
6,764 KB
testcase_27 AC 10 ms
6,112 KB
testcase_28 AC 14 ms
7,256 KB
testcase_29 AC 9 ms
5,428 KB
testcase_30 AC 7 ms
5,264 KB
testcase_31 AC 11 ms
6,748 KB
testcase_32 AC 8 ms
5,760 KB
testcase_33 AC 18 ms
7,236 KB
testcase_34 AC 19 ms
7,272 KB
testcase_35 AC 18 ms
7,184 KB
testcase_36 AC 19 ms
7,200 KB
testcase_37 AC 20 ms
7,172 KB
testcase_38 AC 18 ms
7,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	int d = ri();
	if (d == 0) {
		puts(std::count_if(s.begin(), s.end(), [] (char c) { return c != '?' && c != '0'; }) ? "0" : "1");
		return 0;
	}
	if (d == 9) d = 0;
	int dp[n + 1][9];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	auto add = [&] (int &i, int j) {
		i += j;
		if (i >= 1000000007) i -= 1000000007;
	};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 9; j++) {
			if (s[i] == '?') {
				for (int k = 0; k < 10; k++) add(dp[i + 1][(j + k) % 9], dp[i][j]);
			} else add(dp[i + 1][(j + s[i] - '0') % 9], dp[i][j]);
		}
	}
	printf("%d\n", dp[n][d]);
	return 0;
}
0