結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー yagisumiyagisumi
提出日時 2021-03-31 04:18:06
言語 TypeScript
(5.4.3)
結果
AC  
実行時間 168 ms / 3,000 ms
コード長 3,682 bytes
コンパイル時間 9,558 ms
コンパイル使用メモリ 258,844 KB
実行使用メモリ 50,012 KB
最終ジャッジ日時 2023-08-20 23:42:51
合計ジャッジ時間 15,175 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
42,424 KB
testcase_01 AC 80 ms
42,460 KB
testcase_02 AC 82 ms
42,364 KB
testcase_03 AC 80 ms
42,328 KB
testcase_04 AC 79 ms
42,216 KB
testcase_05 AC 79 ms
42,216 KB
testcase_06 AC 81 ms
42,512 KB
testcase_07 AC 79 ms
42,220 KB
testcase_08 AC 80 ms
42,208 KB
testcase_09 AC 80 ms
42,456 KB
testcase_10 AC 79 ms
42,216 KB
testcase_11 AC 79 ms
42,360 KB
testcase_12 AC 79 ms
42,204 KB
testcase_13 AC 79 ms
42,368 KB
testcase_14 AC 79 ms
42,468 KB
testcase_15 AC 81 ms
42,256 KB
testcase_16 AC 80 ms
42,408 KB
testcase_17 AC 83 ms
42,216 KB
testcase_18 AC 81 ms
42,360 KB
testcase_19 AC 81 ms
42,268 KB
testcase_20 AC 81 ms
42,244 KB
testcase_21 AC 81 ms
42,260 KB
testcase_22 AC 81 ms
42,260 KB
testcase_23 AC 81 ms
42,356 KB
testcase_24 AC 81 ms
42,496 KB
testcase_25 AC 82 ms
44,416 KB
testcase_26 AC 81 ms
42,420 KB
testcase_27 AC 82 ms
42,468 KB
testcase_28 AC 83 ms
42,232 KB
testcase_29 AC 81 ms
42,500 KB
testcase_30 AC 134 ms
47,272 KB
testcase_31 AC 126 ms
47,096 KB
testcase_32 AC 166 ms
50,012 KB
testcase_33 AC 143 ms
48,436 KB
testcase_34 AC 162 ms
48,240 KB
testcase_35 AC 168 ms
48,512 KB
testcase_36 AC 165 ms
48,436 KB
testcase_37 AC 166 ms
48,548 KB
testcase_38 AC 158 ms
48,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import { timeStamp } from 'console'
import * as fs from 'fs'

// import * as readline from 'readline'
// const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
// const ask = (query: string) => new Promise<string>((resolve) => rl.question(query, resolve))
// // Don't forget `rl.close()`.

const INT = Math.floor

declare global {
  interface Array<T> {
    last(): T | undefined
    isEmpty(): boolean
  }
}
Array.prototype.last = function () {
  return this.length === 0 ? undefined : this[this.length - 1]
}
Array.prototype.isEmpty = function () {
  return this.length === 0
}

const bigIntMax = (...args: bigint[]) => args.reduce((m, e) => (e > m ? e : m))
const bigIntMin = (...args: bigint[]) => args.reduce((m, e) => (e < m ? e : m))
const bigIntAbs = (arg: bigint) => (arg < 0 ? -arg : arg)

declare const stdin: number
function read_stdin() {
  return fs.readFileSync(process.env.NODE_ENV === 'debug' ? stdin : process.stdin.fd, 'utf8')
}
class Input {
  readonly inputs: string[]
  private index = 0
  constructor(str?: string) {
    this.inputs = (str ? str : read_stdin()).split(/\s+/)
  }
  number() {
    return Number(this.inputs[this.index++])
  }
  numbers(n: number) {
    return this.inputs.slice(this.index, (this.index += n)).map(Number)
  }
  bigint() {
    return BigInt(this.inputs[this.index++])
  }
  bigints(n: number) {
    return this.inputs.slice(this.index, (this.index += n)).map(BigInt)
  }
  word() {
    return this.inputs[this.index++]
  }
  words(n: number) {
    return this.inputs.slice(this.index, (this.index += n))
  }
}

function array<T>(len: number, init: T): T[] {
  return Array(len).fill(init)
}

function array2<T>(h: number, w: number, init: T): T[][] {
  return array(h, 0).map(() => array(w, init))
}

function main() {
  const input = new Input()

  const N = input.word()
  const M = 10 ** 9 + 7
  const B = 100

  const tight = 1
  let tight_state = {
    has0: false,
    count2: 0,
    count5: 0,
  }
  let dp = array2(3, 3, 0)

  for (let i = 0; i < N.length; i++) {
    const dp2 = array2(3, 3, 0)
    dp2[0][0] = 1
    if (!tight_state.has0) {
      const digit = Number(N[i])
      for (let j = 1; j < digit; j++) {
        let c2 = tight_state.count2
        let c5 = tight_state.count5
        if (j === 2 || j === 6) {
          c2 = Math.min(2, c2 + 1)
        } else if (j === 4 || j === 8) {
          c2 = Math.min(2, c2 + 2)
        } else if (j === 5) {
          c5 = Math.min(2, c5 + 1)
        }
        dp2[c2][c5] += tight
      }

      if (digit === 0) {
        tight_state.has0 = true
      } else if (digit === 2 || digit === 6) {
        tight_state.count2 = Math.min(2, tight_state.count2 + 1)
      } else if (digit === 4 || digit === 8) {
        tight_state.count2 = Math.min(2, tight_state.count2 + 2)
      } else if (digit === 5) {
        tight_state.count5 = Math.min(2, tight_state.count5 + 1)
      }
    }

    for (let c2 = 0; c2 < 3; c2++) {
      for (let c5 = 0; c5 < 3; c5++) {
        for (let j = 1; j < 10; j++) {
          let curr_c2 = c2
          let curr_c5 = c5
          if (j === 2 || j === 6) {
            curr_c2 = Math.min(2, c2 + 1)
          } else if (j === 4 || j === 8) {
            curr_c2 = Math.min(2, c2 + 2)
          } else if (j === 5) {
            curr_c5 = Math.min(2, c5 + 1)
          }
          dp2[curr_c2][curr_c5] = (dp2[curr_c2][curr_c5] + dp[c2][c5]) % M
        }
      }
    }

    // console.log(dp2)
    dp = dp2
  }

  // console.log(dp)

  let ans = 0
  if (!tight_state.has0 && tight_state.count2 === 2 && tight_state.count5 === 2) {
    ans++
  }
  ans = (ans + dp[2][2]) % M
  console.log(ans)
}

main()
0