답안 #643753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643753 2022-09-22T22:47:23 Z beaconmc Palindrome-Free Numbers (BOI13_numbers) PyPy 3
100 / 100
88 ms 21664 KB
def palin(x):
    x = str(x)
    for i in range(len(x)-1):
        if x[i] == x[i+1]: return True
    for i in range(len(x)-2):
        if x[i] == x[i+2]: return True
    return False

def dp(flag,prev,prev2,d):
    if d==cur:
        return 1
    if dps[flag][prev][prev2][d] != -1:
        return dps[flag][prev][prev2][d]
    
    ans = 0

    if flag:
        for i in range(sus[d+1]+1):
            if prev==10 and i==0: i = 10
            
            if i==prev and i!=10: continue
            if i==prev2 and i!=10: continue
            
            if i==sus[d+1]:
                ans += dp(1,i,prev,d+1)
            else:
                ans += dp(0,i,prev,d+1)
    else:
            
        for i in range(10):
            if prev==10 and i==0: i = 10
            if prev == i and i!=10: continue
            if i==prev2 and i!=10: continue
            
            ans += dp(0,i,prev,d+1)
    
    dps[flag][prev][prev2][d] = ans
    return ans


a,b = map(int, input().split())
sus = [-1]+[int(i) for i in str(a)]
cur = len(sus)-1
dps= [[[[-1 for i in range(19)]for i in range(11)]for i in range(11)]for i in range(2)]
aa = dp(1,10,10,0)


sus = [-1]+[int(i) for i in str(b)]
cur = len(sus)-1
dps= [[[[-1 for i in range(19)]for i in range(11)]for i in range(11)]for i in range(2)]
bb = dp(1,10,10,0)


if not palin(a):
    aa -= 1
print(bb-aa)

# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 18856 KB Output is correct
2 Correct 42 ms 18816 KB Output is correct
3 Correct 72 ms 20932 KB Output is correct
4 Correct 47 ms 19408 KB Output is correct
5 Correct 40 ms 19004 KB Output is correct
6 Correct 41 ms 18928 KB Output is correct
7 Correct 38 ms 18852 KB Output is correct
8 Correct 38 ms 18892 KB Output is correct
9 Correct 38 ms 18860 KB Output is correct
10 Correct 42 ms 18896 KB Output is correct
11 Correct 51 ms 19876 KB Output is correct
12 Correct 51 ms 19780 KB Output is correct
13 Correct 38 ms 18844 KB Output is correct
14 Correct 51 ms 19484 KB Output is correct
15 Correct 44 ms 19484 KB Output is correct
16 Correct 63 ms 20208 KB Output is correct
17 Correct 70 ms 20220 KB Output is correct
18 Correct 45 ms 18876 KB Output is correct
19 Correct 67 ms 20984 KB Output is correct
20 Correct 47 ms 19920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 20512 KB Output is correct
2 Correct 73 ms 20984 KB Output is correct
3 Correct 83 ms 21448 KB Output is correct
4 Correct 67 ms 20804 KB Output is correct
5 Correct 56 ms 20108 KB Output is correct
6 Correct 64 ms 20516 KB Output is correct
7 Correct 58 ms 20440 KB Output is correct
8 Correct 56 ms 20572 KB Output is correct
9 Correct 50 ms 20440 KB Output is correct
10 Correct 55 ms 20264 KB Output is correct
11 Correct 67 ms 20608 KB Output is correct
12 Correct 55 ms 20268 KB Output is correct
13 Correct 62 ms 20724 KB Output is correct
14 Correct 57 ms 20148 KB Output is correct
15 Correct 53 ms 20300 KB Output is correct
16 Correct 67 ms 21416 KB Output is correct
17 Correct 80 ms 21588 KB Output is correct
18 Correct 74 ms 21472 KB Output is correct
19 Correct 67 ms 21452 KB Output is correct
20 Correct 79 ms 21448 KB Output is correct
21 Correct 67 ms 21388 KB Output is correct
22 Correct 67 ms 20900 KB Output is correct
23 Correct 66 ms 20912 KB Output is correct
24 Correct 74 ms 21636 KB Output is correct
25 Correct 67 ms 21020 KB Output is correct
26 Correct 71 ms 21472 KB Output is correct
27 Correct 69 ms 21452 KB Output is correct
28 Correct 66 ms 21428 KB Output is correct
29 Correct 65 ms 21312 KB Output is correct
30 Correct 66 ms 21312 KB Output is correct
31 Correct 70 ms 21568 KB Output is correct
32 Correct 69 ms 21664 KB Output is correct
33 Correct 68 ms 20928 KB Output is correct
34 Correct 68 ms 21468 KB Output is correct
35 Correct 67 ms 20808 KB Output is correct
36 Correct 69 ms 21412 KB Output is correct
37 Correct 71 ms 21076 KB Output is correct
38 Correct 88 ms 20560 KB Output is correct
39 Correct 71 ms 20808 KB Output is correct
40 Correct 66 ms 21320 KB Output is correct
41 Correct 67 ms 21504 KB Output is correct
42 Correct 67 ms 21456 KB Output is correct
43 Correct 72 ms 21428 KB Output is correct
44 Correct 67 ms 20632 KB Output is correct
45 Correct 72 ms 21472 KB Output is correct