Submission #70432177


Source Code Expand

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 n = next()
  const a = nexts(n)
  const freq = new Map()
  for (const num of a) {
    if (freq.has(num)) {
      freq.set(num, freq.get(num) + 1)
    }
    else {
      freq.set(num, 1)
    }
  }
  let res = 0n
  freq.forEach((value) => {
    if (value >= 2) {
      res += (BigInt(n) - BigInt(value)) * BigInt(value) * (BigInt(value) - 1n) / 2n
    }
  })
  return res.toString()
}
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 }

Submission Info

Submission Time
Task C - Odd One Subsequence
User xhksun
Language JavaScript (Node.js 18.16.1)
Score 300
Code Size 1859 Byte
Status AC
Exec Time 279 ms
Memory 86780 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 28
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 39 ms 42676 KiB
example_01.txt AC 39 ms 42692 KiB
hand_00.txt AC 279 ms 82336 KiB
hand_01.txt AC 88 ms 72544 KiB
hand_02.txt AC 91 ms 71588 KiB
hand_03.txt AC 39 ms 42788 KiB
hand_04.txt AC 39 ms 42712 KiB
hand_05.txt AC 89 ms 73252 KiB
random_00.txt AC 126 ms 86172 KiB
random_01.txt AC 126 ms 86684 KiB
random_02.txt AC 125 ms 86780 KiB
random_03.txt AC 127 ms 86376 KiB
random_04.txt AC 125 ms 86628 KiB
random_05.txt AC 105 ms 74560 KiB
random_06.txt AC 104 ms 74476 KiB
random_07.txt AC 104 ms 74588 KiB
random_08.txt AC 104 ms 74824 KiB
random_09.txt AC 104 ms 73148 KiB
random_10.txt AC 91 ms 69908 KiB
random_11.txt AC 91 ms 69992 KiB
random_12.txt AC 91 ms 70264 KiB
random_13.txt AC 92 ms 70036 KiB
random_14.txt AC 91 ms 70244 KiB
random_15.txt AC 70 ms 63504 KiB
random_16.txt AC 69 ms 63268 KiB
random_17.txt AC 69 ms 63368 KiB
random_18.txt AC 68 ms 63288 KiB
random_19.txt AC 68 ms 63352 KiB