結果
問題 | No.319 happy b1rthday 2 me |
ユーザー |
![]() |
提出日時 | 2023-02-02 16:12:48 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 2,331 bytes |
コンパイル時間 | 287 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 12,160 KB |
最終ジャッジ日時 | 2024-07-02 04:37:24 |
合計ジャッジ時間 | 2,459 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
import bisectimport copyimport decimalimport fractionsimport heapqimport itertoolsimport mathimport randomimport sysimport timefrom collections import Counter,deque,defaultdictfrom functools import lru_cache,reducefrom heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_maxdef _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], itemheapq._siftup_max(heap, 0)return itemfrom math import gcd as GCDread=sys.stdin.readreadline=sys.stdin.readlinereadlines=sys.stdin.readlineswrite=sys.stdout.writeA,B=map(int,readline().split())B+=1def solve(x):xx=xX=list(map(int,list(str(x))))dp=[0]*2dp_cnt=[0]*2for i in range(1,X[0]):if i==1:dp_cnt[1]+=1else:dp_cnt[0]+=1cnt=0if X[0]==1:cur=1else:cur=0for x in X[1:]:prev=dpprev_cnt=dp_cntdp=[0]*2dp_cnt=[0]*2for 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]+=1else:dp_cnt[0]+=1for i in range(x):if i==1:dp[1]+=cntdp_cnt[1]+=1elif i==2:dp[0]+=cntif cur:dp[0]+=1dp_cnt[0]+=1else:dp[0]+=cntdp_cnt[0]+=1if x==1:cur=1elif x==2 and cur:cnt+=1cur=0else:cur=0ans=0x=xxif x>=3:ans+=1x+=7x//=10le=len(str(x))for i in range(le-1):ans+=10**ians+=max(0,min(10**(le-1),x-2*10**(le-1)))return ans+dp[0]+dp[1]ans=solve(B)-solve(A)if int(str(A)[0])==2 and A%10==2:ans-=1print(ans)