結果

問題 No.260 世界のなんとか3
ユーザー pekempeypekempey
提出日時 2016-12-28 13:02:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,427 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 182,304 KB
実行使用メモリ 25,368 KB
最終ジャッジ日時 2023-08-21 18:01:12
合計ジャッジ時間 6,539 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 166 ms
25,296 KB
testcase_04 AC 166 ms
25,360 KB
testcase_05 AC 82 ms
11,492 KB
testcase_06 AC 50 ms
8,572 KB
testcase_07 AC 157 ms
22,000 KB
testcase_08 AC 183 ms
22,348 KB
testcase_09 AC 92 ms
12,836 KB
testcase_10 AC 130 ms
20,204 KB
testcase_11 AC 170 ms
23,344 KB
testcase_12 AC 141 ms
18,708 KB
testcase_13 AC 25 ms
6,260 KB
testcase_14 AC 163 ms
22,172 KB
testcase_15 AC 34 ms
7,456 KB
testcase_16 AC 126 ms
18,524 KB
testcase_17 AC 98 ms
14,740 KB
testcase_18 AC 82 ms
13,340 KB
testcase_19 AC 170 ms
22,216 KB
testcase_20 AC 110 ms
15,336 KB
testcase_21 AC 122 ms
16,308 KB
testcase_22 AC 127 ms
19,008 KB
testcase_23 AC 12 ms
4,848 KB
testcase_24 AC 156 ms
20,704 KB
testcase_25 AC 266 ms
25,232 KB
testcase_26 AC 162 ms
25,368 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 160 ms
25,364 KB
testcase_29 AC 159 ms
25,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int mod = 1e9 + 7;

template<class T>
auto multiVector(T init, int n) {
	return vector<T>(n, init);
}

template<class T, class... Args>
auto multiVector(T init, int n, Args... ns) {
	return vector<decltype(multiVector<T>(init, ns...))>(n, multiVector<T>(init, ns...));
}

void upd(int &x, int y) {
	if ((x += y) >= mod) {
		x -= mod;
	}
}

int main() {
	string A, B;
	cin >> A >> B;
	int n = max(A.size(), B.size());
	A = string(n - A.size(), '0') + A;
	B = string(n - B.size(), '0') + B;
	auto dp = multiVector<int>(0, n + 1, 2, 2, 2, 3, 8); // pos, more, less, has3, mod3, mod8

	dp[0][0][0][0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				for (int l = 0; l < 2; l++) {
					for (int s = 0; s < 3; s++) {
						for (int t = 0; t < 8; t++) {
							int L = j ? 0 : A[i] - '0';
							int R = k ? 9 : B[i] - '0';
							for (int d = L; d <= R; d++) {
								upd(dp[i + 1][j || d > L][k || d < R][l || d == 3][(s + d) % 3][(t * 10 + d) % 8], dp[i][j][k][l][s][t]);
							}
						}
					}
				}
			}
		}
	}

	int ans = 0;
	for (int j = 0; j < 2; j++) {
		for (int k = 0; k < 2; k++) {
			for (int l = 0; l < 2; l++) {
				for (int s = 0; s < 3; s++) {
					for (int t = 1; t < 8; t++) {
						if (l || s == 0) {	
							upd(ans, dp[n][j][k][l][s][t]);
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
}
0