結果

問題 No.1085 桁和の桁和
ユーザー QCFium
提出日時 2020-01-09 23:03:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 169,028 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-06 17:31:03
合計ジャッジ時間 2,705 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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();
	bool zero_possible = !std::count_if(s.begin(), s.end(), [] (char c) { return c != '?' && c != '0'; });
	if (d == 0) {
		puts(zero_possible ? "1" : "0");
		return 0;
	}
	if (d == 9) d = 0;
	int base = 0, res = 0, cur = 1;
	for (auto c : s) {
		if (c != '?') base += c - '0';
		else {
			res += cur;
			if (res >= 1000000007) res -= 1000000007;
			cur = (int64_t) cur * 10 % 1000000007;
		}
	}
	
	base %= 9;
	if (base == d) {
		res++;
		if (res >= 1000000007) res -= 1000000007;
	}
	if (d == 0) {
		res -= zero_possible;
		if (res < 0) res += 1000000007;
	}
	printf("%d\n", res);
	return 0;
}
0