結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | koyumeishi |
提出日時 | 2015-12-09 02:22:55 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,051 bytes |
コンパイル時間 | 248 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 17,272 KB |
最終ジャッジ日時 | 2024-09-14 20:53:58 |
合計ジャッジ時間 | 28,191 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
16,384 KB |
testcase_01 | AC | 33 ms
11,136 KB |
testcase_02 | AC | 66 ms
11,136 KB |
testcase_03 | AC | 33 ms
11,008 KB |
testcase_04 | AC | 33 ms
11,008 KB |
testcase_05 | AC | 37 ms
11,136 KB |
testcase_06 | AC | 70 ms
11,136 KB |
testcase_07 | AC | 36 ms
11,136 KB |
testcase_08 | AC | 40 ms
11,008 KB |
testcase_09 | AC | 34 ms
11,008 KB |
testcase_10 | AC | 34 ms
11,008 KB |
testcase_11 | AC | 34 ms
11,136 KB |
testcase_12 | AC | 782 ms
11,264 KB |
testcase_13 | AC | 778 ms
11,136 KB |
testcase_14 | AC | 1,540 ms
11,188 KB |
testcase_15 | AC | 1,548 ms
11,264 KB |
testcase_16 | AC | 1,562 ms
11,180 KB |
testcase_17 | AC | 1,569 ms
11,184 KB |
testcase_18 | AC | 796 ms
11,264 KB |
testcase_19 | AC | 799 ms
11,264 KB |
testcase_20 | AC | 860 ms
11,520 KB |
testcase_21 | AC | 854 ms
11,520 KB |
testcase_22 | AC | 1,727 ms
11,440 KB |
testcase_23 | AC | 1,641 ms
11,436 KB |
testcase_24 | AC | 1,556 ms
11,392 KB |
testcase_25 | AC | 1,630 ms
11,448 KB |
testcase_26 | AC | 1,579 ms
11,180 KB |
testcase_27 | AC | 1,553 ms
11,264 KB |
testcase_28 | AC | 1,700 ms
11,436 KB |
testcase_29 | TLE | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
ソースコード
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)