Submission #3415442


Source Code Expand

import strutils
import sequtils
import algorithm
import math
import queues
import tables
import sets
import logging
import future

const INF* = int(1e18 + 373)

proc readSeq*(): seq[string] = stdin.readLine().strip().split()
proc readSeq*(n: Natural): seq[string] =
  result = newSeq[string](n)
  for i in 0..<n:
    result[i] = stdin.readLine().strip()

proc readInt1*(): int = readSeq().map(parseInt)[0]
proc readInt2*(): (int, int) =
  let a = readSeq().map(parseInt)
  return (a[0], a[1])
proc readInt3*(): (int, int, int) =
  let a = readSeq().map(parseInt)
  return (a[0], a[1], a[2])
proc readInt4*(): (int, int, int, int) =
  let a = readSeq().map(parseInt)
  return (a[0], a[1], a[2], a[3])

type seq2*[T] = seq[seq[T]]
proc newSeq2*[T](n1, n2: Natural): seq2[T] = newSeqWith(n1, newSeq[T](n2))

#------------------------------------------------------------------------------#

proc placeDiamond(a: var seq2[char]; h, w, y, x, r: int; c: char) =
  for dy in (-r + 1)..(r - 1):
    for dx in (-r + 1)..(r - 1):
      let nextY = dy + y
      let nextX = dx + x
      if nextY in 0..<h and nextX in 0..<w and abs(dy) + abs(dx) < r:
        a[nextY][nextX] = c

proc main() =
  let (h, w, d) = readInt3()
  var a = newSeq2[char](h, w)
  for i in 0..<h:
    a[i].fill('.')

  if d mod 2 == 1:
    for i in 0..<h:
      a[i].fill('.')
    for i in 0..<h:
      for j in 0..<w:
        a[i][j] = (if (i + j) mod 2 == 0: 'R' else: 'B')
    for i in 0..<h:
      echo a[i].map(it => $it).join()
    return

  let r = d div 2

  let dy = @[ r, (r - 1), -r, -(r - 1) ]
  let dx = @[ -(r - 1), r, (r - 1), -r ]

  var q = initQueue[(int, int)]()
  q.enqueue((0, 0))
  placeDiamond(a, h, w, 0, 0, r, 'R')

  while q.len() > 0:
    let (y, x) = q.dequeue()
    for k in 0..<4:
      let nextY = y + dy[k]
      let nextX = x + dx[k]
      if nextY in 0..<h and nextX in 0..<w and a[nextY][nextX] == '.':
        q.enqueue((nextY, nextX))

      case a[y][x]:
      of 'R':
        if k mod 2 == 0:
          placeDiamond(a, h, w, nextY, nextX, r, 'B')
        else:
          placeDiamond(a, h, w, nextY, nextX, r, 'Y')
      of 'Y':
        if k mod 2 == 0:
          placeDiamond(a, h, w, nextY, nextX, r, 'G')
        else:
          placeDiamond(a, h, w, nextY, nextX, r, 'R')
      of 'G':
        if k mod 2 == 0:
          placeDiamond(a, h, w, nextY, nextX, r, 'Y')
        else:
          placeDiamond(a, h, w, nextY, nextX, r, 'B')
      of 'B':
        if k mod 2 == 0:
          placeDiamond(a, h, w, nextY, nextX, r, 'R')
        else:
          placeDiamond(a, h, w, nextY, nextX, r, 'G')
      else:
        discard

  for i in 0..<h:
    echo a[i].map(it => $it).join()


main()

Submission Info

Submission Time
Task D - Four Coloring
User somq14
Language Nim (0.13.0)
Score 0
Code Size 2797 Byte
Status WA
Exec Time 23 ms
Memory 4476 KB

Compile Error

Hint: system [Processing]
Hint: Main [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: sequtils [Processing]
Hint: algorithm [Processing]
Hint: math [Processing]
Hint: times [Processing]
Hint: queues [Processing]
Hint: tables [Processing]
Hint: hashes [Processing]
Hint: etcpriv [Processing]
Hint: sets [Processing]
Hint: os [Processing]
Hint: posix [Processing]
Hint: logging [Processing]
lib/pure/logging.nim(128, 22) Hint: 'Exception' is declared but not used [XDeclaredButNotUsed]
Hint: future [Processing]
Hint: macros [Processing]
Hint:  [Link]
Hint: operation successful (24892 lines compiled; 2.740 sec total; 25.261MB; Release Build) [SuccessX]

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 1
WA × 1
AC × 26
WA × 22
Set Name Test Cases
Sample 0_00.txt, 0_01.txt
All 0_00.txt, 0_01.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt WA 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt WA 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt WA 2 ms 256 KB
1_06.txt AC 2 ms 380 KB
1_07.txt WA 2 ms 380 KB
1_08.txt AC 2 ms 380 KB
1_09.txt WA 2 ms 380 KB
1_10.txt AC 14 ms 4476 KB
1_11.txt WA 23 ms 4476 KB
1_12.txt AC 14 ms 4476 KB
1_13.txt AC 21 ms 4476 KB
1_14.txt AC 11 ms 4476 KB
1_15.txt WA 21 ms 4476 KB
1_16.txt AC 11 ms 4476 KB
1_17.txt WA 18 ms 4476 KB
1_18.txt AC 12 ms 4476 KB
1_19.txt WA 14 ms 4476 KB
1_20.txt AC 13 ms 4476 KB
1_21.txt WA 15 ms 4476 KB
1_22.txt WA 10 ms 4348 KB
1_23.txt AC 11 ms 4476 KB
1_24.txt AC 10 ms 4476 KB
1_25.txt WA 14 ms 4476 KB
1_26.txt WA 13 ms 4476 KB
1_27.txt AC 12 ms 4476 KB
1_28.txt AC 14 ms 4476 KB
1_29.txt WA 14 ms 4476 KB
1_30.txt AC 10 ms 4476 KB
1_31.txt WA 15 ms 4476 KB
1_32.txt WA 16 ms 4476 KB
1_33.txt WA 12 ms 4476 KB
1_34.txt WA 14 ms 4476 KB
1_35.txt WA 19 ms 4476 KB
1_36.txt WA 17 ms 4476 KB
1_37.txt AC 14 ms 4476 KB
1_38.txt WA 16 ms 4476 KB
1_39.txt AC 14 ms 4476 KB
1_40.txt AC 12 ms 4476 KB
1_41.txt AC 14 ms 4476 KB
1_42.txt AC 11 ms 4476 KB
1_43.txt AC 14 ms 4476 KB
1_44.txt WA 16 ms 4476 KB
1_45.txt AC 11 ms 4476 KB