結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー nikkukunnikkukun
提出日時 2021-03-05 23:32:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 3,000 ms
コード長 1,249 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 164,632 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-16 11:38:52
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 7 ms
5,504 KB
testcase_34 AC 11 ms
6,144 KB
testcase_35 AC 10 ms
6,016 KB
testcase_36 AC 11 ms
5,888 KB
testcase_37 AC 11 ms
6,144 KB
testcase_38 AC 10 ms
5,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 1e4 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

const int D2[] = {0, 0, 1, 0, 2, 0, 1, 0, 3, 0};
const int D5[] = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0};

int f[N][2][2][3][3];
string s;

int dfs(int o, int lim, int hasBegin, int f2, int f5) {
	if (o < 0)
		return f2 == 0 && f5 == 0;
	if (f[o][lim][hasBegin][f2][f5] != -1)
		return f[o][lim][hasBegin][f2][f5];

	ll ans = 0;
	int upp = lim ? s[o] - '0' : 9;
	int low = hasBegin ? 1 : 0;
	for (int d = low; d <= upp; d++) {
		int d2 = D2[d];
		int d5 = D5[d];
		ans += dfs(o - 1, lim && (d == upp), (hasBegin || d > 0), max(f2 - d2, 0), max(f5 - d5, 0));
	}

	ans = (ans % MOD + MOD) % MOD;
	return f[o][lim][hasBegin][f2][f5] = ans;
}

int main() {
	ios::sync_with_stdio(0);

	memset(f, -1, sizeof(f));
	cin >> s;
	reverse(all(s));
	int n = s.size();
	ll ans = dfs(n - 1, 1, 0, 2, 2);
	cout << (ans % MOD + MOD) % MOD << endl;

	return 0;
}
0