結果

問題 No.315 世界のなんとか3.5
ユーザー t8m8⛄️t8m8⛄️
提出日時 2017-06-22 23:52:16
言語 Nim
(2.0.0)
結果
TLE  
実行時間 -
コード長 1,556 bytes
コンパイル時間 3,624 ms
コンパイル使用メモリ 69,536 KB
実行使用メモリ 324,676 KB
最終ジャッジ日時 2023-09-12 13:10:17
合計ジャッジ時間 13,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 27 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 27 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 MLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 49) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 49) Warning: imported and not used: 'future' [UnusedImport]
/home/judge/data/code/Main.nim(1, 39) Warning: imported and not used: 'strscans' [UnusedImport]
/home/judge/data/code/Main.nim(1, 28) Warning: imported and not used: 'algorithm' [UnusedImport]

ソースコード

diff #

import strutils, sequtils, algorithm, strscans, future

{.warning[SmallLshouldNotBeUsed]: off.}

const MOD = 1000000007

proc minus1(a: var string): string =
  for i in countDown(a.len-1, 0):
    if a[i] != '0':
      a[i] = ((a[i].int - '0'.int) - 1 + '0'.int).char
      break
    else:
      a[i] = '9'
  while a.len > 1 and a[0] == '0':
    a = a[1..a.len-1]
  result = a

proc solve(a: string, dp: var seq[seq[seq[seq[seq[int]]]]], pp: int): int =
  dp[0][0][0][0][0] = 1

  for i in 0..<a.len:
    for j in 0..1:
      for k in 0..1:
        for l in 0..2:
          for m in 0..pp-1:
            for n in 0..9:
              if j == 0 and n > (a[i].int - '0'.int): break
              var
                p = if n < (a[i].int - '0'.int): 1 else: j
                q = if n == 3: 1 else: k
              dp[i+1][p][q][(n + l*10) mod 3][(n + m*10) mod pp] =
                  (dp[i+1][p][q][(n + l*10) mod 3][(n + m*10) mod pp] + dp[i][j][k][l][m]) mod MOD
  for j in 0..1:
    for k in 0..1:
      for l in 0..2:
        for m in 0..pp-1:
          if (k == 1 or l == 0) and m != 0:
            result = (result + dp[a.len][j][k][l][m]) mod MOD

when isMainModule:
  var
    input = stdin.readLine.split
    (a, b, p) = (input[0].minus1, input[1], input[2].parseint)
    dpA = newSeqWith(a.len+1, newSeqWith(2, newSeqWith(2, newSeqWith(3, newSeq[int](p)))))
    dpB = newSeqWith(b.len+1, newSeqWith(2, newSeqWith(2, newSeqWith(3, newSeq[int](p)))))

  var
    ansA = solve(a, dpA, p)
    ansB = solve(b, dpB, p)

  echo((ansB - ansA + MOD) mod MOD)

0