結果

問題 No.220 世界のなんとか2
ユーザー yagisumiyagisumi
提出日時 2021-03-31 23:42:26
言語 TypeScript
(5.4.3)
結果
AC  
実行時間 77 ms / 1,000 ms
コード長 2,393 bytes
コンパイル時間 9,615 ms
コンパイル使用メモリ 258,012 KB
実行使用メモリ 42,560 KB
最終ジャッジ日時 2023-08-22 04:43:39
合計ジャッジ時間 12,449 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
42,300 KB
testcase_01 AC 70 ms
42,264 KB
testcase_02 AC 73 ms
42,416 KB
testcase_03 AC 75 ms
42,264 KB
testcase_04 AC 76 ms
42,560 KB
testcase_05 AC 76 ms
42,352 KB
testcase_06 AC 74 ms
42,304 KB
testcase_07 AC 72 ms
42,424 KB
testcase_08 AC 71 ms
42,396 KB
testcase_09 AC 74 ms
42,272 KB
testcase_10 AC 73 ms
42,276 KB
testcase_11 AC 70 ms
42,396 KB
testcase_12 AC 72 ms
42,472 KB
testcase_13 AC 75 ms
42,284 KB
testcase_14 AC 75 ms
42,332 KB
testcase_15 AC 77 ms
42,332 KB
testcase_16 AC 76 ms
42,444 KB
testcase_17 AC 76 ms
42,480 KB
testcase_18 AC 76 ms
42,476 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 main() {
  const input = new Input()

  const P = input.number()

  const HAVENT3 = 0
  const HAS3 = 1
  let dp = array2(3, 2, 0n)
  dp[0][HAVENT3] = 1n

  for (let i = 0; i < P; i++) {
    const dp2 = array2(3, 2, 0n)
    for (let mod3 = 0; mod3 < 3; mod3++) {
      for (let n3 = 0; n3 < 2; n3++) {
        for (let j = 0; j < 10; j++) {
          let curr_mod3 = (mod3 + j) % 3
          let curr_n3 = j === 3 ? HAS3 : n3
          dp2[curr_mod3][curr_n3] += dp[mod3][n3]
        }
      }
    }
    dp = dp2
  }

  const ans = dp[0][HAVENT3] + dp[0][HAS3] + dp[1][HAS3] + dp[2][HAS3]
  console.log((ans - 1n).toString())
}

main()
0