結果

問題 No.260 世界のなんとか3
ユーザー pekempeypekempey
提出日時 2016-12-28 13:03:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,468 bytes
コンパイル時間 2,790 ms
コンパイル使用メモリ 170,160 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-05-08 23:38:32
合計ジャッジ時間 4,613 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 78 ms
11,008 KB
testcase_04 AC 78 ms
11,008 KB
testcase_05 AC 38 ms
6,272 KB
testcase_06 AC 25 ms
5,376 KB
testcase_07 AC 74 ms
9,728 KB
testcase_08 AC 85 ms
9,856 KB
testcase_09 AC 42 ms
6,656 KB
testcase_10 AC 60 ms
9,216 KB
testcase_11 AC 79 ms
10,368 KB
testcase_12 AC 66 ms
8,576 KB
testcase_13 AC 13 ms
5,376 KB
testcase_14 AC 75 ms
9,984 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 60 ms
8,704 KB
testcase_17 AC 44 ms
7,168 KB
testcase_18 AC 38 ms
7,040 KB
testcase_19 AC 80 ms
9,856 KB
testcase_20 AC 49 ms
7,552 KB
testcase_21 AC 58 ms
7,936 KB
testcase_22 AC 59 ms
8,832 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 AC 73 ms
9,344 KB
testcase_25 AC 124 ms
11,136 KB
testcase_26 AC 75 ms
11,008 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 75 ms
11,008 KB
testcase_29 AC 75 ms
11,008 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;
	static int dp[10001][2][2][2][3][8];
	// 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