結果

問題 No.315 世界のなんとか3.5
ユーザー koyumeishikoyumeishi
提出日時 2015-12-01 00:41:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,198 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 81,832 KB
最終ジャッジ日時 2023-10-12 06:11:26
合計ジャッジ時間 42,502 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
76,264 KB
testcase_01 AC 146 ms
78,400 KB
testcase_02 AC 210 ms
78,876 KB
testcase_03 AC 99 ms
77,096 KB
testcase_04 AC 100 ms
77,268 KB
testcase_05 AC 149 ms
77,992 KB
testcase_06 AC 210 ms
78,808 KB
testcase_07 AC 150 ms
78,420 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 WA -
testcase_34 TLE -
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import array

mod = 1000000007
a,b,p = input().split()
p = int(p)

#dp small mod3 has3 mod p
def calc(x):
	sz = len(x)
	dp = [[0 for col in range(2*4*2)] for row in range(p)]
	dp_ = [[0 for col in range(2*4*2)] for row in range(p)]

	dp[0][0] = 1

	for i in range(sz) :
		k = ord(x[i]) - ord('0')


		if i<sz-5 :
			#initialize
			for small in range(2) :
				for mod3 in range(3) :
					for has3 in range(2) :
						s = (small<<3)|(mod3<<1)|has3
						dp_[0][s] = 0

			for small in range(2) :
				for mod3 in range(3) :
					for has3 in range(3) :
						s = (small<<3)|(mod3<<1)|has3

						for d in range(10) :
							if small==0 and d>k :
								continue
							m1_ = small | (1 if d<k else 0)
							m2_ = (mod3 * 10 + d) % 3
							m3_ = has3 | (1 if d==3 else 0)
							s_ = (m1_<<3)|(m2_<<1)|m3_

							dp_[0][s_] += dp[0][s]
							if(dp_[0][s_] >= mod):
								dp_[0][s_] -= mod

		else :
			for j in range(p) : 
				for small in range(2) :
					for mod3 in range(3) :
						for has3 in range(2) :
							s = (small<<3)|(mod3<<1)|has3
							dp_[j][s] = 0
			for j in range(p) :

				for small in range(2) :
					for mod3 in range(3) :
						for has3 in range(2) :
							s = (small<<3)|(mod3<<1)|has3
							for d in range(10) :
								if small==0 and d>k :
									continue
								m1_ = small | (1 if d<k else 0)
								m2_ = (mod3 * 10 + d) % 3
								m3_ = has3 | (1 if d==3 else 0)
								s_ = (m1_<<3)|(m2_<<1)|m3_
							
								j_ = (j*10 + d) % p

								dp_[j_][s_] += dp[j][s]
								if(dp_[j_][s_] >= mod):
									dp_[j_][s_] -= mod

		dp, dp_ = dp_, dp

	ret = 0
	for j in range(p) : 
		if j%p == 0 :
			continue

		for small in range(2) :
			for mod3 in range(3) :
				for has3 in range(2) :
					if (has3==0 and mod3 != 0):
						continue
					s = (small<<3)|(mod3<<1)|has3
					ret += dp[j][s];
					ret += -mod if ret>=mod else 0

	return ret




ans = calc(b)
ans = ans - calc(a)

ans += mod if ans<0 else 0

has3_ = 0
mod3_ = 0
modp_ = 0
for i in range(len(a)):
	k = ord(a[i])-ord('0')
	has3_ |= 1 if k == 3 else 0
	mod3_ = (mod3_ * 10 + k) % 3
	modp_ = (modp_ * 10 + k) % p

if (has3_!=0 or mod3_ == 0) and modp_ != 0 :
	ans += 1

ans %= mod

print(ans)

0