結果

問題 No.260 世界のなんとか3
ユーザー pekempeypekempey
提出日時 2016-12-28 13:31:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 1,573 ms
コンパイル使用メモリ 176,524 KB
実行使用メモリ 11,308 KB
最終ジャッジ日時 2023-08-21 18:01:17
合計ジャッジ時間 3,914 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 61 ms
11,288 KB
testcase_04 AC 61 ms
11,104 KB
testcase_05 AC 29 ms
6,396 KB
testcase_06 AC 19 ms
5,292 KB
testcase_07 AC 57 ms
9,880 KB
testcase_08 AC 65 ms
10,080 KB
testcase_09 AC 33 ms
6,764 KB
testcase_10 AC 48 ms
9,224 KB
testcase_11 AC 62 ms
10,364 KB
testcase_12 AC 51 ms
8,720 KB
testcase_13 AC 10 ms
4,412 KB
testcase_14 AC 59 ms
9,952 KB
testcase_15 AC 13 ms
4,784 KB
testcase_16 AC 47 ms
8,664 KB
testcase_17 AC 34 ms
7,424 KB
testcase_18 AC 29 ms
6,928 KB
testcase_19 AC 61 ms
9,960 KB
testcase_20 AC 38 ms
7,560 KB
testcase_21 AC 44 ms
7,892 KB
testcase_22 AC 46 ms
8,868 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 57 ms
9,440 KB
testcase_25 AC 95 ms
11,180 KB
testcase_26 AC 58 ms
11,092 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 58 ms
11,060 KB
testcase_29 AC 58 ms
11,308 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 pack(int more, int less, int has3, int mod24) {
	int ret = mod24;
	ret = ret * 2 + has3;
	ret = ret * 2 + less;
	ret = ret * 2 + more;
	return ret;
}

tuple<int, int, int, int> unpack(int v) {
	int more = v % 2; v /= 2;
	int less = v % 2; v /= 2;
	int has3 = v % 2; v /= 2;
	int mod24 = v;
	return make_tuple(more, less, has3, mod24);
}

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 * 24); // pos, more, less, has3, mod3, mod8

	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 2 * 2 * 2 * 24; j++) {
			int more, less, has3, mod24;
			tie(more, less, has3, mod24) = unpack(j);

			int L = more ? 0 : A[i] - '0';
			int R = less ? 9 : B[i] - '0';

			for (int d = L; d <= R; d++) {
				int nj = pack(more || d > L, less || d < R, has3 || d == 3, (mod24 * 10 + d) % 24);
				upd(dp[i + 1][nj], dp[i][j]);
			}
		}
	}

	int ans = 0;
	for (int j = 0; j < 2 * 2 * 2 * 24; j++) {
		int has3, mod24;
		tie(ignore, ignore, has3, mod24) = unpack(j);
		if ((has3 || mod24 % 3 == 0) && mod24 % 8 != 0) {
			upd(ans, dp[n][j]);
		}
	}
	cout << ans << endl;
}
0