Submission #731046

# Submission time Handle Problem Language Result Execution time Memory
731046 2023-04-26T21:06:14 Z Boomyday Palindrome-Free Numbers (BOI13_numbers) C++14
Compilation error
0 ms 0 KB
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)







Compilation message

numbers.cpp:25:1: error: stray '##' in program
   25 | ## dig = 1
      | ^~
numbers.cpp:28:1: error: stray '##' in program
   28 | ##d = 5
      | ^~
numbers.cpp:31:3: warning: missing terminating " character
   31 | """
      |   ^
numbers.cpp:31:3: error: missing terminating " character
numbers.cpp:38:3: warning: missing terminating " character
   38 | """
      |   ^
numbers.cpp:38:3: error: missing terminating " character
numbers.cpp:53:6: error: invalid preprocessing directive #print
   53 |     #print(ans)
      |      ^~~~~
numbers.cpp:59:10: error: invalid preprocessing directive #print
   59 |         #print(d, ch)
      |          ^~~~~
numbers.cpp:70:10: error: invalid preprocessing directive #print
   70 |         #print(ans)
      |          ^~~~~
numbers.cpp:81:2: error: invalid preprocessing directive #print
   81 | #print(ans, ans_brute)
      |  ^~~~~
numbers.cpp:2:1: error: 'a' does not name a type
    2 | a, b = map(int, input().split())
      | ^