結果

問題 No.602 隠されていたゲーム2
ユーザー locol23
提出日時 2021-12-01 10:57:12
言語 TypeScript
(5.7.2)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 8,789 ms
コンパイル使用メモリ 228,840 KB
実行使用メモリ 55,244 KB
最終ジャッジ日時 2024-12-31 16:41:45
合計ジャッジ時間 11,367 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import * as fs from 'fs'

const main = () => {
  const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')

  const [n] = input[0].split(' ').map((x: string): number => +x)
  const d = input[1].split(' ').map((x: string): number => +x)
  const [x, y] = input[2].split(' ').map((x: string) => +x)

  const targetDistance = Math.abs(x) + Math.abs(y)
  let incrementAcc = 0
  let decrementAcc = 0

  for (let i = 0, len = n; i < len; i++) {
    if (d[i] === targetDistance) {
      return console.log(1)
    }

    if (incrementAcc === targetDistance) {
      return console.log(2)
    }

    if (decrementAcc === targetDistance) {
      return console.log(2)
    }

    incrementAcc += d[i]
    decrementAcc -= d[i]
  }

  return console.log(-1)
}

main()
0