結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | koyumeishi |
提出日時 | 2015-12-09 02:23:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 528 ms / 2,000 ms |
コード長 | 2,051 bytes |
コンパイル時間 | 373 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 78,992 KB |
最終ジャッジ日時 | 2024-09-14 20:55:04 |
合計ジャッジ時間 | 10,172 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
53,376 KB |
testcase_01 | AC | 60 ms
64,128 KB |
testcase_02 | AC | 108 ms
76,332 KB |
testcase_03 | AC | 55 ms
59,776 KB |
testcase_04 | AC | 53 ms
60,928 KB |
testcase_05 | AC | 83 ms
72,448 KB |
testcase_06 | AC | 121 ms
77,312 KB |
testcase_07 | AC | 82 ms
71,296 KB |
testcase_08 | AC | 88 ms
74,496 KB |
testcase_09 | AC | 56 ms
60,928 KB |
testcase_10 | AC | 56 ms
60,800 KB |
testcase_11 | AC | 56 ms
61,056 KB |
testcase_12 | AC | 165 ms
76,032 KB |
testcase_13 | AC | 169 ms
76,416 KB |
testcase_14 | AC | 264 ms
77,036 KB |
testcase_15 | AC | 257 ms
76,928 KB |
testcase_16 | AC | 285 ms
77,312 KB |
testcase_17 | AC | 286 ms
77,184 KB |
testcase_18 | AC | 206 ms
77,568 KB |
testcase_19 | AC | 215 ms
76,928 KB |
testcase_20 | AC | 259 ms
78,332 KB |
testcase_21 | AC | 242 ms
77,824 KB |
testcase_22 | AC | 322 ms
77,696 KB |
testcase_23 | AC | 325 ms
77,952 KB |
testcase_24 | AC | 292 ms
77,568 KB |
testcase_25 | AC | 332 ms
78,336 KB |
testcase_26 | AC | 306 ms
77,252 KB |
testcase_27 | AC | 274 ms
76,748 KB |
testcase_28 | AC | 333 ms
78,464 KB |
testcase_29 | AC | 481 ms
78,796 KB |
testcase_30 | AC | 443 ms
77,568 KB |
testcase_31 | AC | 425 ms
77,568 KB |
testcase_32 | AC | 503 ms
78,772 KB |
testcase_33 | AC | 324 ms
77,952 KB |
testcase_34 | AC | 488 ms
78,992 KB |
testcase_35 | AC | 528 ms
78,380 KB |
ソースコード
import array mod = 1000000007 a,b,p = input().split() p = int(p) memo = [[[] for col in range(8)] for row in range(10)] def gen_memo(): global memo for k in range(10) : for sml in range(2) : for mod3 in range(4) : s = (sml<<2)|mod3 nx = [0 for i in range(8)] for d in range(10) : if sml==0 and d>k : continue sml_ = 1 if (d<k or sml==1) else 0 mod3_ = 3 if (mod3==3 or d==3) else (mod3+d)%3 s_ = (sml_<<2) | mod3_ nx[s_] += 1 for s_ in range(8) : if nx[s_] > 0 : memo[k][s].append( (s_, nx[s_]) ) def calc(x): sz = len(x) dp = [[[0 for col in range(8)] for row in range(p)] for hoge in range(2)] dp[0][0][0] = 1 u = 0 v = 1 for i in range(sz) : k = ord(x[i]) - ord('0') for j in range(1 if i<sz-4 else p): for sml in range(2): for mod3 in range(4): s = (sml<<2)|mod3 val = dp[u][j][s] dp[u][j][s] = 0 if val == 0: continue if i<sz-5: for c in range(len(memo[k][s])): s_ = memo[k][s][c][0] dp[v][0][ s_ ] += val * memo[k][s][c][1] if dp[v][0][s_] >= mod: dp[v][0][s_] %= mod else: for d in range(10) : if sml==0 and d>k : break sml_ = 1 if (sml==1 or d<k) else 0 mod3_ = 3 if (mod3==3 or d==3) else (mod3+d)%3 s_ = (sml_<<2) | mod3_ j_ = (j*10 + d) % p dp[v][j_][s_] += val if dp[v][j_][s_] >= mod: dp[v][j_][s_] -= mod u,v = v,u ret = 0 for j in range(p) : if j%p == 0 : continue for sml in range(2) : for mod3 in range(4) : if mod3==0 or mod3==3: s = (sml<<2)|mod3 ret += dp[u][j][s]; ret += -mod if ret>=mod else 0 return ret gen_memo() ans = calc(b) ans = ans - calc(a) ans += mod if ans<0 else 0 def hoge(): global ans mod3__ = 0 modp__ = 0 for i in range(len(a)): k = ord(a[i])-ord('0') mod3__ = 3 if mod3__==3 or k==3 else (mod3__ + k)%3 modp__ = (modp__ * 10 + k) % p if (mod3__==0 or mod3__==3) and modp__ != 0 : ans += 1 ans %= mod hoge() print(ans)