結果

問題 No.1767 BLUE to RED
ユーザー motoshiramotoshira
提出日時 2021-11-27 00:31:44
言語 Common Lisp
(sbcl 2.3.8)
結果
AC  
実行時間 516 ms / 2,000 ms
コード長 2,679 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 37,988 KB
実行使用メモリ 78,964 KB
最終ジャッジ日時 2023-09-12 06:11:12
合計ジャッジ時間 8,838 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
27,320 KB
testcase_01 AC 10 ms
27,248 KB
testcase_02 AC 9 ms
23,280 KB
testcase_03 AC 9 ms
23,208 KB
testcase_04 AC 12 ms
23,260 KB
testcase_05 AC 11 ms
25,324 KB
testcase_06 AC 9 ms
23,200 KB
testcase_07 AC 12 ms
27,212 KB
testcase_08 AC 12 ms
25,508 KB
testcase_09 AC 302 ms
52,660 KB
testcase_10 AC 386 ms
64,604 KB
testcase_11 AC 321 ms
54,760 KB
testcase_12 AC 296 ms
56,432 KB
testcase_13 AC 420 ms
67,016 KB
testcase_14 AC 514 ms
75,288 KB
testcase_15 AC 516 ms
75,284 KB
testcase_16 AC 512 ms
78,964 KB
testcase_17 AC 512 ms
75,372 KB
testcase_18 AC 513 ms
78,876 KB
testcase_19 AC 516 ms
77,260 KB
testcase_20 AC 516 ms
78,880 KB
testcase_21 AC 513 ms
75,312 KB
testcase_22 AC 515 ms
78,876 KB
testcase_23 AC 515 ms
77,232 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 12 SEP 2023 06:11:03 AM):
; processing (IN-PACKAGE #:CL-USER)
; processing (DECLAIM (OPTIMIZE # ...))
; processing (DECLAIM (MUFFLE-CONDITIONS COMPILER-NOTE))
; processing (DISABLE-DEBUGGER)
; processing (PUSHNEW :INLINE-GENERIC-FUNCION ...)
; processing (IN-PACKAGE #:CL-USER)
; processing (DECLAIM (INLINE PRINTLN))
; processing (DEFUN PRINTLN ...)
; processing (DEFUN READ-INTO ...)
; processing (DEFCONSTANT +INF+ ...)
; processing (DEFUN MAIN ...)
; processing (MAIN)

; wrote /home/judge/data/code/Main.fasl
; compilation finished in 0:00:00.013

ソースコード

diff #

(in-package #:cl-user)

;;------------------------------Preferences------------------------------

(eval-when (:compile-toplevel :load-toplevel :execute)
  #+swank (declaim (optimize (speed 3) (safety 2)))
  #-swank (declaim (optimize (speed 3) (safety 0) (debug 0)))
  #+swank (load "~/ghq/github.com/motoshira/atcoder-submission/ac-tools/act.lisp")
  #+swank (ql:quickload :prove)
  #-swank (declaim (sb-ext:muffle-conditions sb-ext:compiler-note))
  #-swank (sb-ext:disable-debugger)
  (pushnew :inline-generic-funcion *features*))

;;---------------------------------Body---------------------------------

(in-package #:cl-user)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 obj
      (princ obj stream)
      (terpri stream))))

(defun read-into (count &optional (result-type 'list) (reader #'read))
  (coerce (loop :repeat count :collect (funcall reader)) result-type))

(defconstant +inf+ #.(ash 1 60))

(defun main ()
  (let* ((n (read))
         (m (read))
         (as (read-into n))
         (bs (read-into m))
         (es nil))
    ;; blue -> 0
    ;; red  -> 1
    (dolist (a as)
      (push (list a 1) es))
    (push (list +inf+ 1) es)
    (push (list (- +inf+) 1) es)
    (dolist (b bs)
      (push (list b 0) es))
    (setf es (sort es #'< :key #'first))
    (let ((res 0)
          (cs nil)
          (a nil))
      (flet ((push-blue! (blue)
               (push blue cs))
             (inc-and-flush-blue! (red)
               (declare (fixnum red))
               (when a
                 (incf res
                       (- (1- (abs (- red a)))
                          (loop :for (b0 b1) :on (concatenate 'list
                                                              (list a)
                                                              (reverse cs)
                                                              (list red))
                                :by #'cdr
                                :when b1
                                  :maximize (1- (- b1 b0))))))
               (setf a red
                     cs nil)))
        (loop :for (value type) :in es
              :do (ecase type
                    (0 (push-blue! value))
                    (1 (inc-and-flush-blue! value))))
        (println res)))))

#-swank (main)

#+swank
(defun run ()
  (let ((*standard-input*
          (make-string-input-stream
           (with-output-to-string (*standard-output*)
             (run-program
              (merge-pathnames "copy-or-paste" (truename "~/bin/"))
              '()
              :output *standard-output*)))))
    (main)))
0