結果
問題 | No.2017 Mod7 Parade |
ユーザー |
👑 ![]() |
提出日時 | 2022-07-22 21:54:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 605 ms / 2,000 ms |
コード長 | 787 bytes |
コンパイル時間 | 148 ms |
コンパイル使用メモリ | 82,104 KB |
実行使用メモリ | 76,480 KB |
最終ジャッジ日時 | 2024-07-04 06:11:01 |
合計ジャッジ時間 | 8,416 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
""" 111111 mod 7か… 10^L 倍 + """ import sys from sys import stdin def DL_seven(D,L): #DDDDDDDDDDD ← L個をmod7で求める ret = [D % 7] while True: nex = (ret[-1] * 10 + D) % 7 if nex == ret[0]: break ret.append(nex) #print (ret) return ret[(L-1) % len(ret)] #print (DL_seven(1,4)) K = int(stdin.readline()) dp = [0] * 7 dp[0] = 1 mod = 10**9+7 for loop in range(K): D,L = map(int,stdin.readline().split()) ndp = [ i % mod for i in dp ] ndl = DL_seven(D,L) #追加する場合 for i in range(7): nex = (i * pow(10,L,7) + ndl) % 7 ndp[nex] += dp[i] dp = ndp dp[0] -= 1 ans = 0 for i in range(7): ans += dp[i] * i ans %= mod print (ans)