답안 #731044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731044 2023-04-26T21:04:24 Z Boomyday Palindrome-Free Numbers (BOI13_numbers) PyPy 3
20 / 100
70 ms 19952 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):
    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)







# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 19496 KB Output is correct
2 Correct 52 ms 19472 KB Output is correct
3 Incorrect 53 ms 19740 KB Output isn't correct
4 Incorrect 52 ms 19472 KB Output isn't correct
5 Correct 49 ms 19480 KB Output is correct
6 Correct 53 ms 19364 KB Output is correct
7 Correct 56 ms 19392 KB Output is correct
8 Correct 51 ms 19472 KB Output is correct
9 Correct 47 ms 19376 KB Output is correct
10 Correct 49 ms 19496 KB Output is correct
11 Correct 50 ms 19412 KB Output is correct
12 Correct 49 ms 19400 KB Output is correct
13 Incorrect 57 ms 19388 KB Output isn't correct
14 Incorrect 53 ms 19496 KB Output isn't correct
15 Correct 50 ms 19512 KB Output is correct
16 Incorrect 50 ms 19616 KB Output isn't correct
17 Correct 49 ms 19624 KB Output is correct
18 Incorrect 46 ms 19484 KB Output isn't correct
19 Incorrect 51 ms 19804 KB Output isn't correct
20 Incorrect 50 ms 19452 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 19736 KB Output isn't correct
2 Incorrect 61 ms 19828 KB Output isn't correct
3 Incorrect 56 ms 19768 KB Output isn't correct
4 Incorrect 53 ms 19860 KB Output isn't correct
5 Correct 55 ms 19648 KB Output is correct
6 Incorrect 52 ms 19608 KB Output isn't correct
7 Incorrect 57 ms 19720 KB Output isn't correct
8 Incorrect 53 ms 19668 KB Output isn't correct
9 Incorrect 49 ms 19424 KB Output isn't correct
10 Correct 48 ms 19440 KB Output is correct
11 Incorrect 51 ms 19716 KB Output isn't correct
12 Incorrect 48 ms 19600 KB Output isn't correct
13 Incorrect 59 ms 19624 KB Output isn't correct
14 Correct 64 ms 19652 KB Output is correct
15 Incorrect 55 ms 19632 KB Output isn't correct
16 Incorrect 53 ms 19952 KB Output isn't correct
17 Incorrect 51 ms 19796 KB Output isn't correct
18 Incorrect 52 ms 19832 KB Output isn't correct
19 Incorrect 55 ms 19752 KB Output isn't correct
20 Incorrect 51 ms 19852 KB Output isn't correct
21 Incorrect 66 ms 19808 KB Output isn't correct
22 Incorrect 58 ms 19808 KB Output isn't correct
23 Incorrect 56 ms 19844 KB Output isn't correct
24 Incorrect 64 ms 19824 KB Output isn't correct
25 Incorrect 61 ms 19764 KB Output isn't correct
26 Incorrect 60 ms 19784 KB Output isn't correct
27 Incorrect 55 ms 19752 KB Output isn't correct
28 Incorrect 57 ms 19760 KB Output isn't correct
29 Incorrect 54 ms 19684 KB Output isn't correct
30 Incorrect 55 ms 19784 KB Output isn't correct
31 Incorrect 50 ms 19752 KB Output isn't correct
32 Incorrect 52 ms 19852 KB Output isn't correct
33 Incorrect 55 ms 19724 KB Output isn't correct
34 Incorrect 57 ms 19784 KB Output isn't correct
35 Incorrect 63 ms 19796 KB Output isn't correct
36 Incorrect 56 ms 19764 KB Output isn't correct
37 Incorrect 56 ms 19844 KB Output isn't correct
38 Incorrect 52 ms 19844 KB Output isn't correct
39 Incorrect 51 ms 19856 KB Output isn't correct
40 Incorrect 53 ms 19792 KB Output isn't correct
41 Incorrect 70 ms 19764 KB Output isn't correct
42 Incorrect 56 ms 19756 KB Output isn't correct
43 Incorrect 51 ms 19756 KB Output isn't correct
44 Incorrect 56 ms 19756 KB Output isn't correct
45 Incorrect 55 ms 19752 KB Output isn't correct