Submission #66959029


Source Code Expand

function main(stdin) {
  const lines = stdin.trim().split('\n')
  const [n, q] = lines[0].split(' ').map(Number)
  const a = lines[1].split(' ').map(s => Number(s) - 1)
  // 0: white, 1: black
  const block = Array.from({ length: n }, () => 0)
  let ans = 0
  const res = []
  for (let i = 0; i < q; i++) {
    const idx = a[i]
    if (block[idx] === 0) {
      // w -> b
      if (idx === 0 && idx === n - 1) {
        ans++
      }
      else if (idx === 0 && block[idx + 1] === 0) {
        ans++
      }
      else if (idx === n - 1 && block[idx - 1] === 0) {
        ans++
      }
      else if (block[idx - 1] === 0 && block[idx + 1] === 0) {
        ans++
      }
      else if (block[idx - 1] === 1 && block[idx + 1] === 1) {
        ans--
      }
      block[idx] = 1
    }
    else {
      // b -> w
      if (idx === 0 && idx === n - 1) {
        ans--
      }
      else if (idx === 0 && block[idx + 1] === 0) {
        ans--
      }
      else if (idx === n - 1 && block[idx - 1] === 0) {
        ans--
      }
      else if (block[idx - 1] === 0 && block[idx + 1] === 0) {
        ans--
      }
      else if (block[idx - 1] === 1 && block[idx + 1] === 1) {
        ans++
      }
      block[idx] = 0
    }
    res.push(ans)
  }
  return res.join('\n')
}

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 - Black Intervals
User xhksun
Language JavaScript (Node.js 18.16.1)
Score 350
Code Size 1503 Byte
Status AC
Exec Time 254 ms
Memory 134888 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 29
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.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 45 ms 42664 KiB
example_01.txt AC 44 ms 42708 KiB
example_02.txt AC 45 ms 42720 KiB
hand_00.txt AC 218 ms 119884 KiB
hand_01.txt AC 204 ms 115688 KiB
hand_02.txt AC 238 ms 134888 KiB
hand_03.txt AC 137 ms 81824 KiB
hand_04.txt AC 44 ms 42784 KiB
hand_05.txt AC 135 ms 78552 KiB
random_00.txt AC 213 ms 119348 KiB
random_01.txt AC 202 ms 117572 KiB
random_02.txt AC 244 ms 122328 KiB
random_03.txt AC 201 ms 119924 KiB
random_04.txt AC 204 ms 119476 KiB
random_05.txt AC 201 ms 116068 KiB
random_06.txt AC 220 ms 121552 KiB
random_07.txt AC 203 ms 116752 KiB
random_08.txt AC 221 ms 123904 KiB
random_09.txt AC 218 ms 117092 KiB
random_10.txt AC 223 ms 119296 KiB
random_11.txt AC 206 ms 116860 KiB
random_12.txt AC 254 ms 123760 KiB
random_13.txt AC 218 ms 121700 KiB
random_14.txt AC 229 ms 121504 KiB
random_15.txt AC 211 ms 119944 KiB
random_16.txt AC 203 ms 115260 KiB
random_17.txt AC 252 ms 122628 KiB
random_18.txt AC 185 ms 106092 KiB
random_19.txt AC 228 ms 119000 KiB