Submission #5082472


Source Code Expand

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return (if minus (- result) result))))))))

(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

(defun main ()
  (let* ((n (read))
         (ts (make-array n :element-type 'uint16))
         (cumul-ts (make-array (+ 1 n) :element-type 'uint16 :initial-element 0))
         (vs (make-array (+ n 1) :element-type 'uint16)))
    (dotimes (i n) (setf (aref ts i) (* 2 (read-fixnum))))
    (dotimes (i n) (setf (aref vs i) (* 2 (read-fixnum))))
    (loop for i from n downto 1
          do (when (> (aref vs (- i 1)) (aref vs i))
               (setf (aref vs (- i 1))
                     (min (aref vs (- i 1))
                          (+ (aref vs i) (aref ts (- i 1)))))))
    (dotimes (i n)
      (setf (aref cumul-ts (+ i 1))
            (+ (aref cumul-ts i) (aref ts i))))
    (let* ((total-time (reduce #'+ ts))
           (next-points (make-array total-time :element-type 'uint16))
           (prev-points (make-array total-time :element-type 'uint16))
           (time-vs (make-array total-time :element-type 'uint16))
           (time-next-vs (make-array total-time :element-type 'uint16))
           (timeline (make-array (+ total-time 1) :element-type 'uint16 :initial-element 0)))
      (dotimes (i n)
        (loop for time from (aref cumul-ts i) below (aref cumul-ts (+ i 1))
              do (setf (aref next-points time) (aref cumul-ts (+ i 1))
                       (aref prev-points time) (aref cumul-ts i)
                       (aref time-vs time) (aref vs i)
                       (aref time-next-vs time) (aref vs (+ i 1))))
        (unless (zerop i)
          (setf (aref time-vs (aref cumul-ts i))
                (min (aref time-vs (aref cumul-ts i))
                     (aref time-vs (- (aref cumul-ts i) 1))))))
      (loop for time from 1 below total-time
            for prev-v = (aref timeline (- time 1))
            do (cond ((and (<= (- (+ 1 prev-v) (- (aref next-points time) time))
                               (aref time-next-vs time))
                           (<= (+ 1 prev-v) (aref time-vs time)))
                      (setf (aref timeline time) (+ 1 prev-v)))
                     ((and (<= (- prev-v (- (aref next-points time) time))
                               (aref time-next-vs time))
                           (<= prev-v (aref time-vs time)))
                      (setf (aref timeline time) prev-v))
                     (t (setf (aref timeline time) (- prev-v 1)))))
      (println (/ (loop for time from 0 below total-time
                        sum (+ (aref timeline time) (aref timeline (+ 1 time))))
                  8d0)))))

#-swank(main)

Submission Info

Submission Time
Task D - AtCoder Express
User sansaqua
Language Common Lisp (SBCL 1.1.14)
Score 400
Code Size 4895 Byte
Status AC
Exec Time 94 ms
Memory 18920 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 40
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt, s5.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, s1.txt, s2.txt, s3.txt, s4.txt, s5.txt
Case Name Status Exec Time Memory
in01.txt AC 92 ms 18916 KiB
in02.txt AC 92 ms 18920 KiB
in03.txt AC 92 ms 18912 KiB
in04.txt AC 91 ms 18912 KiB
in05.txt AC 92 ms 18912 KiB
in06.txt AC 92 ms 18920 KiB
in07.txt AC 92 ms 18916 KiB
in08.txt AC 92 ms 18912 KiB
in09.txt AC 92 ms 18916 KiB
in10.txt AC 92 ms 18916 KiB
in11.txt AC 93 ms 18916 KiB
in12.txt AC 92 ms 18916 KiB
in13.txt AC 91 ms 18912 KiB
in14.txt AC 92 ms 18916 KiB
in15.txt AC 92 ms 18912 KiB
in16.txt AC 92 ms 18916 KiB
in17.txt AC 91 ms 18916 KiB
in18.txt AC 92 ms 18916 KiB
in19.txt AC 92 ms 18916 KiB
in20.txt AC 92 ms 18916 KiB
in21.txt AC 92 ms 18912 KiB
in22.txt AC 92 ms 18916 KiB
in23.txt AC 91 ms 18920 KiB
in24.txt AC 92 ms 18916 KiB
in25.txt AC 92 ms 18912 KiB
in26.txt AC 92 ms 18916 KiB
in27.txt AC 92 ms 18916 KiB
in28.txt AC 91 ms 18916 KiB
in29.txt AC 92 ms 18920 KiB
in30.txt AC 92 ms 18916 KiB
in31.txt AC 92 ms 18916 KiB
in32.txt AC 93 ms 18916 KiB
in33.txt AC 94 ms 18916 KiB
in34.txt AC 92 ms 18916 KiB
in35.txt AC 92 ms 18912 KiB
s1.txt AC 91 ms 18912 KiB
s2.txt AC 92 ms 18916 KiB
s3.txt AC 92 ms 18916 KiB
s4.txt AC 92 ms 18916 KiB
s5.txt AC 92 ms 18916 KiB