結果

問題 No.315 世界のなんとか3.5
ユーザー shobonvipshobonvip
提出日時 2022-08-07 19:54:05
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,328 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 81,584 KB
実行使用メモリ 76,084 KB
最終ジャッジ日時 2023-10-17 14:35:04
合計ジャッジ時間 11,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,396 KB
testcase_01 AC 54 ms
61,636 KB
testcase_02 AC 64 ms
61,736 KB
testcase_03 AC 48 ms
59,404 KB
testcase_04 AC 48 ms
59,404 KB
testcase_05 AC 53 ms
61,636 KB
testcase_06 AC 64 ms
61,736 KB
testcase_07 AC 53 ms
61,636 KB
testcase_08 AC 54 ms
61,636 KB
testcase_09 AC 47 ms
59,404 KB
testcase_10 AC 46 ms
59,404 KB
testcase_11 AC 47 ms
59,404 KB
testcase_12 AC 1,019 ms
75,704 KB
testcase_13 AC 1,015 ms
75,704 KB
testcase_14 AC 1,947 ms
76,084 KB
testcase_15 AC 1,947 ms
76,084 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9 + 7
a,b,ps = input().split()
p = int(ps)

def solve(x, mode):
	size = len(x)
	tp = 3*p
	dpy = [0] * tp
	dpn = [0] * tp
	ndpy = [0] * tp
	ndpn = [0] * tp
	nowisy = 0
	now24 = 0
	for num in range(size):
		for i in range(tp):
			ndpy[i] = 0
			ndpn[i] = 0
		
		#継続
		for i in range(10):
			if i == 3:
				v = i
				for j in range(tp):
					ndpy[v%tp] += dpy[j] + dpn[j]
					ndpy[v%tp] %= mod
					v = (v+10)%tp
			else:
				v = i
				for j in range(tp):
					ndpy[v%tp] += dpy[j]
					ndpy[v%tp] %= mod
					ndpn[v%tp] += dpn[j]
					ndpn[v%tp] %= mod
					v = (v+10)%tp
		
		#新規
		if num > 0:
			for i in range(1, 10):
				if i == 3:
					ndpy[i] += 1
				else:
					ndpn[i] += 1
		
		targ = int(x[num])
		
		#解放
		if nowisy:
			for i in range(num<1, targ):
				ndpy[(i+10*now24)%tp] += 1
		else:
			for i in range(num<1, targ):
				if i == 3:
					ndpy[(i+10*now24)%tp] += 1
				else:
					ndpn[(i+10*now24)%tp] += 1
		
		for i in range(tp):
			dpn[i] = ndpn[i]
			dpy[i] = ndpy[i]
		
		if targ == 3:
			nowisy = 1
		
		now24 = (10*now24+targ) % tp
	
	if mode:
		if nowisy:
			dpy[now24] += 1
		else:
			dpn[now24] += 1
	
	ans = 0
	for i in range(tp):
		if i % p != 0:
			ans += dpy[i]
			ans %= mod
			if i % 3 == 0:
				ans += dpn[i]
				ans %= mod
	
	return ans

print((solve(b, 1)-solve(a, 0)) % mod)
0