結果

問題 No.260 世界のなんとか3
ユーザー tancahn2380tancahn2380
提出日時 2017-11-30 21:04:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,994 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 88,212 KB
実行使用メモリ 20,708 KB
最終ジャッジ日時 2023-08-18 10:59:13
合計ジャッジ時間 4,588 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,352 KB
testcase_01 AC 2 ms
5,428 KB
testcase_02 AC 3 ms
5,404 KB
testcase_03 AC 159 ms
20,408 KB
testcase_04 AC 159 ms
20,484 KB
testcase_05 AC 32 ms
8,280 KB
testcase_06 AC 22 ms
7,392 KB
testcase_07 AC 108 ms
15,808 KB
testcase_08 AC 76 ms
12,424 KB
testcase_09 AC 44 ms
9,228 KB
testcase_10 AC 122 ms
16,816 KB
testcase_11 AC 115 ms
16,168 KB
testcase_12 AC 71 ms
11,804 KB
testcase_13 AC 21 ms
7,196 KB
testcase_14 AC 105 ms
15,164 KB
testcase_15 AC 29 ms
7,932 KB
testcase_16 AC 91 ms
13,856 KB
testcase_17 AC 72 ms
12,088 KB
testcase_18 AC 70 ms
11,812 KB
testcase_19 AC 90 ms
13,788 KB
testcase_20 AC 65 ms
11,260 KB
testcase_21 AC 57 ms
10,708 KB
testcase_22 AC 104 ms
15,116 KB
testcase_23 AC 12 ms
6,240 KB
testcase_24 AC 81 ms
12,884 KB
testcase_25 AC 103 ms
13,204 KB
testcase_26 AC 61 ms
13,128 KB
testcase_27 AC 2 ms
5,524 KB
testcase_28 AC 160 ms
20,708 KB
testcase_29 AC 201 ms
20,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
//typedef pair<LL, LL> P;
//typedef pair<P, P> PP;

LL dp[101010][2][2][3][8];//keta,less,has3,mod3,mod8
LL dp2[101010][2][2][3][8];
string a;
int n;
const LL MOD = 1e9 + 7;

int main() {
	cin >> a;
	for (int c = a.size() - 1; c >= 0; c--) {
		if (a[c] != '0') {
			a[c]--;
			break;
		}
		else {
			a[c] = '9';
		}
	}
	n = a.length();
	dp[0][0][0][0][0] = 1;
	REP(i, n)REP(j, 2)REP(k, 2)REP(l, 3)REP(m, 8) {
		int lim = (j ? 9 : a[i] - '0');
		REP(d, lim + 1) {
			(dp[i + 1][j || d < lim][k || d == 3][(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 == 0) && m != 0)(ans += dp[n][j][k][l][m]) %= MOD;
	string b;
	cin >> b;
	n = b.length();
	dp2[0][0][0][0][0] = 1;
	REP(i, n)REP(j, 2)REP(k, 2)REP(l, 3)REP(m, 8) {
		int lim = (j ? 9 : b[i] - '0');
		REP(d, lim + 1) {
			(dp2[i + 1][j || d < lim][k || d == 3][(l + d) % 3][(10 * m + d) % 8] += dp2[i][j][k][l][m]) %= MOD;
		}
	}
	LL ans2 = 0;
	REP(j, 2)REP(k, 2)REP(l, 3)REP(m, 8)if ((k || l == 0) && m != 0)(ans2 += dp2[n][j][k][l][m]) %= MOD;

	cout << (ans2 - ans + MOD) % MOD << endl;
	//system("pause");
}
0