結果

問題 No.779 Heisei
ユーザー sansaquasansaqua
提出日時 2020-11-07 04:46:54
言語 Common Lisp
(sbcl 2.3.8)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 4,539 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 38,804 KB
実行使用メモリ 29,260 KB
最終ジャッジ日時 2023-09-29 20:11:54
合計ジャッジ時間 2,115 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
25,304 KB
testcase_01 AC 8 ms
27,344 KB
testcase_02 AC 7 ms
23,272 KB
testcase_03 AC 8 ms
23,336 KB
testcase_04 AC 8 ms
27,232 KB
testcase_05 AC 9 ms
27,416 KB
testcase_06 AC 8 ms
23,352 KB
testcase_07 AC 8 ms
23,176 KB
testcase_08 AC 9 ms
27,324 KB
testcase_09 AC 8 ms
23,160 KB
testcase_10 AC 9 ms
29,260 KB
testcase_11 AC 7 ms
23,256 KB
testcase_12 AC 9 ms
27,336 KB
testcase_13 AC 7 ms
23,180 KB
testcase_14 AC 7 ms
23,240 KB
testcase_15 AC 8 ms
25,328 KB
testcase_16 AC 7 ms
23,176 KB
testcase_17 AC 8 ms
27,320 KB
testcase_18 AC 8 ms
23,320 KB
testcase_19 AC 8 ms
23,280 KB
testcase_20 AC 8 ms
27,292 KB
testcase_21 AC 7 ms
23,356 KB
testcase_22 AC 8 ms
23,324 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 29 SEP 2023 08:11:53 PM):
; processing (IN-PACKAGE :CL-USER)
; processing (DEFPARAMETER *OPT* ...)
; processing (SET-DISPATCH-MACRO-CHARACTER #\# ...)
; processing (DEFINE-INT-TYPES 2 ...)
; processing (DEFCONSTANT +MOD+ ...)
; processing (DEFMACRO DBG ...)
; processing (DECLAIM (INLINE PRINTLN))
; processing (DEFUN PRINTLN ...)
; processing (DEFPACKAGE :CP/DATE ...)
; processing (IN-PACKAGE :CP/DATE)
; processing (DECLAIM (INLINE LEAP-YEAR-P))
; processing (DEFUN LEAP-YEAR-P ...)
; processing (DEFUN GET-DAY-OF-WEEK ...)
; processing (DECLAIM (INLINE GET-JULIAN-DAY-NUMBER))
; processing (DEFUN GET-JULIAN-DAY-NUMBER ...)
; processing (USE-PACKAGE :CP/DATE ...)
; processing (IN-PACKAGE :CL-USER)
; processing (DEFUN MAIN ...)
; processing (MAIN)

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

ソースコード

diff #

(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)))))
#+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)
  #+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)))

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

;; BEGIN_INSERTED_CONTENTS
(defpackage :cp/date
  (:use :cl)
  (:export #:leap-year-p #:get-day-of-week #:get-julian-day-number))
(in-package :cp/date)

(declaim (inline leap-year-p))
(defun leap-year-p (year)
  (or (zerop (mod year 400))
      (and (zerop (mod year 4))
           (not (zerop (mod year 100))))))

;; Gauss's algorithm
;; https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
(defun get-day-of-week (day month year)
  "Returns the day of the week (starting with Sunday) as an integer from 0 to 6.
Note that DAY and MONTH are 1-based."
  (declare ((integer 1 31) day)
           ((integer 1 12) month)
           (fixnum year))
  (let ((ms #.(coerce #(0 3 3 6 1 4 6 2 5 0 3 5)
                      '(simple-array (unsigned-byte 4) (*))))
        (leap-ms #.(coerce #(0 3 4 0 2 5 0 3 6 1 4 6)
                           '(simple-array (unsigned-byte 4) (*)))))
    (let ((m (aref (if (leap-year-p year) leap-ms ms)
                   (- month 1))))
      (declare ((integer 0 6) m))
      (mod (+ day
              m
              (* 5 (mod (- year 1) 4))
              (* 4 (mod (- year 1) 100))
              (* 6 (mod (- year 1) 400)))
           7))))

(declaim (inline get-julian-day-number))
(defun get-julian-day-number (day month year)
  "Converts a Gregorian calendar date to Julian Day Number. (It will be used to
get the number of days between two dates."
  (+ (truncate (* 1461 (+ year 4800 (truncate (- month 14) 12))) 4)
     (truncate (* 367 (- month 2 (* 12 (truncate (- month 14) 12)))) 12)
     (- (truncate (* 3 (truncate (+ year 4900 (truncate (- month 14) 12)) 100)) 4))
     day
     -32075))

;; BEGIN_USE_PACKAGE
(eval-when (:compile-toplevel :load-toplevel :execute)
  (use-package :cp/date :cl-user))
(in-package :cl-user)

;;;
;;; Body
;;;

(defun main ()
  (let* ((y (read))
         (m (read))
         (d (read)))
    (write-line (if (<= (get-julian-day-number 8 1 1989)
                        (get-julian-day-number d m y)
                        (get-julian-day-number 30 4 2019))
                    "Yes"
                    "No"))))

#-swank (main)

;;;
;;; Test and benchmark
;;;

#+swank
(progn
  (defparameter *lisp-file-pathname* (uiop:current-lisp-file-pathname))
  (setq *default-pathname-defaults* (uiop:pathname-directory-pathname *lisp-file-pathname*))
  (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *lisp-file-pathname*))
  (defparameter *problem-url* "https://yukicoder.me/problems/no/779"))

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

#-swank
(eval-when (:compile-toplevel)
  (when (or (> sb-c::*compiler-warning-count* 0)
            sb-c::*undefined-warnings*)
    (error "count: ~D, undefined warnings: ~A"
           sb-c::*compiler-warning-count*
           sb-c::*undefined-warnings*)))

;; To run: (5am:run! :sample)
#+swank
(5am:test :sample
  (5am:is
   (equal "Yes
"
          (run "2001 9 9
" nil)))
  (5am:is
   (equal "No
"
          (run "2019 5 3
" nil)))
  (5am:is
   (equal "No
"
          (run "1989 1 7
" nil))))
0