AtCoder Beginner Contest 007

Submission #1770270

Source codeソースコード

# import sequtils, strutils, strscans, algorithm, math, future, sets, queues, tables # for yukicoder (0.17.1)
import sequtils, strutils, algorithm, math, future, sets, queues, tables # for AtCoder (0.13.0)
template getLine: string = stdin.readLine
template getInteger: int = getLine.parseInt
template getBiggestInteger: int64 = getLine.parseBiggestInt
template getIntSeq: seq[int] = getLine.split.map(parseInt)
template getBigIntSeq: seq[int64] = getLine.split.map(parseBiggestInt)

proc digitDP(N: string): int64 =
  let L = N.len
  var dp = newSeqWith(L + 1, newSeqWith(2, newSeqWith(2, 0.int64)))
  dp[0][0][0] = 1.int64
  for l in 0..<L:
    for flag in 0..1:
      for cond in 0..1:
        if cond == 1:
          for i in 0..<10:
            if i == 4 or i == 9:
              dp[l + 1][1][1] += dp[l][flag][1]
            else:
              dp[l + 1][flag][1] += dp[l][flag][1]
        else:
          for i in 0..<(N[l].ord - '0'.ord):
            if i == 4 or i == 9:
              dp[l + 1][1][1] += dp[l][flag][0]
            else:
              dp[l + 1][flag][1] += dp[l][flag][0]
          if (N[l].ord - '0'.ord) == 4 or (N[l].ord - '0'.ord) == 9:
            dp[l + 1][1][0] += dp[l][flag][0]
          else:
            dp[l + 1][flag][0] += dp[l][flag][0]
  return dp[L][1].sum


when isMainModule:
  let
    num = getLine.split
    (A, B) = (num[0], num[1])
  var ans = digitDP(B) - digitDP(A)
  if '4' in A or '9' in A:
    echo(ans + 1)
  else:
    echo(ans)

Submission

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

Compiler messageコンパイルメッセージ

Hint: system [Processing]
Hint: Main [Processing]
Hint: sequtils [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: algorithm [Processing]
Hint: math [Processing]
Hint: times [Processing]
Hint: future [Processing]
Hint: macros [Processing]
Hint: sets [Processing]
Hint: os [Processing]
Hint: posix [Processing]
Hint: hashes [Processing]
Hint: etcpriv [Processing]
Hint: queues [Processing]
Hint: tables [Processing]
Main.nim(13, 7) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
Main.nim(19, 18) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
Main.nim(19, 37) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
Main.nim(21, 18) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
Main.nim(21, 40) Warning: 'l' should not be used as an identifier; may look like '1' (one) [SmallLshouldNotBeUsed]
Main.nim...

Test case

Set

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