AtCoder Beginner Contest 007

Submission #4238860

Source codeソースコード

A,B = map(int,input().split())
itika = [0] * 20
answer = 0
for i in range(20):

    if i >= 1:
        
        itika[i] = (itika[i-1] * 8) + (2 * (10**(i-1)))

def nino(a,b):

    return (a % (10**b)) // (10**(b-1))





if len(str(A)) == len(str(B)):

    miku = 100

    for i in range(len(str(A))):

        if nino(A,i+1) != nino(B,i+1):

            miku = i

    if miku != 100:

        for i in range(miku):

            if i == 0:
        
                if '4' in str(A)[0:len(str(A))-1] or '9' in str(A)[0:len(str(A))-1]:

                    answer += 10-nino(A,1)

                else:

                    if nino(A,1) <= 4:

                        answer += 2

                    else:

                        answer += 1

            else:

                if '4' in str(A)[0:len(str(A))-i-1] or '9' in str(A)[0:len(str(A))-i-1]:

                    answer += (10**i)*(9-nino(A,i+1))

                else:

                    if nino(A,i+1) <= 3:

                        answer += (2*(10**i))+((7-nino(A,i+1))*itika[i])

                    elif nino(A,i+1) == 9:

                        answer += 0

                    else:

                        answer += (10**i)+((8-nino(A,i+1))*itika[i])
                    
        for i in range(miku+1):

            if i != miku:
        
                if i == 0:

                    if '4' in str(B)[0:len(str(B))-miku-1] or '9' in str(B)[0:len(str(B))-miku-1]:

                        answer += (nino(B,miku+1)-nino(A,miku+1)-1)*(10**(miku))

                    else:

                        if nino(B,miku+1) <= 4 or 4 <= nino(A,miku+1):

                            answer += (nino(B,miku+1)-nino(A,miku+1)-1)*itika[miku]

                        else:

                            answer += (nino(B,miku+1)-nino(A,miku+1)-2) * itika[miku] + (10**(miku))


                else:

                    if '4' in str(B)[0:len(str(B))-miku+i-1] or '9' in str(B)[0:len(str(B))-miku+i-1]:

                        answer += nino(B,miku+1-i) * (10**(miku-i))

                    else:

                        if nino(B,miku+1-i) <= 4:

                            answer += nino(B,miku+1-i) * itika[miku-i]

                        else:

                            answer += (nino(B,miku+1-i)-1) * itika[miku-i] + 10**(miku-i)

            else:

                if miku == 0:

                    if '4' in str(B)[0:len(str(B))-1] or '9' in str(B)[0:len(str(B))-1]:

                        answer += nino(B,1)-nino(A,1)+1

                    else:

                        for j in range(nino(B,1)-nino(A,1)+1):

                            if nino(A,1)+j == 4 or nino(A,1)+j == 9:

                                answer += 1

                else:

                    if '4' in str(B)[0:len(str(B))-1] or '9' in str(B)[0:len(str(B))-1]:

                        answer += nino(B,1)+1

                    else:

                        for j in range(nino(B,1)+1):

                            if j == 4 or j == 9:

                                answer += 1

            

    else:

        if '4' in str(B) or '9' in str(B):

            answer += 1

else:

    for i in range(len(str(B))-1):

        if i == 0:

            if '4' in str(A)[0:len(str(A))-1] or '9' in str(A)[0:len(str(A))-1]:

                answer += 10-nino(A,1)

            else:

                if i <= 4:

                    answer += 2

                else:

                    answer += 1

        elif i <= len(str(A))-1:

            if '4' in str(A)[0:len(str(A))-i-1] or '9' in str(A)[0:len(str(A))-i-1]:

                answer += (9-nino(A,i+1))*(10**i)

            else:

                if nino(A,i+1) <= 3:

                    answer += (2*(10**i))+(7-nino(A,i+1))*itika[i]

                elif nino(A,i+1) == 9:

                    answer += 0

                else:
                    
                    answer += (10**i)+(8-nino(A,i+1))*itika[i]

        else:

            answer += 7*itika[i]+2*(10**i)

    for i in range(len(str(B))):
        
        if i == 0:

            if nino(B,len(str(B))) <= 4:

                answer += (nino(B,len(str(B)))-1) * itika[len(str(B))-1]

            else:

                answer += (10**(len(str(B))-1)) + ((nino(B,len(str(B)))-2) * itika[len(str(B))-1])

        else:
            
            if '4' in str(B)[0:i] or '9' in str(B)[0:i]:

                answer += (10**(len(str(B))-i-1)) * nino(B,len(str(B))-i)

            else:

                if nino(B,len(str(B))-i) <= 4:

                    answer += nino(B,len(str(B))-i) * itika[len(str(B))-i-1]

                else:

                    answer += (10**(len(str(B))-i-1)) + ((nino(B,len(str(B))-i)-1) * itika[len(str(B))-i-1])

    if '4' in str(B) or '9' in str(B):

        answer += 1

if B <= 10000:

    answer = 0

    for i in range(B-A+1):

        if '4' in str(A+i) or '9' in str(A+i)

            answer += 1


print(answer)

        

        




    

        

                    




            




            
                        

Submission

Task問題 D - 禁止された数字
User nameユーザ名 asuka_kurasina
Created time投稿日時
Language言語 Python3 (3.4.3)
Status状態 RE
Score得点 0
Source lengthソースコード長 5315 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt,subtask0_sample04.txt
Subtask1 0 / 30 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt
Subtask2 0 / 70 subtask0_sample01.txt,subtask0_sample02.txt,subtask0_sample03.txt,subtask0_sample04.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask2_13.txt,subtask2_14.txt,subtask2_15.txt,subtask2_16.txt,subtask2_17.txt,subtask2_18.txt,subtask2_19.txt,subtask2_20.txt,subtask2_21.txt,subtask2_22.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
subtask0_sample01.txt RE
subtask0_sample02.txt RE
subtask0_sample03.txt RE
subtask0_sample04.txt RE
subtask1_01.txt RE
subtask1_02.txt RE
subtask1_03.txt RE
subtask1_04.txt RE
subtask1_05.txt RE
subtask1_06.txt RE
subtask1_07.txt RE
subtask1_08.txt RE
subtask1_09.txt RE
subtask1_10.txt RE
subtask1_11.txt RE
subtask1_12.txt RE
subtask1_13.txt RE
subtask2_01.txt RE
subtask2_02.txt RE
subtask2_03.txt RE
subtask2_04.txt RE
subtask2_05.txt RE
subtask2_06.txt RE
subtask2_07.txt RE
subtask2_08.txt RE
subtask2_09.txt RE
subtask2_10.txt RE
subtask2_11.txt RE
subtask2_12.txt RE
subtask2_13.txt RE
subtask2_14.txt RE
subtask2_15.txt RE
subtask2_16.txt RE
subtask2_17.txt RE
subtask2_18.txt RE
subtask2_19.txt RE
subtask2_20.txt RE
subtask2_21.txt RE
subtask2_22.txt RE