AtCoder Beginner Contest 007

Submission #4240826

Source codeソースコード

def solve(s):
    #dp[keta][isBaned][isEqual]
    length = len(s)
    dp = [[[0] * 2 for _ in range(2)] for _ in range(length)]
    top = int(s[0])
    if top <= 3:
        dp[0][0][0] = top
        dp[0][0][1] = 1
    elif top == 4:
        dp[0][0][0] = 4
        dp[0][0][1] = 0
        dp[0][1][0] = 0
        dp[0][1][1] = 1
    elif top <= 8:
        dp[0][0][0] = top - 1
        dp[0][0][1] = 1
        dp[0][1][0] = 0
        dp[0][1][1] = 1
    elif top == 9:
        dp[0][0][0] = 8
        dp[0][0][1] = 0
        dp[0][1][0] = 1
        dp[0][1][1] = 1

    for i in range(1, length):
        num = int(s[i])
        if num <= 3:
            dp[i][0][0] = dp[i - 1][0][0] * 8 + dp[i - 1][0][1] * num
            dp[i][0][1] = dp[i - 1][0][1]
            dp[i][1][0] = dp[i - 1][0][0] * 2 + dp[i - 1][1][0] * 10 + dp[i - 1][1][1] * num
            dp[i][1][1] = dp[i - 1][1][1]
        elif num == 4:
            dp[i][0][0] = dp[i - 1][0][0] * 8 + dp[i - 1][0][1] * num
            dp[i][0][1] = 0
            dp[i][1][0] = dp[i - 1][0][0] * 2 + dp[i - 1][1][0] * 10 + dp[i - 1][1][1] * num
            dp[i][1][1] = 1
        elif num <= 8:
            dp[i][0][0] = dp[i - 1][0][0] * 8 + dp[i - 1][0][1] * (num - 1)
            dp[i][0][1] = dp[i - 1][0][1]
            dp[i][1][0] = dp[i - 1][0][0] * 2 + dp[i - 1][0][1] + dp[i - 1][1][0] * 10 + dp[i - 1][1][1] * num
            dp[i][1][1] = dp[i - 1][1][1]
        elif num == 9:
            dp[i][0][0] = dp[i - 1][0][0] * 8 + dp[i - 1][0][1] * (num - 1)
            dp[i][0][1] = 0
            dp[i][1][0] = dp[i - 1][0][0] * 2 + dp[i - 1][0][1] + dp[i - 1][1][0] * 10 + dp[i - 1][1][1] * num
            dp[i][1][1] = 1
    return dp[length - 1][1][0] + dp[length - 1][1][1]

a, b = input().split()
print(solve(b) - solve(str(int(a) - 1)))

Submission

Task問題 D - 禁止された数字
User nameユーザ名 orca
Created time投稿日時
Language言語 Python3 (3.4.3)
Status状態 WA
Score得点 0
Source lengthソースコード長 1860 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 AC 18 ms 3256 KB
subtask0_sample02.txt AC 18 ms 3320 KB
subtask0_sample03.txt AC 18 ms 3256 KB
subtask0_sample04.txt AC 18 ms 3320 KB
subtask1_01.txt AC 18 ms 3256 KB
subtask1_02.txt AC 18 ms 3256 KB
subtask1_03.txt AC 18 ms 3256 KB
subtask1_04.txt WA
subtask1_05.txt AC 18 ms 3256 KB
subtask1_06.txt WA
subtask1_07.txt AC 18 ms 3320 KB
subtask1_08.txt WA
subtask1_09.txt AC 18 ms 3320 KB
subtask1_10.txt WA
subtask1_11.txt WA
subtask1_12.txt WA
subtask1_13.txt WA
subtask2_01.txt AC 18 ms 3320 KB
subtask2_02.txt AC 18 ms 3256 KB
subtask2_03.txt WA
subtask2_04.txt WA
subtask2_05.txt WA
subtask2_06.txt WA
subtask2_07.txt AC 18 ms 3256 KB
subtask2_08.txt WA
subtask2_09.txt WA
subtask2_10.txt AC 18 ms 3256 KB
subtask2_11.txt WA
subtask2_12.txt WA
subtask2_13.txt AC 18 ms 3320 KB
subtask2_14.txt WA
subtask2_15.txt WA
subtask2_16.txt WA
subtask2_17.txt WA
subtask2_18.txt AC 18 ms 3256 KB
subtask2_19.txt WA
subtask2_20.txt AC 18 ms 3320 KB
subtask2_21.txt WA
subtask2_22.txt WA