結果
問題 | No.319 happy b1rthday 2 me |
ユーザー |
|
提出日時 | 2015-12-12 00:48:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,944 bytes |
コンパイル時間 | 1,320 ms |
コンパイル使用メモリ | 163,776 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-15 08:31:00 |
合計ジャッジ時間 | 2,204 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h>#define GET_MACRO(a, b, c, NAME, ...) NAME#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)#define rep2(i, a) rep3 (i, 0, a)#define rep3(i, a, b) for (int i = (a); i < (b); i++)#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)#define repr2(i, a) repr3 (i, 0, a)#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }using namespace std;typedef long long ll;ll dp[20][2][2][20][2]; // less, 0-1, num 12, leading zeropair<ll, ll> f(string S, bool less, bool onetwo) {if (S.length() <= 1) {int n = S[0] - '0';if (n <= 1) {return {0, 0};} else {return {0, 1};}}memset(dp, 0, sizeof(dp));int n = S.length();dp[0][0][0][0][0] = 1;rep (i, n) rep (j, 2) {rep (k, 2) rep (l, 19) rep (m, 2) {int lim = j ? 9 : S[i] - '0';rep (x, lim + 1) {if (onetwo && !m && x > 0 && x != 2) continue;if (onetwo && i == n - 1 && x != 1) continue;if (k == 0 && x == 1) {dp[i + 1][j || x < lim][1][l][m || x > 0] += dp[i][j][k][l][m];} else if (k == 1 && x == 1) {dp[i + 1][j || x < lim][1][l][m || x > 0] += dp[i][j][k][l][m];} else if (k == 1 && x == 2) {dp[i + 1][j || x < lim][0][l + 1][m || x > 0] += dp[i][j][k][l][m];} else {dp[i + 1][j || x < lim][0][l][m || x > 0] += dp[i][j][k][l][m];}}}}ll res1 = 0, res2 = 0;rep (j, 2) rep (k, 2) rep (l, 20) rep (m, 2) {if (j == 0 && less) continue;res1 += dp[n][j][k][l][m] * l;res2 += dp[n][j][k][l][m];}return {res1, res2 + 1};}int main() {string A, B;cin >> A >> B;ll ans = f(B, false, false).first - f(A, true, false).first;ans += f(B, true, true).second - f(A, true, true).second;cout << ans << endl;return 0;}