結果

問題 No.189 SUPER HAPPY DAY
ユーザー kaikeykaikey
提出日時 2020-05-21 11:17:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 3,120 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 167,068 KB
実行使用メモリ 16,304 KB
最終ジャッジ日時 2024-04-09 23:16:25
合計ジャッジ時間 2,558 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
16,172 KB
testcase_01 AC 6 ms
16,300 KB
testcase_02 AC 5 ms
16,304 KB
testcase_03 AC 5 ms
16,300 KB
testcase_04 AC 6 ms
16,172 KB
testcase_05 AC 5 ms
16,300 KB
testcase_06 AC 6 ms
16,040 KB
testcase_07 AC 6 ms
16,176 KB
testcase_08 AC 5 ms
16,176 KB
testcase_09 AC 5 ms
16,168 KB
testcase_10 AC 5 ms
16,168 KB
testcase_11 AC 5 ms
16,300 KB
testcase_12 AC 5 ms
16,296 KB
testcase_13 AC 14 ms
16,300 KB
testcase_14 AC 17 ms
16,172 KB
testcase_15 AC 14 ms
16,172 KB
testcase_16 AC 15 ms
16,172 KB
testcase_17 AC 17 ms
16,300 KB
testcase_18 AC 14 ms
16,172 KB
testcase_19 AC 18 ms
16,168 KB
testcase_20 AC 11 ms
16,296 KB
testcase_21 AC 10 ms
16,172 KB
testcase_22 AC 6 ms
16,304 KB
testcase_23 AC 12 ms
16,048 KB
testcase_24 AC 11 ms
16,044 KB
testcase_25 AC 19 ms
16,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T & a, const T & b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1000000009;

template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
typedef modint<MOD> ModInt;

ModInt dpM[202][2][2000];
ModInt dpD[202][2][2000];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string M, Day;
	cin >> M >> Day;
	lint m = SZ(M), d = SZ(Day);
	fill((long long*)dpM, (long long*)dpM + sizeof(dpM) / sizeof(long long), 0);
	fill((long long*)dpD, (long long*)dpD + sizeof(dpD) / sizeof(long long), 0);

	dpM[0][0][0] = 1;
	dpD[0][0][0] = 1;
	REP(i, m) {
		int D = M[i] - '0';
		REP(j, 2) {
			REP(k, 2000) {
				REP(d, (j ? 10 : D + 1)) {
					dpM[i + 1][j || d < D][k + d] += dpM[i][j][k];
				}
			}
		}
	}

	REP(i, d) {
		int D = Day[i] - '0';
		REP(j, 2) {
			REP(k, 2000) {
				REP(d, (j ? 10 : D + 1)) {
					dpD[i + 1][j || d < D][k + d] += dpD[i][j][k];
				}
			}
		}
	}

	ModInt sum = 0;
	FOR(i, 1, 2000) {
		sum += (dpM[m][1][i] + dpM[m][0][i]) * (dpD[d][1][i] + dpD[d][0][i]);
	}
	cout << sum.a << endl;
}
0