結果
問題 |
No.315 世界のなんとか3.5
|
ユーザー |
![]() |
提出日時 | 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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 22 TLE * 6 |
ソースコード
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)