結果

問題 No.260 世界のなんとか3
ユーザー pekempeypekempey
提出日時 2016-12-28 13:35:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,629 bytes
コンパイル時間 4,097 ms
コンパイル使用メモリ 174,188 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 18:02:33
合計ジャッジ時間 4,955 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 57 ms
4,376 KB
testcase_04 AC 57 ms
4,376 KB
testcase_05 AC 28 ms
4,376 KB
testcase_06 AC 18 ms
4,380 KB
testcase_07 AC 54 ms
4,380 KB
testcase_08 AC 63 ms
4,380 KB
testcase_09 AC 30 ms
4,380 KB
testcase_10 AC 45 ms
4,380 KB
testcase_11 AC 58 ms
4,376 KB
testcase_12 AC 48 ms
4,380 KB
testcase_13 AC 10 ms
4,376 KB
testcase_14 AC 56 ms
4,380 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 43 ms
4,376 KB
testcase_17 AC 32 ms
4,376 KB
testcase_18 AC 27 ms
4,380 KB
testcase_19 AC 58 ms
4,380 KB
testcase_20 AC 36 ms
4,380 KB
testcase_21 AC 42 ms
4,384 KB
testcase_22 AC 44 ms
4,376 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 53 ms
4,380 KB
testcase_25 AC 93 ms
4,380 KB
testcase_26 AC 54 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 54 ms
4,376 KB
testcase_29 AC 54 ms
4,380 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;
	vector<int> dp0(2 * 2 * 2 * 24);
	vector<int> dp1(2 * 2 * 2 * 24);

	dp0[0] = 1;
	for (int i = 0; i < n; i++) {
		fill(begin(dp1), end(dp1), 0);
		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(dp1[nj], dp0[j]);
			}
		}
		swap(dp0, dp1);
	}

	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, dp0[j]);
		}
	}
	cout << ans << endl;
}
0