結果
問題 | No.1417 100の倍数かつ正整数(2) |
ユーザー | marroncastle |
提出日時 | 2021-03-05 23:58:30 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,742 bytes |
コンパイル時間 | 365 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 852,636 KB |
最終ジャッジ日時 | 2024-04-16 12:04:55 |
合計ジャッジ時間 | 8,309 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
53,888 KB |
testcase_01 | AC | 46 ms
54,364 KB |
testcase_02 | AC | 139 ms
78,108 KB |
testcase_03 | AC | 38 ms
53,120 KB |
testcase_04 | AC | 39 ms
53,760 KB |
testcase_05 | AC | 40 ms
53,248 KB |
testcase_06 | AC | 40 ms
53,632 KB |
testcase_07 | AC | 39 ms
53,632 KB |
testcase_08 | AC | 41 ms
53,760 KB |
testcase_09 | AC | 40 ms
54,144 KB |
testcase_10 | AC | 40 ms
53,760 KB |
testcase_11 | AC | 40 ms
54,016 KB |
testcase_12 | AC | 56 ms
66,560 KB |
testcase_13 | AC | 63 ms
68,352 KB |
testcase_14 | AC | 71 ms
73,344 KB |
testcase_15 | AC | 93 ms
76,664 KB |
testcase_16 | AC | 97 ms
76,800 KB |
testcase_17 | AC | 116 ms
77,048 KB |
testcase_18 | AC | 120 ms
77,416 KB |
testcase_19 | AC | 122 ms
77,300 KB |
testcase_20 | AC | 117 ms
77,364 KB |
testcase_21 | AC | 140 ms
78,212 KB |
testcase_22 | AC | 140 ms
78,428 KB |
testcase_23 | AC | 141 ms
78,248 KB |
testcase_24 | AC | 144 ms
78,096 KB |
testcase_25 | AC | 144 ms
78,168 KB |
testcase_26 | AC | 140 ms
78,132 KB |
testcase_27 | AC | 139 ms
78,184 KB |
testcase_28 | AC | 136 ms
78,056 KB |
testcase_29 | AC | 140 ms
78,096 KB |
testcase_30 | AC | 403 ms
91,944 KB |
testcase_31 | AC | 337 ms
89,364 KB |
testcase_32 | AC | 506 ms
132,864 KB |
testcase_33 | AC | 823 ms
319,400 KB |
testcase_34 | MLE | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
ソースコード
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)