# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731046 | Boomyday | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
a, b = map(int, input().split())
dp = [[[0 for i in range(11)] for i in range(11)] for i in range(20)]
dp[0][10][10] = 1
for dig in range(1, 19):
for cur in range(10):
for prev in range(11):
if cur == prev:
continue
for prev2 in range(11):
if prev2 == cur:
continue
dp[dig][cur][prev] += dp[dig-1][prev][prev2]
## dig = 1
##d = 5
"""
ans = 1
for dig in range(1, d+1):
for cur in range(1, 11):
for prev in range(11):
ans += dp[dig][cur][prev]
"""
def solve(x):
if x == 0:
return 0
ans = 1
x = list(str(x))
for dig in range(1, len(x)):
for cur in range(1, 11):
for prev in range(11):
ans += dp[dig][cur][prev]
#print(ans)
chk = [11,11]
for i, ch in enumerate(x):
d = len(x) - i
#print(d, ch)
val = int(ch)
for cur in range(0, val):
if chk[-1] == 11 and cur == 0:
continue
if cur == chk[-1] or cur == chk[-2]:
continue
for prev in range(11):
if prev == chk[-1]: continue
ans += dp[d][cur][prev]
#print(ans)
chk[-2] = chk[-1]
chk[-1] = val
return ans
print(solve(b+1)-solve(a))
#print(ans, ans_brute)