Submission #12200337


Source Code Expand

(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-int:defconstant-eqx opt
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))
    #'equal)
  #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
  #-swank (set-dispatch-macro-character
           #\# #\> (lambda (s c p) (declare (ignore c p)) `(values ,(read s nil nil t)))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(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
;;;


;; Reference: https://codeforces.com/blog/entry/57496
(defun solve (mat)
  (declare (optimize (speed 3))
           ((array * (* *)) mat))
  (let* ((n (array-dimension mat 0))
         (adjs (make-array n :element-type 'uint62 :initial-element 0))
         (res n))
    (declare ((integer 0 62) n res))
    (assert (= n (array-dimension mat 1)))
    (dotimes (i n)
      (dotimes (j n)
        (when (= (aref mat i j) 1)
          (setf (ldb (byte 1 j) (aref adjs i)) 1))))
    (labels ((tzcount (x) (- (integer-length (logand x (- x))) 1)))
      (dolist (mod '(2147483647 2147483489 2147483477))
        (declare (uint31 mod))
        (let ((ind (make-array (ash 1 n) :element-type 'uint31 :initial-element 0))
              (s (make-array (ash 1 n) :element-type 'uint31 :initial-element 0)))
          ;; store signs for inclusion-exclusion
          (dotimes (i (ash 1 n))
            (setf (aref s i) (if (oddp (- n (logcount i))) (- mod 1) 1)))
          (setf (aref ind 0) 1)
          (loop for i from 1 below (ash 1 n)
                for u = (tzcount i)
                do (setf (aref ind i)
                         (mod (+ (aref ind (logxor i (ash 1 u)))
                                 (aref ind (logandc2 (logxor i (ash 1 u))
                                                     (aref adjs u))))
                              mod)))
          (loop for k from 1
                for sum of-type uint31 = 0
                while (< k res)
                do (dotimes (i (ash 1 n))
                     (setf (aref s i)
                           (mod (* (aref s i) (aref ind i)) mod)
                           sum (mod (+ sum (aref s i)) mod)))
                   (unless (zerop sum)
                     (setq res k))))))
    res))

(defun overlap-p (l1 r1 l2 r2)
  (and (< l1 r2) (< l2 r1)))

(defun main ()
  (let* ((n (read))
         (ls (make-array n))
         (rs (make-array n))
         (mat (make-array (list n n) :element-type 'uint62 :initial-element 0)))
    (dotimes (i n)
      (let* ((line (read-line))
             (l-hour (read-from-string line t nil :start 0 :end 2))
             (l-min (read-from-string line t nil :start 3 :end 5))
             (r-hour (read-from-string line t nil :start 6 :end 8))
             (r-min (read-from-string line t nil :start 9 :end 11)))
        (setf (aref ls i) (+ l-min (* 60 l-hour))
              (aref rs i) (+ r-min (* 60 r-hour)))))
    (dotimes (i1 n)
      (loop for i2 from 0 below n
            for l1 = (aref ls i1)
            for l2 = (aref ls i2)
            for r1 = (aref rs i1)
            for r2 = (aref rs i2)
            when (and (/= i1 i2)
                      (loop for x from -3 to 3
                            thereis (overlap-p l1 r1 (+ l2 (* 1440 x)) (+ r2 (* 1440 x)))))
            do (setf (aref mat i1 i2) 1)))
    (println (solve mat))))

#-swank (main)

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

#+swank
(defun io-equal (in-string out-string &key (function #'main) (test #'equal))
  "Passes IN-STRING to *STANDARD-INPUT*, executes FUNCTION, and returns true if
the string output to *STANDARD-OUTPUT* is equal to OUT-STRING."
  (labels ((ensure-last-lf (s)
             (if (eql (uiop:last-char s) #\Linefeed)
                 s
                 (uiop:strcat s uiop:+lf+))))
    (funcall test
             (ensure-last-lf out-string)
             (with-output-to-string (out)
               (let ((*standard-output* out))
                 (with-input-from-string (*standard-input* (ensure-last-lf in-string))
                   (funcall function)))))))

#+swank
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "powershell.exe" '("-Command" "Get-Clipboard") :output out :search t)))

#+swank (defparameter *this-pathname* (uiop:current-lisp-file-pathname))
#+swank (defparameter *dat-pathname* (uiop:merge-pathnames* "test.dat" *this-pathname*))

#+swank
(defun run (&optional thing (out *standard-output*))
  "THING := null | string | symbol | pathname

null: run #'MAIN using the text on clipboard as input.
string: run #'MAIN using the string as input.
symbol: alias of FIVEAM:RUN!.
pathname: run #'MAIN using the text file as input."
  (let ((*standard-output* out))
    (etypecase thing
      (null
       (with-input-from-string (*standard-input* (delete #\Return (get-clipbrd)))
         (main)))
      (string
       (with-input-from-string (*standard-input* (delete #\Return thing))
         (main)))
      (symbol (5am:run! thing))
      (pathname
       (with-open-file (*standard-input* thing)
         (main))))))

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

;; To run: (5am:run! :sample)
#+swank
(it.bese.fiveam:test :sample
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "3
10:00 12:00
12:00 14:00
14:00 18:00
"
    "1
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "3
00:00 09:00
08:00 17:00
16:00 25:00
"
    "3
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "4
00:00 07:00
06:00 13:00
12:00 19:00
18:00 25:00
"
    "2
")))

Submission Info

Submission Time
Task C - 席が足りない
User sansaqua
Language Common Lisp (SBCL 1.1.14)
Score 100
Code Size 6651 Byte
Status AC
Exec Time 245 ms
Memory 28392 KiB

Judge Result

Set Name small1 small2 large
Score / Max Score 20 / 20 30 / 30 50 / 50
Status
AC × 45
AC × 42
AC × 88
Set Name Test Cases
small1 small1/00_sample1, small1/10_input00, small1/10_input01, small1/10_input02, small1/10_input03, small1/10_input04, small1/10_input05, small1/10_input06, small1/10_input07, small1/10_input08, small1/10_input09, small1/10_input10, small1/10_input11, small1/10_input12, small1/10_input13, small1/10_input14, small1/10_input15, small1/10_input16, small1/10_input17, small1/10_input18, small1/10_input19, small2/50_sample2, small2/50_sample3, small2/60_input41, small2/60_input42, small2/60_input43, small2/60_input44, small2/60_input45, small2/60_input46, small2/60_input47, small2/60_input48, small2/60_input49, small2/60_input50, small2/60_input51, small2/60_input52, small2/60_input53, small2/60_input54, small2/60_input55, small2/60_input56, small2/60_input57, small2/60_input58, small2/60_input59, small2/60_input60, small2/60_input61, small2/60_input62
small2 small1/00_sample1, small1/10_input00, small1/10_input01, small1/10_input02, small1/10_input03, small1/10_input04, small1/10_input05, small1/10_input06, small1/10_input07, small1/10_input08, small1/10_input09, small1/10_input10, small1/10_input11, small1/10_input12, small1/10_input13, small1/10_input14, small1/10_input15, small1/10_input16, small1/10_input17, small1/10_input18, small1/10_input19, large1/20_input20, large1/20_input21, large1/20_input22, large1/20_input23, large1/20_input24, large1/20_input25, large1/20_input26, large1/20_input27, large1/20_input28, large1/20_input29, large1/20_input30, large1/20_input31, large1/20_input32, large1/20_input33, large1/20_input34, large1/20_input35, large1/20_input36, large1/20_input37, large1/20_input38, large1/20_input39, large1/20_input40
large small1/00_sample1, small1/10_input00, small1/10_input01, small1/10_input02, small1/10_input03, small1/10_input04, small1/10_input05, small1/10_input06, small1/10_input07, small1/10_input08, small1/10_input09, small1/10_input10, small1/10_input11, small1/10_input12, small1/10_input13, small1/10_input14, small1/10_input15, small1/10_input16, small1/10_input17, small1/10_input18, small1/10_input19, small2/50_sample2, small2/50_sample3, small2/60_input41, small2/60_input42, small2/60_input43, small2/60_input44, small2/60_input45, small2/60_input46, small2/60_input47, small2/60_input48, small2/60_input49, small2/60_input50, small2/60_input51, small2/60_input52, small2/60_input53, small2/60_input54, small2/60_input55, small2/60_input56, small2/60_input57, small2/60_input58, small2/60_input59, small2/60_input60, small2/60_input61, small2/60_input62, large1/20_input20, large1/20_input21, large1/20_input22, large1/20_input23, large1/20_input24, large1/20_input25, large1/20_input26, large1/20_input27, large1/20_input28, large1/20_input29, large1/20_input30, large1/20_input31, large1/20_input32, large1/20_input33, large1/20_input34, large1/20_input35, large1/20_input36, large1/20_input37, large1/20_input38, large1/20_input39, large1/20_input40, large2/70_input61, large2/70_input62, large2/70_input63, large2/70_input64, large2/70_input65, large2/70_input66, large2/70_input67, large2/70_input68, large2/70_input69, large2/70_input70, large2/70_input71, large2/70_input72, large2/70_input73, large2/70_input74, large2/70_input75, large2/70_input76, large2/70_input77, large2/70_input78, large2/70_input79, large2/70_input80, large2/70_input81, large2/70_input82
Case Name Status Exec Time Memory
large1/20_input20 AC 245 ms 28392 KiB
large1/20_input21 AC 81 ms 16868 KiB
large1/20_input22 AC 83 ms 16872 KiB
large1/20_input23 AC 84 ms 16872 KiB
large1/20_input24 AC 86 ms 16868 KiB
large1/20_input25 AC 87 ms 16868 KiB
large1/20_input26 AC 106 ms 16864 KiB
large1/20_input27 AC 81 ms 16872 KiB
large1/20_input28 AC 82 ms 16864 KiB
large1/20_input29 AC 83 ms 16868 KiB
large1/20_input30 AC 85 ms 16868 KiB
large1/20_input31 AC 86 ms 16868 KiB
large1/20_input32 AC 93 ms 16864 KiB
large1/20_input33 AC 100 ms 16868 KiB
large1/20_input34 AC 81 ms 16868 KiB
large1/20_input35 AC 81 ms 16872 KiB
large1/20_input36 AC 83 ms 16868 KiB
large1/20_input37 AC 83 ms 16868 KiB
large1/20_input38 AC 86 ms 16868 KiB
large1/20_input39 AC 92 ms 16872 KiB
large1/20_input40 AC 102 ms 16868 KiB
large2/70_input61 AC 82 ms 16868 KiB
large2/70_input62 AC 82 ms 16864 KiB
large2/70_input63 AC 82 ms 16868 KiB
large2/70_input64 AC 83 ms 16864 KiB
large2/70_input65 AC 85 ms 16868 KiB
large2/70_input66 AC 91 ms 16872 KiB
large2/70_input67 AC 97 ms 16864 KiB
large2/70_input68 AC 82 ms 16864 KiB
large2/70_input69 AC 82 ms 16868 KiB
large2/70_input70 AC 84 ms 16868 KiB
large2/70_input71 AC 84 ms 16872 KiB
large2/70_input72 AC 86 ms 16872 KiB
large2/70_input73 AC 90 ms 16868 KiB
large2/70_input74 AC 102 ms 16864 KiB
large2/70_input75 AC 81 ms 16868 KiB
large2/70_input76 AC 81 ms 16868 KiB
large2/70_input77 AC 82 ms 16868 KiB
large2/70_input78 AC 83 ms 16868 KiB
large2/70_input79 AC 85 ms 16872 KiB
large2/70_input80 AC 89 ms 16868 KiB
large2/70_input81 AC 97 ms 16872 KiB
large2/70_input82 AC 88 ms 16868 KiB
small1/00_sample1 AC 82 ms 16872 KiB
small1/10_input00 AC 81 ms 16868 KiB
small1/10_input01 AC 81 ms 16864 KiB
small1/10_input02 AC 81 ms 16868 KiB
small1/10_input03 AC 81 ms 16868 KiB
small1/10_input04 AC 81 ms 16868 KiB
small1/10_input05 AC 81 ms 16872 KiB
small1/10_input06 AC 82 ms 16868 KiB
small1/10_input07 AC 81 ms 16868 KiB
small1/10_input08 AC 81 ms 16868 KiB
small1/10_input09 AC 83 ms 16868 KiB
small1/10_input10 AC 81 ms 16872 KiB
small1/10_input11 AC 81 ms 16864 KiB
small1/10_input12 AC 81 ms 16868 KiB
small1/10_input13 AC 81 ms 16864 KiB
small1/10_input14 AC 81 ms 16868 KiB
small1/10_input15 AC 81 ms 16868 KiB
small1/10_input16 AC 81 ms 16872 KiB
small1/10_input17 AC 82 ms 16868 KiB
small1/10_input18 AC 81 ms 16868 KiB
small1/10_input19 AC 81 ms 16868 KiB
small2/50_sample2 AC 83 ms 16868 KiB
small2/50_sample3 AC 81 ms 16868 KiB
small2/60_input41 AC 82 ms 16868 KiB
small2/60_input42 AC 82 ms 16868 KiB
small2/60_input43 AC 81 ms 16868 KiB
small2/60_input44 AC 81 ms 16864 KiB
small2/60_input45 AC 82 ms 16868 KiB
small2/60_input46 AC 82 ms 16864 KiB
small2/60_input47 AC 82 ms 16864 KiB
small2/60_input48 AC 81 ms 16872 KiB
small2/60_input49 AC 81 ms 16872 KiB
small2/60_input50 AC 81 ms 16872 KiB
small2/60_input51 AC 81 ms 16868 KiB
small2/60_input52 AC 81 ms 16868 KiB
small2/60_input53 AC 81 ms 16872 KiB
small2/60_input54 AC 81 ms 16868 KiB
small2/60_input55 AC 81 ms 16868 KiB
small2/60_input56 AC 81 ms 16872 KiB
small2/60_input57 AC 81 ms 16868 KiB
small2/60_input58 AC 81 ms 16868 KiB
small2/60_input59 AC 81 ms 16868 KiB
small2/60_input60 AC 81 ms 16864 KiB
small2/60_input61 AC 82 ms 16872 KiB
small2/60_input62 AC 81 ms 16868 KiB