提出 #4712556


ソースコード 拡げる

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  `(progn
     ,@(mapcar (lambda (form) `(format *error-output* "~A => ~A~%" ',form ,form))
               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)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Body
(defun make-com-table (size)
  (let* ((table (make-array (list size size)
                            :element-type 'double-float
                            :initial-element 0d0)))
    (setf (aref table 0 0) 1d0)
    (loop for i from 1 below size
          do (setf (aref table i 0) 1d0)
             (loop for j from 1 below size
                   do (setf (aref table i j)
                            (+ (aref table (- i 1) (- j 1))
                               (aref table (- i 1) j)))))
    table))

(declaim ((simple-array double-float (* *)) *com*))
(defparameter *com* (make-com-table 100))

(declaim (inline binom))
(defun binom (x y)
  (if (< x y)
      0
      (aref *com* x y)))

(defparameter *fact*
  (let ((table (make-array 101 :element-type 'double-float :initial-element 1d0)))
    (loop for i from 1 below (length table)
          do (setf (aref table i) (* i (aref table (- i 1)))))
    table))

(defun calc-expectation (d n)
  (declare (uint7 d n))
  (if (zerop d)
      1d0
      (/ (* (loop for p from 1 to n
                  sum (loop for prev-num from 0 to d by 2
                            sum (* (binom (- p 1) prev-num)
                                   (binom (- n p) (- d prev-num)))))
            (aref *fact* d))
         (/ (aref *fact* n)
            (aref *fact* (- n d 1))))))

(defun main ()
  (let* ((n (read))
         (cs (make-array n :element-type 'uint31))
         (ds (make-array n :element-type 'uint7)))
    (dotimes (i n) (setf (aref cs i) (read)))
    (dotimes (i n)
      (dotimes (j n)
        (when (and (not (= i j))
                   (zerop (mod (aref cs i) (aref cs j))))
          (incf (aref ds i)))))
    (println (loop for d across ds
                   sum (calc-expectation d n)))))

#-swank(main)

提出情報

提出日時
問題 C - コイン
ユーザ sansaqua
言語 Common Lisp (SBCL 1.1.14)
得点 100
コード長 2952 Byte
結果 AC
実行時間 332 ms
メモリ 34272 KiB

ジャッジ結果

セット名 Sample Subtask1 Subtask2
得点 / 配点 0 / 0 99 / 99 1 / 1
結果
AC × 3
AC × 20
AC × 40
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt
Subtask2 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt
ケース名 結果 実行時間 メモリ
sample_01.txt AC 332 ms 34272 KiB
sample_02.txt AC 73 ms 14820 KiB
sample_03.txt AC 73 ms 14824 KiB
subtask1_01.txt AC 73 ms 14820 KiB
subtask1_02.txt AC 73 ms 14816 KiB
subtask1_03.txt AC 73 ms 14820 KiB
subtask1_04.txt AC 73 ms 14820 KiB
subtask1_05.txt AC 73 ms 14820 KiB
subtask1_06.txt AC 73 ms 14820 KiB
subtask1_07.txt AC 73 ms 14820 KiB
subtask1_08.txt AC 73 ms 14820 KiB
subtask1_09.txt AC 74 ms 14820 KiB
subtask1_10.txt AC 74 ms 14820 KiB
subtask1_11.txt AC 73 ms 14820 KiB
subtask1_12.txt AC 73 ms 14816 KiB
subtask1_13.txt AC 73 ms 14820 KiB
subtask1_14.txt AC 73 ms 14824 KiB
subtask1_15.txt AC 73 ms 14816 KiB
subtask1_16.txt AC 73 ms 14824 KiB
subtask1_17.txt AC 74 ms 14816 KiB
subtask1_18.txt AC 73 ms 14820 KiB
subtask1_19.txt AC 73 ms 14820 KiB
subtask1_20.txt AC 74 ms 14816 KiB
subtask2_01.txt AC 75 ms 14820 KiB
subtask2_02.txt AC 73 ms 14816 KiB
subtask2_03.txt AC 74 ms 14816 KiB
subtask2_04.txt AC 76 ms 16868 KiB
subtask2_05.txt AC 75 ms 16868 KiB
subtask2_06.txt AC 74 ms 14820 KiB
subtask2_07.txt AC 74 ms 14820 KiB
subtask2_08.txt AC 83 ms 29156 KiB
subtask2_09.txt AC 82 ms 29160 KiB
subtask2_10.txt AC 82 ms 29156 KiB
subtask2_11.txt AC 79 ms 23012 KiB
subtask2_12.txt AC 79 ms 23012 KiB
subtask2_13.txt AC 75 ms 16872 KiB
subtask2_14.txt AC 80 ms 25064 KiB
subtask2_15.txt AC 79 ms 23012 KiB
subtask2_16.txt AC 74 ms 14820 KiB
subtask2_17.txt AC 82 ms 29160 KiB
subtask2_18.txt AC 73 ms 14820 KiB
subtask2_19.txt AC 74 ms 14820 KiB
subtask2_20.txt AC 83 ms 29156 KiB