結果

問題 No.260 世界のなんとか3
ユーザー kyawashellkyawashell
提出日時 2018-03-26 12:23:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,645 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 202,984 KB
実行使用メモリ 11,092 KB
最終ジャッジ日時 2023-09-07 12:40:29
合計ジャッジ時間 7,000 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 223 ms
10,960 KB
testcase_04 AC 224 ms
10,956 KB
testcase_05 AC 45 ms
6,124 KB
testcase_06 AC 31 ms
5,196 KB
testcase_07 AC 144 ms
9,764 KB
testcase_08 AC 106 ms
9,892 KB
testcase_09 AC 58 ms
6,532 KB
testcase_10 AC 163 ms
9,192 KB
testcase_11 AC 155 ms
10,208 KB
testcase_12 AC 101 ms
8,656 KB
testcase_13 AC 28 ms
4,380 KB
testcase_14 AC 142 ms
9,828 KB
testcase_15 AC 38 ms
4,752 KB
testcase_16 AC 125 ms
8,600 KB
testcase_17 AC 99 ms
7,224 KB
testcase_18 AC 95 ms
6,824 KB
testcase_19 AC 126 ms
9,772 KB
testcase_20 AC 90 ms
7,644 KB
testcase_21 AC 81 ms
7,864 KB
testcase_22 AC 142 ms
8,760 KB
testcase_23 AC 14 ms
4,384 KB
testcase_24 AC 112 ms
9,440 KB
testcase_25 AC 144 ms
11,092 KB
testcase_26 AC 86 ms
11,000 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 160 ms
10,920 KB
testcase_29 AC 282 ms
10,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll mod = 1e9+7;
string A,B;
ll dp [200000][2][2][3][8];
int main(){
	cin >> A >> B;


	ll n = B.length();

	dp[0][0][0][0][0] = 1;

	REP(i,n) {
		REP(j,2) {
			REP(k,2) {
				REP(l,3) {
					REP(m,8) {
						ll lim = (j ? 9 : B[i] - '0');

						REP(d,lim + 1) {
							(dp[i + 1][j || d < lim][k || d == 3][(10 * l + d) % 3][(10 * m + d) % 8] += dp[i][j][k][l][m] ) %= mod;
						}
					}
				}
			}
		}
	}

	ll ans = 0;
	REP(j,2) {
		REP(k,2) {
			REP(l,3) {
				REP(m,8) {
					if((k || !l) && m) {
						(ans += dp[n][j][k][l][m]) %= mod;
					}
				}
			}
		}
	}

	n = A.length();
	REP(i,n + 1) {
		REP(j,2) {
			REP(k,2) {
				REP(l,3) {
					REP(m,8) {
						dp[i][j][k][l][m] = 0;
					}
				}
			}
		}
	}

	dp[0][0][0][0][0] = 1;

	REP(i,n) {
		REP(j,2) {
			REP(k,2) {
				REP(l,3) {
					REP(m,8) {
						ll lim = (j ? 9 : A[i] - '0');

						REP(d,lim + 1) {
							(dp[i + 1][j || d < lim][k || d == 3][(10 * l + d) % 3][(10 * m + d) % 8] += dp[i][j][k][l][m] ) %= mod;
						}
					}
				}
			}
		}
	}

	
	REP(j,2) {
		REP(k,2) {
			REP(l,3) {
				REP(m,8) {
					if(j && (k || !l) && m) {
						(ans += mod - dp[n][j][k][l][m]) %= mod;
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}
0