結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー marroncastlemarroncastle
提出日時 2021-03-05 23:58:30
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,742 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 852,000 KB
最終ジャッジ日時 2024-10-07 06:12:56
合計ジャッジ時間 8,829 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,760 KB
testcase_01 AC 41 ms
54,668 KB
testcase_02 AC 140 ms
78,108 KB
testcase_03 AC 39 ms
52,864 KB
testcase_04 AC 39 ms
53,120 KB
testcase_05 AC 39 ms
53,120 KB
testcase_06 AC 40 ms
53,376 KB
testcase_07 AC 40 ms
54,016 KB
testcase_08 AC 40 ms
53,376 KB
testcase_09 AC 39 ms
53,376 KB
testcase_10 AC 41 ms
53,760 KB
testcase_11 AC 40 ms
54,016 KB
testcase_12 AC 58 ms
66,304 KB
testcase_13 AC 62 ms
68,480 KB
testcase_14 AC 73 ms
73,216 KB
testcase_15 AC 94 ms
76,528 KB
testcase_16 AC 96 ms
76,552 KB
testcase_17 AC 103 ms
76,868 KB
testcase_18 AC 116 ms
77,240 KB
testcase_19 AC 120 ms
77,444 KB
testcase_20 AC 123 ms
77,144 KB
testcase_21 AC 140 ms
78,164 KB
testcase_22 AC 140 ms
78,380 KB
testcase_23 AC 140 ms
78,172 KB
testcase_24 AC 141 ms
78,040 KB
testcase_25 AC 146 ms
78,108 KB
testcase_26 AC 143 ms
78,052 KB
testcase_27 AC 145 ms
78,180 KB
testcase_28 AC 141 ms
78,052 KB
testcase_29 AC 143 ms
77,988 KB
testcase_30 AC 397 ms
91,908 KB
testcase_31 AC 335 ms
89,280 KB
testcase_32 AC 489 ms
132,604 KB
testcase_33 AC 799 ms
319,276 KB
testcase_34 MLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9+7

class ModInt:
  def __init__(self, x):
    self.x = x % MOD

  def __str__(self):
    return str(self.x)

  __repr__ = __str__

  def __add__(self, other):
    return (
      ModInt(self.x + other.x) if isinstance(other, ModInt) else
      ModInt(self.x + other)
    )

  def __sub__(self, other):
    return (
      ModInt(self.x - other.x) if isinstance(other, ModInt) else
      ModInt(self.x - other)
    )

  def __mul__(self, other):
    return (
      ModInt(self.x * other.x) if isinstance(other, ModInt) else
      ModInt(self.x * other)
    )

  def __truediv__(self, other):
    return (
      ModInt(
        self.x * pow(other.x, MOD - 2, MOD)
      ) if isinstance(other, ModInt) else
      ModInt(self.x * pow(other, MOD - 2, MOD))
    )

  __floordiv__ = __truediv__

  def __pow__(self, other):
    return (
      ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
      ModInt(pow(self.x, other, MOD))
    )

  __radd__ = __add__

  def __rsub__(self, other):
    return (
      ModInt(other.x - self.x) if isinstance(other, ModInt) else
      ModInt(other - self.x)
    )

  __rmul__ = __mul__

  def __rtruediv__(self, other):
    return (
      ModInt(
        other.x * pow(self.x, MOD - 2, MOD)
      ) if isinstance(other, ModInt) else
      ModInt(other * pow(self.x, MOD - 2, MOD))
    )

  def __rpow__(self, other):
    return (
      ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
      ModInt(pow(other, self.x, MOD))
    )

N = list(map(int,list(input())))[::-1]
digit = len(N)
dp = [[[[0]*10 for _ in range(3)] for _ in range(3)] for _ in N+[0]]
dp[0][0][0] = [1]*10
for i in range(digit): #配るDP
  for j in range(3): #2
    for k in range(3): #5
      for l in range(1,10):
        dp[i+1][j][k][l] += dp[i+1][j][k][l-1]
        dp[i+1][j][k][l] += dp[i][j][k][-1]*(int(l%2==1)-int(l%5==0))
        dp[i+1][min(2,j+1)][k][l] += dp[i][j][k][-1]*(int(l%2==0)-int(l%4==0))
        dp[i+1][min(2,j+2)][k][l] += dp[i][j][k][-1]*int(l%4==0)
        dp[i+1][j][min(2,k+1)][l] += dp[i][j][k][-1]*int(l%5==0)
dp1 = [[[0]*3 for _ in range(3)] for _ in N+[0]]
ans = ModInt(0)
for i in range(digit-1):
  ans += dp[i+1][-1][-1][-1]
for i in range(digit):
  if N[i-1]>0 and N[i]>0:
    for j in range(3): #2
      for k in range(3): #5
        dp1[i+1][j][k] += (dp[i][j][k][N[i-1]-1]+dp1[i][j][k])*(int(N[i]%2==1)-int(N[i]%5==0))
        dp1[i+1][min(2,j+1)][k] += (dp[i][j][k][N[i-1]-1]+dp1[i][j][k])*(int(N[i]%2==0)-int(N[i]%4==0))
        dp1[i+1][min(2,j+2)][k] += (dp[i][j][k][N[i-1]-1]+dp1[i][j][k])*int(N[i]%4==0)
        dp1[i+1][j][min(2,k+1)] += (dp[i][j][k][N[i-1]-1]+dp1[i][j][k])*int(N[i]%5==0)
ans += dp1[-1][-1][-1]+dp[-1][-1][-1][N[-1]-1]
print(ans)
0