結果

問題 No.1407 Kindness
ユーザー yagisumiyagisumi
提出日時 2021-04-02 01:30:10
言語 TypeScript
(5.4.3)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 3,320 bytes
コンパイル時間 8,169 ms
コンパイル使用メモリ 257,096 KB
実行使用メモリ 53,564 KB
最終ジャッジ日時 2023-08-23 08:25:28
合計ジャッジ時間 13,680 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
44,320 KB
testcase_01 AC 76 ms
42,496 KB
testcase_02 AC 76 ms
42,260 KB
testcase_03 AC 77 ms
42,256 KB
testcase_04 AC 76 ms
42,312 KB
testcase_05 AC 75 ms
42,276 KB
testcase_06 AC 74 ms
42,444 KB
testcase_07 AC 78 ms
42,428 KB
testcase_08 AC 77 ms
42,356 KB
testcase_09 AC 80 ms
42,268 KB
testcase_10 AC 82 ms
42,360 KB
testcase_11 AC 79 ms
42,260 KB
testcase_12 AC 105 ms
53,564 KB
testcase_13 AC 95 ms
48,104 KB
testcase_14 AC 95 ms
48,004 KB
testcase_15 AC 104 ms
51,152 KB
testcase_16 AC 97 ms
48,888 KB
testcase_17 AC 92 ms
48,072 KB
testcase_18 AC 94 ms
48,220 KB
testcase_19 AC 99 ms
50,508 KB
testcase_20 AC 98 ms
49,656 KB
testcase_21 AC 81 ms
43,616 KB
testcase_22 AC 87 ms
47,920 KB
testcase_23 AC 96 ms
48,584 KB
testcase_24 AC 104 ms
51,776 KB
testcase_25 AC 94 ms
48,112 KB
testcase_26 AC 97 ms
48,880 KB
testcase_27 AC 82 ms
43,836 KB
testcase_28 AC 99 ms
50,900 KB
testcase_29 AC 80 ms
43,024 KB
testcase_30 AC 105 ms
51,428 KB
testcase_31 AC 96 ms
48,080 KB
testcase_32 AC 142 ms
52,340 KB
testcase_33 AC 118 ms
49,068 KB
testcase_34 AC 130 ms
49,496 KB
testcase_35 AC 120 ms
49,072 KB
testcase_36 AC 85 ms
43,808 KB
testcase_37 AC 104 ms
51,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 Mods(M: number, MAX_N = 0) {
  function mul(...A: number[]) {
    return A.reduce((r, a) => {
      const t = r * a
      return t < 2 ** 53 ? t % M : ((((r >> 16) * a) % M) * 65536 + (r & 65535) * a) % M
    })
  }
  function pow(x: number, n: number) {
    let r = 1
    for (; n; x = mul(x, x), n >>= 1) {
      if (n & 1) r = mul(r, x)
    }
    return r
  }
  const fac: number[] = Array(MAX_N + 1)
  const fac_inv: number[] = Array(MAX_N + 1)
  fac[0] = 1
  fac_inv[0] = 1
  for (let i = 1; i <= MAX_N; i++) {
    fac[i] = mul(fac[i - 1], i)
    fac_inv[i] = mul(fac_inv[i - 1], pow(i, M - 2))
  }
  function nCr(n: number, r: number) {
    return mul(fac[n], fac_inv[r], fac_inv[n - r])
  }
  function nPr(n: number, r: number) {
    return mul(fac[n], fac_inv[n - r])
  }
  return { mul, pow, nCr, nPr }
}

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

  const M = 10 ** 9 + 7
  const mod = Mods(10 ** 9 + 7)
  const N = input.word()
  const pows = array(N.length + 1, 1)
  for (let i = 1; i <= N.length; i++) {
    pows[i] = mod.mul(pows[i - 1], 45)
  }
  const inv = mod.pow(44, M - 2)

  let sum = 0
  if (N.length > 1) {
    sum = mod.mul(pows[N.length] - 45, inv)
  }
  let tight_mul = 1
  for (let i = 0; i < N.length; i++) {
    const digit = Number(N[i])
    if (tight_mul && digit > 1) {
      sum += mod.mul(tight_mul, (digit * (digit - 1)) / 2, pows[N.length - i - 1])
      sum %= M
    }

    tight_mul = mod.mul(tight_mul, digit)
    if (digit === 0) break
  }

  const r = (sum + tight_mul) % M
  console.log(r < 0 ? r + M : r)
}

main()
0