提出 #67362216


ソースコード 拡げる

function main(stdin) {
  // eslint-disable-next-line unused-imports/no-unused-vars, no-unused-vars
  const { next, nextstr, nextbig, nexts, nextssort, nextm, xArray } = makeInputReader(stdin)
  const t = next()
  const res = []
  function isS(nums) {
    // 1
    if (nums.every(num => num === nums[0])) {
      return true
    }
    // -1
    const pl = nums.filter(num => num === nums[0]).length
    const nl = nums.filter(num => num === -nums[0]).length
    const n = nums.length
    if (pl + nl === n && Math.min(pl, nl) === Math.floor(n / 2)) {
      return true
    }
    for (let i = 1; i < nums.length - 1; i++) {
      if (BigInt(nums[i]) * BigInt(nums[i]) !== BigInt(nums[i - 1]) * BigInt(nums[i + 1])) {
        return false
      }
    }
    return true
  }
  for (let tt = 0; tt < t; tt++) {
    const n = next()
    const nums = nexts(n)
    nums.sort((a, b) => Math.abs(a) - Math.abs(b))
    res.push(isS(nums) ? 'Yes' : 'No')
  }
  return res.join('\n')
}
function makeInputReader(input) {
  const cin = input.trim().split(/ |\n/)
  let cid = 0
  function createNDArray(shape, fillFn) {
    if (shape.length === 0)
      return fillFn()
    const [dim, ...rest] = shape
    return Array.from({ length: dim }, () => createNDArray(rest, fillFn))
  }
  return {
    next: () => Number(cin[cid++]),
    nextstr: () => cin[cid++],
    nextbig: () => BigInt(cin[cid++]),
    nexts: (n, addNum = 0, parse = true) =>
      parse ? cin.slice(cid, cid += n).map(s => Number(s) + addNum) : cin.slice(cid, cid += n),
    nextssort: (n, parse = true, desc = false) =>
      parse
        ? cin.slice(cid, cid += n).map(Number).sort((a, b) => desc ? b - a : a - b)
        : cin.slice(cid, cid += n).sort((a, b) => desc ? b.localeCompare(a) : a.localeCompare(b)),
    nextm: (h, w, parse = true) => {
      const res = []
      for (let i = 0; i < h; i++) {
        const row = cin.slice(cid, cid += w)
        res.push(parse ? row.map(Number) : row)
      }
      return res
    },
    xArray: createNDArray,
  }
}
if (require.main === module) {
  const fs = require('node:fs')
  const input = fs.readFileSync('/dev/stdin', 'utf8')
  console.log(main(input))
}
module.exports = { main }

提出情報

提出日時
問題 D - Make Geometric Sequence
ユーザ xhksun
言語 JavaScript (Node.js 18.16.1)
得点 425
コード長 2258 Byte
結果 AC
実行時間 178 ms
メモリ 82072 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 1
AC × 32
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 02_handmade_31.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 39 ms 42776 KiB
01_random_01.txt AC 124 ms 63092 KiB
01_random_02.txt AC 178 ms 79836 KiB
01_random_03.txt AC 158 ms 78064 KiB
01_random_04.txt AC 149 ms 79644 KiB
01_random_05.txt AC 161 ms 81484 KiB
01_random_06.txt AC 81 ms 58668 KiB
01_random_07.txt AC 93 ms 73776 KiB
01_random_08.txt AC 147 ms 78696 KiB
01_random_09.txt AC 148 ms 81728 KiB
01_random_10.txt AC 117 ms 71988 KiB
01_random_11.txt AC 175 ms 81040 KiB
01_random_12.txt AC 147 ms 78636 KiB
01_random_13.txt AC 148 ms 79748 KiB
01_random_14.txt AC 147 ms 79200 KiB
01_random_15.txt AC 167 ms 78436 KiB
01_random_16.txt AC 147 ms 78688 KiB
01_random_17.txt AC 148 ms 81724 KiB
01_random_18.txt AC 131 ms 74788 KiB
01_random_19.txt AC 104 ms 79528 KiB
01_random_20.txt AC 107 ms 62684 KiB
01_random_21.txt AC 176 ms 81648 KiB
01_random_22.txt AC 149 ms 80024 KiB
01_random_23.txt AC 120 ms 73140 KiB
01_random_24.txt AC 162 ms 76072 KiB
01_random_25.txt AC 148 ms 82072 KiB
01_random_26.txt AC 149 ms 81820 KiB
01_random_27.txt AC 143 ms 79224 KiB
01_random_28.txt AC 177 ms 81436 KiB
01_random_29.txt AC 147 ms 81536 KiB
01_random_30.txt AC 116 ms 65012 KiB
02_handmade_31.txt AC 39 ms 42824 KiB