結果

問題 No.189 SUPER HAPPY DAY
ユーザー Yang33Yang33
提出日時 2017-11-02 17:17:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 3,187 bytes
コンパイル時間 2,926 ms
コンパイル使用メモリ 145,292 KB
実行使用メモリ 15,640 KB
最終ジャッジ日時 2023-08-14 15:20:41
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
15,620 KB
testcase_01 AC 9 ms
15,608 KB
testcase_02 AC 6 ms
15,616 KB
testcase_03 AC 9 ms
15,356 KB
testcase_04 AC 9 ms
15,436 KB
testcase_05 AC 9 ms
15,348 KB
testcase_06 AC 9 ms
15,628 KB
testcase_07 AC 9 ms
15,348 KB
testcase_08 AC 9 ms
15,484 KB
testcase_09 AC 9 ms
15,360 KB
testcase_10 AC 9 ms
15,612 KB
testcase_11 AC 9 ms
15,352 KB
testcase_12 AC 9 ms
15,428 KB
testcase_13 AC 58 ms
15,356 KB
testcase_14 AC 73 ms
15,440 KB
testcase_15 AC 65 ms
15,640 KB
testcase_16 AC 68 ms
15,424 KB
testcase_17 AC 78 ms
15,396 KB
testcase_18 AC 62 ms
15,424 KB
testcase_19 AC 89 ms
15,372 KB
testcase_20 AC 39 ms
15,364 KB
testcase_21 AC 43 ms
15,420 KB
testcase_22 AC 14 ms
15,624 KB
testcase_23 AC 47 ms
15,392 KB
testcase_24 AC 47 ms
15,376 KB
testcase_25 AC 82 ms
15,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000009;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/02  Problem: yukicoder189 / Link: https://yukicoder.me/problems/no/189  ----- */
/* ------問題------

ある日、新しい暦「おたく暦」が採用されることになりました。
おたく暦は1年をMヶ月、1ヶ月をD日とする暦です。
例えばMとDがそれぞれ2と3であったとき、1年は1月1日、1月2日、1月3日、2月1日、2月2日、2月3日の6日間で構成されます。現在は最適なMMとDDが検討されています。

XX月YY日についてXXの数字和とYYの数字和が等しいとき、XX月YY日は"SUPER HAPPY DAY"と呼ばれます。
ここで数字和とは与えられた整数の各桁の数字が表す数の総和です。
例えば4月22日、10月1日、121月2020日は4=2+2、1+0=1、1+2+1=2+0+2+0となりSUPER HAPPY DAYです。
一方、4月5日や10月19日、1234月123450日は4≠54≠5、1+0≠1+9、1+2+3+4≠1+2+3+4+5+0となり、SUPER HAPPY DAYではありません。

kamipeipaa君はおたく暦のMMとDDが定まったとき,1年間にどれだけSUPER HAPPY DAYがあるか気になっています。
kamipeipaa君のために1年間に含まれるSUPER HAPPY DAYの数をmod 1000000009で求めてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

LL dp[202][1900][2][2];

LL f(string &target, int i, int sum, int less = 0, int side = 0) {
	if (i == -1) {
		assert(sum >= 0);
		return (sum == 0);
	}
	LL &res = dp[i][sum][less][side];
	if (res != -1)return res;

	res = 0;
	int num = target[i] - '0';
	int Max = less ? 9 : num;
	FOR(nx, 0, Max + 1) {
		if (sum - nx < 0)break;
		res += f(target, i - 1, sum - nx, less | (nx < Max), side)%MOD;
		//debug(res);
		res = (res+ MOD) % MOD;
	}

	return res%MOD;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	string M, D;
	cin >> M >> D;
	reverse(ALL(M));
	reverse(ALL(D));
	fill(***dp, ***dp + 202 * 1900 * 2 * 2, -1);
	FOR(sum, 1, 1809 + 1) {
		//debug(f(M, SZ(M) - 1, i, 0));
		//debug(f(D, SZ(D) - 1, i, 0));
		ans += (f(M, SZ(M) - 1, sum,0, 0) % MOD)*(f(D, SZ(D) - 1, sum, 0,1) % MOD);
		//debug(ans);
		ans = (ans%MOD + MOD) % MOD;
	}
	cout << ans << "\n";

	return 0;
}
0