Submission #2761619


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))

#------------------------------------------------------------------------------#
type Pos = tuple [ x, y: float ]

proc `+`(p1, p2: Pos): Pos = (p1.x + p2.x, p1.y + p2.y)
proc `-`(p1, p2: Pos): Pos = (p1.x - p2.x, p1.y - p2.y)
proc `*`(k: float, p: Pos): Pos = (k * p.x, k * p.y)
proc dot(p1, p2: Pos): float = p1.x * p2.x + p1.y * p2.y
proc det(p1, p2: Pos): float = p1.x * p2.y - p1.y * p2.x
proc abs(p: Pos): float = sqrt(p.x * p.x + p.y * p.y)
proc arg(p: Pos): float = arctan2(p.y, p.x)
#------------------------------------------------------------------------------#

proc intersection(p1, p2, q1, q2: Pos): Pos =
  let dp = p2 - p1
  let dq = q2 - q1
  let t: float = dq.det(q1 - p1) / dq.det(dp)
  return p1 + t * dp

proc eval(a, b, c: Pos; r: float): bool =
  let thA = ((b - a).arg() + (c - a).arg()) / 2.0
  let thB = ((c - b).arg() + (a - b).arg()) / 2.0
  let thC = ((a - c).arg() + (b - c).arg()) / 2.0
  let va: Pos = (cos(thA), sin(thA))
  let vb: Pos = (cos(thB), sin(thB))
  let vc: Pos = (cos(thC), sin(thC))

  let sinA = (b - a).det(va) / (b - a).abs()
  let aCenter = (r / abs(sinA)) * va + a

  let sinB = (a - b).det(vb) / (a - b).abs()
  let bCenter = (r / abs(sinB)) * vb + b

  let sinC = (a - c).det(vc) / (a - c).abs()
  let cCenter = (r / abs(sinC)) * vc + c

  if (aCenter - bCenter).abs() >= 2 * r:
    return true
  if (bCenter - cCenter).abs() >= 2 * r:
    return true
  if (cCenter - aCenter).abs() >= 2 * r:
    return true
  return false

proc main() =
  let (x1, y1) = readInt2()
  let (x2, y2) = readInt2()
  let (x3, y3) = readInt2()

  let a = (x1.float(), y1.float())
  let b = (x2.float(), y2.float())
  let c = (x3.float(), y3.float())

  let thA = ((b - a).arg() + (c - a).arg()) / 2.0
  let thB = ((c - b).arg() + (a - b).arg()) / 2.0
  let thC = ((a - c).arg() + (b - c).arg()) / 2.0
  let va: Pos = (cos(thA), sin(thA))
  let vb: Pos = (cos(thB), sin(thB))
  let vc: Pos = (cos(thC), sin(thC))

  let center = intersection(a, a + va, b, b + vb)
  let grand = intersection(a, b, center, center + (-(b - a).y, (b - a).x))

  # [lb, ub)
  var lb = 0.0
  var ub = (center - grand).abs()
  for i in 0..<1000 * 1000:
    let mid = (lb + ub) / 2.0
    if eval(a, b, c, mid):
      lb = mid
    else:
      ub = mid

  echo lb


main()

Submission Info

Submission Time
Task B - Inscribed Bicycle
User somq14
Language Nim (0.13.0)
Score 0
Code Size 3193 Byte
Status WA
Exec Time 654 ms
Memory 636 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]
Main.nim(90, 7) Hint: 'vc' is declared but not used [XDeclaredButNotUsed]
Main.nim(39, 6) Hint: 'Main.dot(p1: Pos, p2: Pos)' is declared but not used [XDeclaredButNotUsed]
Hint:  [Link]
Hint: operation successful (24896 lines compiled; 2.591 sec total; 25.256MB; Release Build) [SuccessX]

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 13
WA × 5
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 283 ms 636 KB
001.txt AC 398 ms 256 KB
002.txt AC 386 ms 256 KB
003.txt WA 354 ms 256 KB
004.txt AC 492 ms 256 KB
005.txt AC 380 ms 256 KB
006.txt WA 374 ms 256 KB
007.txt WA 372 ms 256 KB
008.txt AC 493 ms 256 KB
009.txt WA 392 ms 256 KB
010.txt AC 369 ms 256 KB
011.txt AC 385 ms 256 KB
012.txt WA 390 ms 256 KB
013.txt AC 398 ms 256 KB
014.txt AC 412 ms 256 KB
015.txt AC 394 ms 256 KB
example0.txt AC 654 ms 256 KB
example1.txt AC 362 ms 256 KB