結果

問題 No.260 世界のなんとか3
ユーザー pekempeypekempey
提出日時 2016-12-28 13:03:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,468 bytes
コンパイル時間 1,579 ms
コンパイル使用メモリ 167,488 KB
実行使用メモリ 10,912 KB
最終ジャッジ日時 2023-08-21 18:00:51
合計ジャッジ時間 4,519 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 76 ms
10,912 KB
testcase_04 AC 76 ms
10,884 KB
testcase_05 AC 37 ms
6,080 KB
testcase_06 AC 24 ms
5,128 KB
testcase_07 AC 72 ms
9,772 KB
testcase_08 AC 82 ms
9,884 KB
testcase_09 AC 41 ms
6,596 KB
testcase_10 AC 59 ms
9,156 KB
testcase_11 AC 78 ms
10,384 KB
testcase_12 AC 64 ms
8,616 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 73 ms
9,848 KB
testcase_15 AC 16 ms
4,996 KB
testcase_16 AC 58 ms
8,548 KB
testcase_17 AC 43 ms
7,184 KB
testcase_18 AC 37 ms
6,772 KB
testcase_19 AC 76 ms
9,812 KB
testcase_20 AC 48 ms
7,424 KB
testcase_21 AC 55 ms
7,816 KB
testcase_22 AC 58 ms
8,740 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 71 ms
9,284 KB
testcase_25 AC 120 ms
10,888 KB
testcase_26 AC 73 ms
10,880 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 73 ms
10,912 KB
testcase_29 AC 73 ms
10,864 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