結果

問題 No.260 世界のなんとか3
ユーザー Yang33Yang33
提出日時 2017-11-02 22:06:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,156 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 146,908 KB
実行使用メモリ 12,104 KB
最終ジャッジ日時 2023-08-14 15:32:03
合計ジャッジ時間 3,796 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,840 KB
testcase_01 AC 5 ms
10,920 KB
testcase_02 AC 5 ms
10,912 KB
testcase_03 AC 76 ms
11,824 KB
testcase_04 AC 76 ms
11,844 KB
testcase_05 AC 30 ms
11,316 KB
testcase_06 AC 21 ms
11,196 KB
testcase_07 AC 64 ms
11,792 KB
testcase_08 AC 66 ms
11,740 KB
testcase_09 AC 35 ms
11,248 KB
testcase_10 AC 60 ms
11,836 KB
testcase_11 AC 69 ms
11,796 KB
testcase_12 AC 54 ms
11,516 KB
testcase_13 AC 15 ms
11,108 KB
testcase_14 AC 65 ms
11,680 KB
testcase_15 AC 18 ms
11,160 KB
testcase_16 AC 53 ms
11,800 KB
testcase_17 AC 41 ms
11,500 KB
testcase_18 AC 36 ms
11,296 KB
testcase_19 AC 64 ms
11,720 KB
testcase_20 AC 42 ms
11,692 KB
testcase_21 AC 45 ms
11,596 KB
testcase_22 AC 55 ms
11,584 KB
testcase_23 AC 10 ms
11,100 KB
testcase_24 AC 60 ms
11,660 KB
testcase_25 AC 75 ms
12,088 KB
testcase_26 AC 72 ms
11,876 KB
testcase_27 AC 5 ms
11,060 KB
testcase_28 AC 76 ms
12,104 KB
testcase_29 AC 79 ms
11,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/02  Problem: yukicoder260 / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;
LL dp[10004][3][2][8][2];
LL f(string &target, int i, int three = 0, int has = 0, int eight = 0, int less = 0) {
	if (i == -1) {
		return ((three == 0 || has == 1) && eight != 0);
	}
	if (dp[i][three][has][eight][less] != -1 && less == 1)return dp[i][three][has][eight][less];
	LL res = 0;
	int num = target[i] - '0';
	int Max = less ? 9 : num;
	FOR(nx, 0, Max + 1) {
		res += f(target, i - 1,(three+nx)%3,has||nx==3,(eight*10+nx)%8,less||(nx<Max))%MOD;
		res %= MOD;
	}
	if (less == 1)return (dp[i][three][has][eight][less] = res);
	return res;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	string A, B; cin >> A >> B;
	int i = SZ(A) - 1;
	while (i >= 0) {
		if (A[i] == '0') {
			A[i] = '9';
		}
		else {
			A[i]--;
			break;
		}
		i--;
	}
	if (A[0] == '0')A = A.substr(1);
	reverse(ALL(A));
	reverse(ALL(B));
	fill(****dp, ****dp + 10004 * 3 * 2 * 8 * 2, -1);
	ans = f(B, SZ(B) - 1);
	if(A!="0")ans -= f(A, SZ(A) - 1);

	cout << (ans+MOD)%MOD << "\n";

	return 0;
}
0