Submission #7316846
Source Code Expand
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
(sb-int:defconstant-eqx OPT
#+swank '(optimize (speed 3) (safety 2))
#-swank '(optimize (speed 3) (safety 0) (debug 0))
#'equal)
#+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
#-swank (set-dispatch-macro-character
#\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy
;; BEGIN_INSERTED_CONTENTS
;;;
;;; ARRAY-ELEMENT-TYPE is not constant-folded on SBCL version earlier than
;;; 1.5.0. See
;;; https://github.com/sbcl/sbcl/commit/9f0d12e7ab961828931d01c0b2a76a5885ad35d2
;;;
(eval-when (:compile-toplevel :load-toplevel :execute)
(sb-c:deftransform array-element-type ((array))
(let ((type (sb-c::lvar-type array)))
(flet ((element-type (type)
(and (sb-c::array-type-p type)
(sb-int:neq (sb-kernel::array-type-specialized-element-type type) sb-kernel:*wild-type*)
(sb-kernel:type-specifier (sb-kernel::array-type-specialized-element-type type)))))
(cond ((let ((type (element-type type)))
(and type
`',type)))
((sb-kernel:union-type-p type)
(let (result)
(loop for type in (sb-kernel:union-type-types type)
for et = (element-type type)
unless (and et
(if result
(equal result et)
(setf result et)))
do (sb-c::give-up-ir1-transform))
`',result))
((sb-kernel:intersection-type-p type)
(loop for type in (sb-kernel:intersection-type-types type)
for et = (element-type type)
when et
return `',et
finally (sb-c::give-up-ir1-transform)))
(t
(sb-c::give-up-ir1-transform)))))))
;;;
;;; 2D convex hull of points (Monotone Chain Algorithm)
;;; Complexity: O(nlog(n))
;;;
(declaim (inline make-convex-hull!))
(defun make-convex-hull! (points &optional (eps 0))
"Returns the vector of the vertices of the convex hull, which are sorted in
the anticlockwise direction around the perimeter. This function sorts POINTS as
a side effect.
If EPS is non-negative, three vertices in a straight line are excluded (when the
calculation error is within EPS, of course); they are allowed if EPS is
negative.
POINTS := vector of complex number"
(declare (inline sort)
(vector points))
;; FIXME: the returned vector may contain duplicate vertices in a degenerative
;; case: E.g. (make-convex-hull! #(#c(1 2) #c(1 2) #c(1 2) #c(1 2)) ) |->
;; #(#C(1 2) #C(1 2))
(macrolet ((outer (p1 p2) ; outer product
`(let ((c1 ,p1)
(c2 ,p2))
(- (* (realpart c1) (imagpart c2))
(* (imagpart c1) (realpart c2))))))
(when (<= (length points) 1)
(return-from make-convex-hull! (copy-seq points)))
(let* ((n (length points))
(end 0)
(res (make-array (* n 2) :element-type (array-element-type points)))
(points (sort points (lambda (p1 p2)
(if (= (realpart p1) (realpart p2))
(< (imagpart p1) (imagpart p2))
(< (realpart p1) (realpart p2)))))))
(declare (fixnum end))
(do ((i 0 (+ i 1)))
((= i n))
(loop (if (and (> end 1)
(<= (outer (- (aref res (- end 1)) (aref res (- end 2)))
(- (aref points i) (aref res (- end 1))))
eps))
(decf end)
(return)))
(setf (aref res end) (aref points i))
(incf end))
(let ((tmp-end end))
(do ((i (- n 2) (- i 1)))
((< i 0))
(loop (if (and (> end tmp-end)
(<= (outer (- (aref res (- end 1)) (aref res (- end 2)))
(- (aref points i) (aref res (- end 1))))
eps))
(decf end)
(return)))
(setf (aref res end) (aref points i))
(incf end)))
(adjust-array res (- end 1)))))
(defmacro dbg (&rest forms)
#+swank
(if (= (length forms) 1)
`(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
`(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
#-swank (declare (ignore forms)))
(defmacro define-int-types (&rest bits)
`(progn
,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)
(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
(let ((*read-default-float-format* 'double-float))
(prog1 (princ obj stream) (terpri stream))))
(defconstant +mod+ 1000000007)
;;;
;;; Body
;;;
(defconstant +eps+ 1d-9)
(defun main ()
(let* ((n (read))
(vecs (make-array n :element-type '(complex double-float)))
(dp (make-array 1 :element-type '(complex double-float) :initial-element #c(0d0 0d0))))
(dotimes (i n)
(let* ((x (float (read) 1d0))
(y (float (read) 1d0)))
(setf (aref vecs i) (complex x y))))
(dotimes (i n)
(let* ((v (aref vecs i))
(len (length dp))
(translation (adjust-array dp (* 2 len))))
(declare ((simple-array (complex double-float) (*)) translation)
(uint32 len))
(dotimes (i len)
(setf (aref translation (+ i len))
(+ (aref translation i) v)))
(setq dp (make-convex-hull! translation +eps+))))
(println (reduce #'max dp :key #'abs))))
#-swank (main)
Submission Info
| Submission Time | |
|---|---|
| Task | F - Engines |
| User | sansaqua |
| Language | Common Lisp (SBCL 1.1.14) |
| Score | 600 |
| Code Size | 6299 Byte |
| Status | AC |
| Exec Time | 396 ms |
| Memory | 55648 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 00-sample-04.txt, 00-sample-05.txt, 00-sample-06.txt, 00-sample-07.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 00-sample-04.txt, 00-sample-05.txt, 00-sample-06.txt, 00-sample-07.txt, 01-random-very-small-01.txt, 01-random-very-small-02.txt, 01-random-very-small-03.txt, 02-random-small-01.txt, 02-random-small-02.txt, 02-random-small-03.txt, 03-random-01.txt, 03-random-02.txt, 03-random-03.txt, 04-zero-01.txt, 05-same-01.txt, 05-same-02.txt, 06-linear-01.txt, 06-linear-02.txt, 06-linear-03.txt, 07-linear-positive-01.txt, 07-linear-positive-02.txt, 07-linear-positive-03.txt, 08-90-degree-01.txt, 08-90-degree-02.txt, 09-180-degree-01.txt, 09-180-degree-02.txt, 10-sandglass-01.txt, 10-sandglass-02.txt, 11-circle-01.txt, 11-circle-02.txt, 11-circle-03.txt, 11-circle-04.txt, 11-circle-05.txt, 12-square-01.txt, 12-square-02.txt, 12-square-03.txt, 13-corner-01.txt, 13-corner-02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-01.txt | AC | 396 ms | 55648 KiB |
| 00-sample-02.txt | AC | 213 ms | 43620 KiB |
| 00-sample-03.txt | AC | 213 ms | 43620 KiB |
| 00-sample-04.txt | AC | 212 ms | 43624 KiB |
| 00-sample-05.txt | AC | 213 ms | 43620 KiB |
| 00-sample-06.txt | AC | 213 ms | 43620 KiB |
| 00-sample-07.txt | AC | 213 ms | 43620 KiB |
| 01-random-very-small-01.txt | AC | 213 ms | 43620 KiB |
| 01-random-very-small-02.txt | AC | 213 ms | 43620 KiB |
| 01-random-very-small-03.txt | AC | 214 ms | 43620 KiB |
| 02-random-small-01.txt | AC | 213 ms | 43616 KiB |
| 02-random-small-02.txt | AC | 218 ms | 43620 KiB |
| 02-random-small-03.txt | AC | 218 ms | 43616 KiB |
| 03-random-01.txt | AC | 213 ms | 43620 KiB |
| 03-random-02.txt | AC | 219 ms | 43620 KiB |
| 03-random-03.txt | AC | 219 ms | 43620 KiB |
| 04-zero-01.txt | AC | 213 ms | 43620 KiB |
| 05-same-01.txt | AC | 213 ms | 43620 KiB |
| 05-same-02.txt | AC | 213 ms | 43616 KiB |
| 06-linear-01.txt | AC | 214 ms | 43616 KiB |
| 06-linear-02.txt | AC | 213 ms | 43620 KiB |
| 06-linear-03.txt | AC | 214 ms | 43624 KiB |
| 07-linear-positive-01.txt | AC | 213 ms | 43616 KiB |
| 07-linear-positive-02.txt | AC | 213 ms | 43616 KiB |
| 07-linear-positive-03.txt | AC | 215 ms | 43620 KiB |
| 08-90-degree-01.txt | AC | 217 ms | 43620 KiB |
| 08-90-degree-02.txt | AC | 220 ms | 43616 KiB |
| 09-180-degree-01.txt | AC | 215 ms | 43616 KiB |
| 09-180-degree-02.txt | AC | 219 ms | 43620 KiB |
| 10-sandglass-01.txt | AC | 215 ms | 43624 KiB |
| 10-sandglass-02.txt | AC | 219 ms | 43616 KiB |
| 11-circle-01.txt | AC | 213 ms | 43616 KiB |
| 11-circle-02.txt | AC | 213 ms | 43616 KiB |
| 11-circle-03.txt | AC | 213 ms | 43616 KiB |
| 11-circle-04.txt | AC | 214 ms | 43620 KiB |
| 11-circle-05.txt | AC | 216 ms | 43624 KiB |
| 12-square-01.txt | AC | 216 ms | 43624 KiB |
| 12-square-02.txt | AC | 219 ms | 43616 KiB |
| 12-square-03.txt | AC | 217 ms | 43620 KiB |
| 13-corner-01.txt | AC | 213 ms | 43616 KiB |
| 13-corner-02.txt | AC | 213 ms | 43620 KiB |