結果

問題 No.779 Heisei
ユーザー sansaquasansaqua
提出日時 2020-11-07 04:46:54
言語 Common Lisp
(sbcl 2.3.8)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 4,539 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 34,304 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-07-22 14:17:51
合計ジャッジ時間 1,304 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
22,272 KB
testcase_01 AC 12 ms
22,400 KB
testcase_02 AC 11 ms
22,272 KB
testcase_03 AC 10 ms
22,272 KB
testcase_04 AC 10 ms
22,272 KB
testcase_05 AC 9 ms
22,272 KB
testcase_06 AC 9 ms
22,272 KB
testcase_07 AC 10 ms
22,272 KB
testcase_08 AC 10 ms
22,272 KB
testcase_09 AC 9 ms
22,272 KB
testcase_10 AC 10 ms
22,272 KB
testcase_11 AC 9 ms
22,272 KB
testcase_12 AC 10 ms
22,272 KB
testcase_13 AC 9 ms
22,272 KB
testcase_14 AC 9 ms
22,272 KB
testcase_15 AC 9 ms
22,272 KB
testcase_16 AC 9 ms
22,272 KB
testcase_17 AC 9 ms
22,144 KB
testcase_18 AC 9 ms
22,272 KB
testcase_19 AC 9 ms
22,272 KB
testcase_20 AC 12 ms
22,400 KB
testcase_21 AC 9 ms
22,272 KB
testcase_22 AC 9 ms
22,272 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 22 JUL 2024 02:17:49 PM):

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

ソースコード

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