結果

問題 No.260 世界のなんとか3
ユーザー Div9851Div9851
提出日時 2017-10-08 14:52:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,030 bytes
コンパイル時間 1,290 ms
コンパイル使用メモリ 162,424 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 13:24:48
合計ジャッジ時間 3,367 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 72 ms
6,944 KB
testcase_04 AC 72 ms
6,940 KB
testcase_05 AC 15 ms
6,940 KB
testcase_06 AC 10 ms
6,944 KB
testcase_07 AC 49 ms
6,944 KB
testcase_08 AC 35 ms
6,944 KB
testcase_09 AC 20 ms
6,944 KB
testcase_10 AC 56 ms
6,944 KB
testcase_11 AC 52 ms
6,940 KB
testcase_12 AC 32 ms
6,944 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 48 ms
6,940 KB
testcase_15 AC 14 ms
6,944 KB
testcase_16 AC 41 ms
6,940 KB
testcase_17 AC 33 ms
6,944 KB
testcase_18 AC 32 ms
6,940 KB
testcase_19 AC 41 ms
6,944 KB
testcase_20 AC 30 ms
6,940 KB
testcase_21 AC 26 ms
6,944 KB
testcase_22 AC 47 ms
6,940 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 AC 37 ms
6,940 KB
testcase_25 AC 46 ms
6,940 KB
testcase_26 AC 27 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 52 ms
6,940 KB
testcase_29 AC 91 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
LL solve(string S, bool less) {
	LL dp[2][2][2][3][8] = { 0 }; //j:Sより小さいか k:3を含んでいるか l:mod 3 m:mod 8
	dp[0][0][0][0][0] = 1;
	int now = 0;
	rep(i, S.size()) {
		rep(j, 2) rep(k, 2) rep(l, 3) rep(m, 8) {
			rep(d, 10) {
				if (!j && (S[i] - '0') < d) break;
				(dp[now ^ 1][j | (d < (S[i] - '0'))][k | (d == 3)][(l * 10 + d) % 3][(m * 10 + d) % 8] += dp[now][j][k][l][m]) %= MOD;
			}
		}
		rep(j, 2) rep(k, 2) rep(l, 3) rep(m, 8) {
			dp[now][j][k][l][m] = 0;
		}
		now ^= 1;
	}
	LL ans = 0;
	rep(j, 2) rep(k, 2) rep(l, 3) rep(m, 8) {
		if (less && !j) continue;
		if ((k || l==0) && m!=0) (ans += dp[now][j][k][l][m]) %= MOD;
	}
	return ans;
}
int main() {
	string A, B;
	cin >> A >> B;
	cout << (solve(B, 0) - solve(A, 1) + MOD) % MOD << endl;
}
0