結果

問題 No.319 happy b1rthday 2 me
ユーザー vwxyzvwxyz
提出日時 2023-02-02 16:10:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,286 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 10,780 KB
最終ジャッジ日時 2023-09-14 21:50:53
合計ジャッジ時間 2,501 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
10,476 KB
testcase_01 AC 35 ms
10,636 KB
testcase_02 AC 36 ms
10,628 KB
testcase_03 AC 34 ms
10,496 KB
testcase_04 AC 34 ms
10,584 KB
testcase_05 AC 34 ms
10,680 KB
testcase_06 AC 33 ms
10,460 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 34 ms
10,496 KB
testcase_10 AC 33 ms
10,504 KB
testcase_11 WA -
testcase_12 AC 34 ms
10,524 KB
testcase_13 AC 33 ms
10,504 KB
testcase_14 AC 33 ms
10,572 KB
testcase_15 AC 34 ms
10,468 KB
testcase_16 AC 34 ms
10,396 KB
testcase_17 WA -
testcase_18 AC 34 ms
10,632 KB
testcase_19 AC 33 ms
10,580 KB
testcase_20 AC 33 ms
10,624 KB
testcase_21 AC 34 ms
10,620 KB
testcase_22 AC 33 ms
10,536 KB
testcase_23 WA -
testcase_24 AC 33 ms
10,532 KB
testcase_25 AC 34 ms
10,496 KB
testcase_26 AC 33 ms
10,500 KB
testcase_27 WA -
testcase_28 AC 34 ms
10,572 KB
testcase_29 AC 34 ms
10,468 KB
testcase_30 AC 33 ms
10,496 KB
testcase_31 AC 34 ms
10,492 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write

A,B=map(int,readline().split())
B+=1
def solve(x):
    xx=x
    X=list(map(int,list(str(x))))
    dp=[0]*2
    dp_cnt=[0]*2
    for i in range(1,X[0]):
        if i==1:
            dp_cnt[1]+=1
        else:
            dp_cnt[0]+=1
    cnt=0
    if X[0]==1:
        cur=1
    else:
        cur=0
    for x in X[1:]:
        prev=dp
        prev_cnt=dp_cnt
        dp=[0]*2
        dp_cnt=[0]*2
        for i in range(10):
            if i==1:
                dp[1]+=prev[0]+prev[1]
                dp_cnt[1]+=prev_cnt[0]+prev_cnt[1]
            elif i==2:
                dp[0]+=prev[0]+prev[1]+prev_cnt[1]
                dp_cnt[0]+=prev_cnt[0]+prev_cnt[1]
            else:
                dp[0]+=prev[0]+prev[1]
                dp_cnt[0]+=prev_cnt[0]+prev_cnt[1]
        for i in range(1,10):
            if i==1:
                dp_cnt[1]+=1
            else:
                dp_cnt[0]+=1
        for i in range(x):
            if i==1:
                dp[1]+=cnt
                dp_cnt[1]+=1
            elif i==2:
                dp[0]+=cnt
                if cur:
                    dp[0]+=1
                dp_cnt[0]+=1
            else:
                dp[0]+=cnt
                dp_cnt[0]+=1
        if x==1:
            cur=1
        elif x==2 and cur:
            cnt+=1
            cur=0
        else:
            cur=0
    ans=0
    x=xx
    if x>=3:
        ans+=1
        x+=7
        x//=10
        le=len(str(x))
        for i in range(le-1):
            ans+=10**i
        ans+=max(0,min(10**(le-1),x-2*10**(le-1)))
    return ans+dp[0]+dp[1]
ans=solve(B)-solve(A)
print(ans)
0