結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | koyumeishi |
提出日時 | 2015-12-01 02:38:31 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,231 bytes |
コンパイル時間 | 209 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 81,020 KB |
最終ジャッジ日時 | 2024-09-14 06:22:26 |
合計ジャッジ時間 | 34,114 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
63,232 KB |
testcase_01 | AC | 130 ms
77,076 KB |
testcase_02 | AC | 206 ms
79,304 KB |
testcase_03 | AC | 76 ms
72,192 KB |
testcase_04 | AC | 78 ms
72,704 KB |
testcase_05 | AC | 134 ms
77,468 KB |
testcase_06 | AC | 203 ms
77,936 KB |
testcase_07 | AC | 133 ms
77,412 KB |
testcase_08 | AC | 140 ms
77,276 KB |
testcase_09 | AC | 76 ms
72,960 KB |
testcase_10 | AC | 77 ms
73,216 KB |
testcase_11 | AC | 76 ms
72,064 KB |
testcase_12 | AC | 651 ms
77,632 KB |
testcase_13 | AC | 676 ms
77,076 KB |
testcase_14 | AC | 1,141 ms
78,656 KB |
testcase_15 | AC | 1,149 ms
78,408 KB |
testcase_16 | AC | 1,202 ms
79,268 KB |
testcase_17 | AC | 1,202 ms
79,436 KB |
testcase_18 | AC | 771 ms
79,220 KB |
testcase_19 | AC | 764 ms
78,612 KB |
testcase_20 | AC | 851 ms
79,904 KB |
testcase_21 | AC | 841 ms
79,940 KB |
testcase_22 | AC | 1,275 ms
80,012 KB |
testcase_23 | AC | 1,261 ms
80,000 KB |
testcase_24 | AC | 1,195 ms
79,312 KB |
testcase_25 | AC | 1,259 ms
80,056 KB |
testcase_26 | AC | 1,191 ms
79,044 KB |
testcase_27 | AC | 1,133 ms
78,408 KB |
testcase_28 | AC | 1,174 ms
80,012 KB |
testcase_29 | AC | 1,974 ms
80,352 KB |
testcase_30 | AC | 1,922 ms
79,020 KB |
testcase_31 | AC | 1,833 ms
78,224 KB |
testcase_32 | TLE | - |
testcase_33 | AC | 1,379 ms
79,984 KB |
testcase_34 | AC | 1,789 ms
79,528 KB |
testcase_35 | TLE | - |
ソースコード
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)] for hoge in range(2)] dp[0][0][0] = 1 mooooood3 = [i%3 for i in range(12)] u = 0 v = 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[v][0][s] = 0 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_ = mooooood3[mod3 + d] m3_ = has3 | (1 if d==3 else 0) s_ = (m1_<<3)|(m2_<<1)|m3_ dp[v][0][s_] += dp[u][0][s] if(dp[v][0][s_] >= mod): dp[v][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[v][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_ = mooooood3[mod3 + d] m3_ = has3 | (1 if d==3 else 0) s_ = (m1_<<3)|(m2_<<1)|m3_ j_ = (j*10 + d) % p dp[v][j_][s_] += dp[u][j][s] 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 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[u][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_ + k) % 3 modp_ = (modp_ * 10 + k) % p if (has3_!=0 or mod3_ == 0) and modp_ != 0 : ans += 1 ans %= mod print(ans)