結果

問題 No.319 happy b1rthday 2 me
ユーザー roarisroaris
提出日時 2019-12-09 17:44:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,530 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 86,788 KB
実行使用メモリ 76,692 KB
最終ジャッジ日時 2023-09-05 04:50:40
合計ジャッジ時間 6,585 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,296 KB
testcase_01 AC 69 ms
71,480 KB
testcase_02 AC 78 ms
76,292 KB
testcase_03 AC 77 ms
76,448 KB
testcase_04 AC 72 ms
71,296 KB
testcase_05 AC 70 ms
71,228 KB
testcase_06 AC 70 ms
71,192 KB
testcase_07 AC 72 ms
71,320 KB
testcase_08 AC 72 ms
71,320 KB
testcase_09 AC 72 ms
71,384 KB
testcase_10 AC 73 ms
71,344 KB
testcase_11 AC 70 ms
71,480 KB
testcase_12 AC 70 ms
71,116 KB
testcase_13 AC 71 ms
71,124 KB
testcase_14 AC 71 ms
71,420 KB
testcase_15 AC 70 ms
71,084 KB
testcase_16 AC 71 ms
71,124 KB
testcase_17 AC 76 ms
75,320 KB
testcase_18 AC 77 ms
75,604 KB
testcase_19 AC 78 ms
75,644 KB
testcase_20 AC 88 ms
76,692 KB
testcase_21 AC 85 ms
76,184 KB
testcase_22 AC 78 ms
76,124 KB
testcase_23 AC 78 ms
75,340 KB
testcase_24 AC 78 ms
75,744 KB
testcase_25 AC 77 ms
76,116 KB
testcase_26 AC 81 ms
75,692 KB
testcase_27 AC 83 ms
76,412 KB
testcase_28 AC 82 ms
76,224 KB
testcase_29 AC 86 ms
76,564 KB
testcase_30 AC 82 ms
76,380 KB
testcase_31 AC 85 ms
76,560 KB
testcase_32 AC 83 ms
76,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def calc1(N):
    N = str(N)
    L = len(N)
    res = 0
    
    for l in range(L-1):
        dp = [[0]*2 for _ in range(L+1)]
        dp[0][0] = 1
        
        for i in range(L):
            Ni = int(N[i])
            
            for j in range(2):
                if i<l or i>l+1:
                    for d in range(10 if j else Ni+1):
                        dp[i+1][j|(d<Ni)] += dp[i][j]
                elif i==l and (1<=Ni or j==1):
                    dp[i+1][j|(1<Ni)] += dp[i][j]
                elif i==l+1 and (2<=Ni or j==1):
                    dp[i+1][j|(2<Ni)] += dp[i][j]
        
        res += dp[L][0]+dp[L][1]
    
    return res

def calc2(N):
    N = str(N)
    L = len(N)
    res = 0
    
    for l in range(L):
        dp = [[0]*2 for _ in range(L+1)]
        dp[0][0] = 1
        
        for i in range(L):
            Ni = int(N[i])
            
            for j in range(2):
                if i<l:
                    dp[i+1][j|(0<Ni)] += dp[i][j]
                elif i==l and (2<=Ni or j==1):
                    dp[i+1][j|(2<Ni)] += dp[i][j]
                elif l<i<L-1:
                    for d in range(10 if j else Ni+1):
                        dp[i+1][j|(d<Ni)] += dp[i][j]
                elif i==L-1 and (2<=Ni or j==1):
                    dp[i+1][j|(2<Ni)] += dp[i][j]
    
        res += dp[L][0]+dp[L][1]

    return res
    
A, B = map(int, input().split())
ans = calc1(B)-calc1(A-1)+calc2(B)-calc2(A-1)
strA = str(A)

if strA[0]=='2' and strA[-1]=='2':
    ans -= 1

print(ans)
0