結果

問題 No.189 SUPER HAPPY DAY
ユーザー __math__math
提出日時 2015-04-22 00:15:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 2,127 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 101,144 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 02:58:51
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 10 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <limits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

// #pragma comment(linker,"/STACK:36777216")

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> void chmax(T& l, const T r) { l = max(l, r); }
template<class T> void chmin(T& l, const T r) { l = min(l, r); }

const int MOD = ten(9) + 9;

vector<ll> digit_dp(const string& s){
	vector<int> a;
	for (auto c : s) a.push_back(c - '0');
	reverse(a.begin(), a.end());

	static ll buf[4][2010];
	memset(buf, 0, sizeof(buf));
	auto pv_leq = buf[0], pv_gt = buf[1], nt_leq = buf[2], nt_gt = buf[3];
	pv_leq[0] = 1;
	FOR(i, sz(a)){
		memset(nt_leq, 0, sizeof(buf[0]));
		memset(nt_gt, 0, sizeof(buf[0]));
		FOR(j, 2010) {
			if (pv_leq[j] == 0 && pv_gt[j] == 0) continue;
			FOR(d, 10) {
				int nj = j + d;
				if (d > a[i]) {
					(nt_gt[nj] += pv_leq[j] + pv_gt[j]) %= MOD;
				} else if (d < a[i]) {
					(nt_leq[nj] += pv_leq[j] + pv_gt[j]) %= MOD;
				} else {
					(nt_leq[nj] += pv_leq[j]) %= MOD;
					(nt_gt[nj] += pv_gt[j]) %= MOD;
				}
			}
		}
		swap(pv_leq, nt_leq);
		swap(pv_gt, nt_gt);
	}
	--pv_leq[0];

	vector<ll> ret;
	FOR(i, 2010) ret.push_back(pv_leq[i]);
	return ret;
}

int main() {
	string m, d; cin >> m >> d;
	auto x = digit_dp(m);
	auto y = digit_dp(d);
	ll ans = 0;
	FOR(i, 2010) ans += x[i] * y[i] % MOD;

	cout << ans % MOD << endl;

	return 0;
}
0