結果
問題 | No.315 世界のなんとか3.5 |
ユーザー | koyumeishi |
提出日時 | 2015-12-01 00:41:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,198 bytes |
コンパイル時間 | 395 ms |
コンパイル使用メモリ | 81,852 KB |
実行使用メモリ | 80,196 KB |
最終ジャッジ日時 | 2024-09-14 05:34:34 |
合計ジャッジ時間 | 41,136 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
62,932 KB |
testcase_01 | AC | 120 ms
76,656 KB |
testcase_02 | AC | 186 ms
78,344 KB |
testcase_03 | AC | 71 ms
73,136 KB |
testcase_04 | AC | 71 ms
72,040 KB |
testcase_05 | AC | 124 ms
77,064 KB |
testcase_06 | AC | 186 ms
77,932 KB |
testcase_07 | AC | 122 ms
77,056 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 | - |
ソースコード
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)