Submission #70802179


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 W = []
  const H = []
  const B = []
  for (let i = 0; i < n; i++) {
    const [w, h, b] = nexts(3)
    W.push(w)
    H.push(h)
    B.push(b)
  }
  const wSum = W.reduce((prev, curr) => prev + curr, 0)
  const offset = wSum
  // d = b - h, d >= 0
  // dp[i][d] = happy
  // const dp = Array.from({ length: n }, () => Array.from({ length: 2 * wSum + 1 }, () => -Infinity))
  let dp = new Map()
  // dp[i+1][d+w] = max()
  dp.set(offset + W[0], B[0])
  dp.set(offset - W[0], H[0])
  // dp[0][offset + W[0]] = B[0]
  // dp[0][offset - W[0]] = H[0]
  for (let i = 1; i < n; i++) {
    const next = new Map()
    const w = W[i]
    const h = H[i]
    const b = B[i]
    for (const [j, val] of dp.entries()) {
      // 放身体
      next.set(j + w, Math.max(next.get(j + w) ?? -Infinity, val + b))
      next.set(j - w, Math.max(next.get(j - w) ?? -Infinity, val + h))
    }
    dp = next
  }
  let res = -Infinity
  for (const [j, val] of dp.entries()) {
    if (j >= offset)
      res = Math.max(res, val)
  }
  return res
}
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 D - Robot Customize
User xhksun
Language JavaScript (Node.js 22.19.0)
Score 0
Code Size 2539 Byte
Status TLE
Exec Time > 2000 ms
Memory 132456 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 22
TLE × 32
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.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, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 22 ms 42076 KiB
00_sample_01.txt AC 23 ms 42024 KiB
00_sample_02.txt AC 22 ms 42184 KiB
00_sample_03.txt AC 127 ms 55256 KiB
01_random_03.txt TLE > 2000 ms 93480 KiB
01_random_04.txt TLE > 2000 ms 92224 KiB
01_random_05.txt TLE > 2000 ms 94600 KiB
01_random_06.txt TLE > 2000 ms 93236 KiB
01_random_07.txt TLE > 2000 ms 93416 KiB
01_random_08.txt TLE > 2000 ms 94732 KiB
01_random_09.txt TLE > 2000 ms 95028 KiB
01_random_10.txt TLE > 2000 ms 98152 KiB
01_random_11.txt TLE > 2000 ms 92456 KiB
01_random_12.txt TLE > 2000 ms 91952 KiB
01_random_13.txt AC 974 ms 119612 KiB
01_random_14.txt AC 803 ms 120136 KiB
01_random_15.txt AC 1751 ms 132456 KiB
01_random_16.txt AC 517 ms 121680 KiB
01_random_17.txt TLE > 2000 ms 92788 KiB
01_random_18.txt TLE > 2000 ms 94664 KiB
01_random_19.txt TLE > 2000 ms 95300 KiB
01_random_20.txt TLE > 2000 ms 96392 KiB
01_random_21.txt TLE > 2000 ms 93420 KiB
01_random_22.txt AC 831 ms 122180 KiB
01_random_23.txt AC 45 ms 55848 KiB
01_random_24.txt AC 22 ms 42356 KiB
01_random_25.txt TLE > 2000 ms 91236 KiB
01_random_26.txt TLE > 2000 ms 91308 KiB
01_random_27.txt TLE > 2000 ms 94700 KiB
01_random_28.txt TLE > 2000 ms 94104 KiB
01_random_29.txt TLE > 2000 ms 94120 KiB
01_random_30.txt TLE > 2000 ms 93904 KiB
01_random_31.txt TLE > 2000 ms 93300 KiB
01_random_32.txt AC 1846 ms 128536 KiB
01_random_33.txt AC 23 ms 42324 KiB
01_random_34.txt AC 22 ms 42332 KiB
01_random_35.txt TLE > 2000 ms 93836 KiB
01_random_36.txt TLE > 2000 ms 92112 KiB
01_random_37.txt TLE > 2000 ms 91312 KiB
01_random_38.txt TLE > 2000 ms 94772 KiB
01_random_39.txt TLE > 2000 ms 95728 KiB
01_random_40.txt TLE > 2000 ms 95632 KiB
01_random_41.txt TLE > 2000 ms 95036 KiB
01_random_42.txt TLE > 2000 ms 91260 KiB
01_random_43.txt AC 1948 ms 130188 KiB
01_random_44.txt TLE > 2000 ms 94080 KiB
01_random_45.txt TLE > 2000 ms 93012 KiB
01_random_46.txt AC 194 ms 105628 KiB
01_random_47.txt AC 1179 ms 120992 KiB
01_random_48.txt AC 40 ms 50564 KiB
01_random_49.txt AC 42 ms 50520 KiB
01_random_50.txt AC 42 ms 50684 KiB
01_random_51.txt AC 22 ms 43228 KiB
01_random_52.txt AC 33 ms 50588 KiB