Please sign in first.
Submission #20639990
Source Code Expand
(in-package :cl-user)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter *opt*
#+swank '(optimize (speed 3) (safety 2))
#-swank '(optimize (speed 3) (safety 0) (debug 0)))
#+swank (ql:quickload '(:cl-debug-print :fiveam :cp/util) :silent t)
#+swank (use-package :cp/util :cl-user)
#-swank (set-dispatch-macro-character
#\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t))))
#+sbcl (dolist (f '(:popcnt :sse4)) (pushnew f sb-c:*backend-subfeatures*))
#+sbcl (setq *random-state* (seed-random-state (nth-value 1 (get-time-of-day)))))
#-swank (eval-when (:compile-toplevel)
(setq *break-on-signals* '(and warning (not style-warning))))
#+swank (set-dispatch-macro-character #\# #\> #'cl-debug-print:debug-print-reader)
(macrolet ((def (b)
`(progn (deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))
(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))))
(define-int-types (&rest bits) `(progn ,@(mapcar (lambda (b) `(def ,b)) bits))))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64))
(defconstant +mod+ 1000000007)
(defmacro dbg (&rest forms)
(declare (ignorable forms))
#+swank (if (= (length forms) 1)
`(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
`(format *error-output* "~A => ~A~%" ',forms `(,,@forms))))
(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
(let ((*read-default-float-format*
(if (typep obj 'double-float) 'double-float *read-default-float-format*)))
(prog1 (princ obj stream) (terpri stream))))
;; BEGIN_INSERTED_CONTENTS
(defpackage :cp/read-fixnum
(:use :cl)
(:export #:read-fixnum))
(in-package :cp/read-fixnum)
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
"NOTE: cannot read -2^62"
(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
(error "Read EOF or #\Nul."))
((= byte #.(char-code #\-))
(setq minus t)))))))
(declare ((integer 0 #.most-positive-fixnum) result))
(loop
(let* ((byte (%read-byte)))
(if (<= 48 byte 57)
(setq result (+ (- byte 48)
(* 10 (the (integer 0 #.(floor most-positive-fixnum 10))
result))))
(return (if minus (- result) result))))))))
(defpackage :cp/modify-macro
(:use :cl)
(:export #:minf #:maxf #:mulf #:divf #:iorf #:xorf #:andf))
(in-package :cp/modify-macro)
(macrolet ((def (name fname)
`(define-modify-macro ,name (new-value) ,fname)))
(def minf min)
(def maxf max)
(def mulf *)
(def divf /)
(def iorf logior)
(def xorf logxor)
(def andf logand))
;; BEGIN_USE_PACKAGE
(eval-when (:compile-toplevel :load-toplevel :execute)
(use-package :cp/modify-macro :cl-user))
(eval-when (:compile-toplevel :load-toplevel :execute)
(use-package :cp/read-fixnum :cl-user))
(in-package :cl-user)
;;;
;;; Body
;;;
(defun main ()
(declare #.*opt*)
(let* ((n (read))
(hs (make-array n :element-type 'uint16 :initial-element 0))
(cs (make-array '(5001 5001) :element-type 'uint31 :initial-element 0))
(invs (make-array '(5001 5001) :element-type 'uint31 :initial-element 0))
(dp (make-array (+ n 1) :element-type 'uint31 :initial-element #x7fffffff)))
(declare (uint16 n))
(dotimes (i n)
(let ((h (read-fixnum)))
(setf (aref hs i) (- h 1))))
(loop for i from 1 below n
for x = (aref hs i)
for prev = (aref hs (- i 1))
do (dotimes (y n)
(setf (aref cs (+ x 1) y)
(if (>= prev y)
(+ 1 (aref cs (+ 1 prev) y))
(aref cs (+ 1 prev) y)))))
(dotimes (x n)
(loop for y from (+ x 1) to n
do (setf (aref invs x y)
(+ (aref invs x (- y 1))
(- (- y 1 x)
(- (aref cs y x)
(aref cs y y)))))))
(dotimes (y (+ n 1))
(loop for x from 1 to n
do (incf (aref cs x y) (aref cs (- x 1) y))))
(setf (aref dp 0) 0)
(dotimes (x n)
(loop for y from (+ x 1) to n
for incr = (- (- (aref cs y x) (aref cs x x))
(aref invs x y))
do (minf (aref dp y) (+ incr (aref dp x)))))
(println (aref dp n))))
#-swank (main)
;;;
;;; Test
;;;
#+swank
(progn
(defparameter *lisp-file-pathname* (uiop:current-lisp-file-pathname))
(setq *default-pathname-defaults* (uiop:pathname-directory-pathname *lisp-file-pathname*))
(uiop:chdir *default-pathname-defaults*)
(defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *lisp-file-pathname*))
(defparameter *problem-url* "https://atcoder.jp/contests/joi2021ho/tasks/joi2021ho_c"))
#+swank
(defun gen-dat ()
(uiop:with-output-file (out *dat-pathname* :if-exists :supersede)
(format out "")))
#+swank
(defun bench (&optional (out (make-broadcast-stream)))
(time (run *dat-pathname* out)))
#+(and sbcl (not swank))
(eval-when (:compile-toplevel)
(when sb-c::*undefined-warnings*
(error "undefined warnings: ~{~A~^ ~}" sb-c::*undefined-warnings*)))
;; To run: (5am:run! :sample)
#+swank
(5am:test :sample
(5am:is
(equal "3
"
(run "5
3 5 2 4 1
" nil)))
(5am:is
(equal "0
"
(run "5
3 2 1 5 4
" nil)))
(5am:is
(equal "9
"
(run "9
6 1 3 4 9 5 7 8 2
" nil))))
Submission Info
| Submission Time | |
|---|---|
| Task | C - 集合写真 (Group Photo) |
| User | sansaqua |
| Language | Common Lisp (SBCL 2.0.3) |
| Score | 100 |
| Code Size | 6099 Byte |
| Status | AC |
| Exec Time | 665 ms |
| Memory | 189852 KiB |
Judge Result
| Set Name | Subtask 1 | Subtask 2 | Subtask 3 | Subtask 4 | Subtask 5 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 5 / 5 | 7 / 7 | 32 / 32 | 20 / 20 | 36 / 36 | ||||||||||
| Status |
|
|
|
|
|
| Set Name | Test Cases |
|---|---|
| Subtask 1 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt |
| Subtask 2 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt |
| Subtask 3 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt |
| Subtask 4 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 04-01.txt, 04-02.txt, 04-03.txt, 04-04.txt, 04-05.txt, 04-06.txt, 04-07.txt, 04-08.txt, 04-09.txt, 04-10.txt |
| Subtask 5 | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 04-01.txt, 04-02.txt, 04-03.txt, 04-04.txt, 04-05.txt, 04-06.txt, 04-07.txt, 04-08.txt, 04-09.txt, 04-10.txt, 05-01.txt, 05-02.txt, 05-03.txt, 05-04.txt, 05-05.txt, 05-06.txt, 05-07.txt, 05-08.txt, 05-09.txt, 05-10.txt, 05-11.txt, 05-12.txt, 05-13.txt, 05-14.txt, 05-15.txt, sample-01.txt, sample-02.txt, sample-03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01-01.txt | AC | 16 ms | 25288 KiB |
| 01-02.txt | AC | 12 ms | 25312 KiB |
| 01-03.txt | AC | 15 ms | 25396 KiB |
| 01-04.txt | AC | 13 ms | 25292 KiB |
| 01-05.txt | AC | 21 ms | 25348 KiB |
| 01-06.txt | AC | 19 ms | 25416 KiB |
| 01-07.txt | AC | 13 ms | 25328 KiB |
| 01-08.txt | AC | 17 ms | 25380 KiB |
| 01-09.txt | AC | 14 ms | 25360 KiB |
| 01-10.txt | AC | 17 ms | 25288 KiB |
| 02-01.txt | AC | 16 ms | 25436 KiB |
| 02-02.txt | AC | 13 ms | 25448 KiB |
| 02-03.txt | AC | 14 ms | 25424 KiB |
| 02-04.txt | AC | 17 ms | 25488 KiB |
| 02-05.txt | AC | 15 ms | 25412 KiB |
| 02-06.txt | AC | 15 ms | 25400 KiB |
| 02-07.txt | AC | 16 ms | 25452 KiB |
| 02-08.txt | AC | 15 ms | 25376 KiB |
| 02-09.txt | AC | 18 ms | 25388 KiB |
| 02-10.txt | AC | 14 ms | 25492 KiB |
| 03-01.txt | AC | 16 ms | 27156 KiB |
| 03-02.txt | AC | 15 ms | 27064 KiB |
| 03-03.txt | AC | 14 ms | 27092 KiB |
| 03-04.txt | AC | 20 ms | 27112 KiB |
| 03-05.txt | AC | 16 ms | 27060 KiB |
| 03-06.txt | AC | 19 ms | 27100 KiB |
| 03-07.txt | AC | 15 ms | 27132 KiB |
| 03-08.txt | AC | 19 ms | 27196 KiB |
| 03-09.txt | AC | 21 ms | 27180 KiB |
| 03-10.txt | AC | 14 ms | 27116 KiB |
| 04-01.txt | AC | 31 ms | 35376 KiB |
| 04-02.txt | AC | 31 ms | 35360 KiB |
| 04-03.txt | AC | 35 ms | 35400 KiB |
| 04-04.txt | AC | 34 ms | 35460 KiB |
| 04-05.txt | AC | 32 ms | 35348 KiB |
| 04-06.txt | AC | 30 ms | 35420 KiB |
| 04-07.txt | AC | 31 ms | 35424 KiB |
| 04-08.txt | AC | 34 ms | 35360 KiB |
| 04-09.txt | AC | 29 ms | 35360 KiB |
| 04-10.txt | AC | 33 ms | 35464 KiB |
| 05-01.txt | AC | 663 ms | 189692 KiB |
| 05-02.txt | AC | 658 ms | 189656 KiB |
| 05-03.txt | AC | 665 ms | 189672 KiB |
| 05-04.txt | AC | 661 ms | 189756 KiB |
| 05-05.txt | AC | 662 ms | 189768 KiB |
| 05-06.txt | AC | 659 ms | 189788 KiB |
| 05-07.txt | AC | 657 ms | 189736 KiB |
| 05-08.txt | AC | 657 ms | 189784 KiB |
| 05-09.txt | AC | 658 ms | 189848 KiB |
| 05-10.txt | AC | 658 ms | 189768 KiB |
| 05-11.txt | AC | 660 ms | 189804 KiB |
| 05-12.txt | AC | 661 ms | 189852 KiB |
| 05-13.txt | AC | 660 ms | 189728 KiB |
| 05-14.txt | AC | 663 ms | 189780 KiB |
| 05-15.txt | AC | 663 ms | 189752 KiB |
| sample-01.txt | AC | 19 ms | 25308 KiB |
| sample-02.txt | AC | 19 ms | 25300 KiB |
| sample-03.txt | AC | 19 ms | 25292 KiB |