結果

問題 No.260 世界のなんとか3
ユーザー vwxyzvwxyz
提出日時 2023-02-02 02:54:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,592 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 11,268 KB
実行使用メモリ 11,108 KB
最終ジャッジ日時 2023-09-14 12:08:53
合計ジャッジ時間 16,107 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
10,560 KB
testcase_01 AC 34 ms
10,588 KB
testcase_02 AC 36 ms
10,620 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 219 ms
10,824 KB
testcase_27 AC 34 ms
10,504 KB
testcase_28 AC 403 ms
10,896 KB
testcase_29 TLE -
権限があれば一括ダウンロードができます

ソースコード

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=readline().split()
A=list(map(int,list(A)))
B=list(map(int,list(B)))
mod=10**9+7
def solve(N):
    if len(N)<=5:
        ans=0
        N=int("".join(map(str,N)))
        for n in range(1,N):
            if (n%3==0 or "3" in str(n)) and n%8:
                ans+=1
        return ans
    dp0=[0]*3
    dp1=[0]*3
    for i in range(1,N[0]):
        if i==3:
            dp1[i%3]+=1
        else:
            dp0[i%3]+=1
    s=N[0]
    bl=(N[0]==3)
    for n in N[1:-3]:
        prev0=dp0
        prev1=dp1
        dp0=[0]*3
        dp1=[0]*3
        for p in range(3):
            for i in range(10):
                if i==3:
                    dp1[(p*10+i)%3]+=prev0[p]
                    dp1[(p*10+i)%3]+=prev1[p]
                    dp1[(p*10+i)%3]%=mod
                else:
                    dp0[(p*10+i)%3]+=prev0[p]
                    dp0[(p*10+i)%3]%=mod
                    dp1[(p*10+i)%3]+=prev1[p]
                    dp1[(p*10+i)%3]%=mod
        for i in range(n):
            if bl|(i==3):
                dp1[(s*10+i)%3]+=1
            else:
                dp0[(s*10+i)%3]+=1
        for i in range(1,10):
            if i==3:
                dp1[i%3]+=1
            else:
                dp0[i%3]+=1
        s=s*10+n
        bl|=n==3
    X=N[-3]*100+N[-2]*10+N[-1]
    ans=0
    for i in range(3):
        for x in range(1000):
            if x%8==0:
                continue
            if (i+x)%3==0 or "3" in str(x):
                ans+=dp0[i]
            ans+=dp1[i]
    for x in range(1,1000):
        if x%8==0:
            continue
        if x%3==0 or "3" in str(x):
            ans+=1
    for x in range(1,X):
        if x%8==0:
            continue
        if (s+x)%3==0 or "3" in str(x) or bl:
            ans+=1
    return ans%mod
ans=(solve(B)-solve(A))%mod
B=[0]*2+B
if 3 in B and sum(B)%3==0 and (B[-3]*100+B[-2]*10+B[-1])%8==0:
    ans+=1
    ans%=mod
print(ans)
0