Submission #10970550


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
           ;; enclose the form with VALUES to avoid being captured by LOOP macro
           #\# #\> (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
;;;

(defun main ()
  (declare #.OPT)
  (labels ((no () (write-line "No") (return-from main))
           (yes () (write-line "Yes") (return-from main)))
    (let* ((s (coerce (read-line) 'simple-base-string))
           (n (length s))
           (dp (make-array 7 :element-type 'uint8 :initial-element 0)))
      (unless (and (zerop (mod n 6))
                   (= (count #\t s)
                      (* 2 (count #\i s))
                      (* 2 (count #\e s))
                      (* 2 (count #\c s))
                      (* 2 (count #\h s))
                      (* 2 (floor n 6))))
        (no))
      (setf (aref dp 0) (floor n 6))
      (sb-int:named-let dfs ((pos 0))
        (declare (uint8 pos))
        (labels ((call (x)
                   (when (> (aref dp x) 0)
                     (decf (aref dp x))
                     (incf (aref dp (+ x 1)))
                     (dfs (+ pos 1))
                     (decf (aref dp (+ x 1)))
                     (incf (aref dp x)))))
          (if (= pos n)
              (yes)
              (ecase (aref s pos)
                (#\t (call 0) (call 2))
                (#\i (call 1))
                (#\e (call 3))
                (#\c (call 4))
                (#\h (call 5))))))
      (no))))

#-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 "titech
"
    "Yes
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "tititechtech
"
    "Yes
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "titecg
"
    "No
"))
  (it.bese.fiveam:is
   (common-lisp-user::io-equal "tttiiittteeeccchhh
"
    "Yes
")))

Submission Info

Submission Time
Task G - titech分離
User sansaqua
Language Common Lisp (SBCL 1.1.14)
Score 100
Code Size 5089 Byte
Status AC
Exec Time 205 ms
Memory 15204 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 4
AC × 59
Set Name Test Cases
Sample 00-example1.txt, 00-example2.txt, 00-example3.txt, 00-example4.txt
All 00-example1.txt, 00-example2.txt, 00-example3.txt, 00-example4.txt, 01-hand00.txt, 01-hand01.txt, 01-hand02.txt, 01-hand03.txt, 01-hand04.txt, 01-hand05.txt, 01-hand06.txt, 01-hand07.txt, 01-hand08.txt, 01-hand09.txt, 10-randomA00.txt, 10-randomA01.txt, 10-randomA02.txt, 10-randomA03.txt, 10-randomA04.txt, 10-randomA05.txt, 10-randomA06.txt, 10-randomA07.txt, 10-randomA08.txt, 10-randomA09.txt, 10-randomA10.txt, 10-randomA11.txt, 10-randomA12.txt, 10-randomA13.txt, 10-randomA14.txt, 20-randomB00.txt, 20-randomB01.txt, 20-randomB02.txt, 20-randomB03.txt, 20-randomB04.txt, 20-randomB05.txt, 20-randomB06.txt, 20-randomB07.txt, 20-randomB08.txt, 20-randomB09.txt, 20-randomB10.txt, 20-randomB11.txt, 20-randomB12.txt, 20-randomB13.txt, 20-randomB14.txt, 25-randomC00.txt, 25-randomC01.txt, 25-randomC02.txt, 25-randomC03.txt, 25-randomC04.txt, 25-randomC05.txt, 25-randomC06.txt, 25-randomC07.txt, 25-randomC08.txt, 25-randomC09.txt, 30-special00.txt, 30-special01.txt, 30-special02.txt, 30-special03.txt, 30-special04.txt
Case Name Status Exec Time Memory
00-example1.txt AC 112 ms 15204 KiB
00-example2.txt AC 52 ms 10596 KiB
00-example3.txt AC 52 ms 10600 KiB
00-example4.txt AC 52 ms 10596 KiB
01-hand00.txt AC 52 ms 10592 KiB
01-hand01.txt AC 52 ms 10596 KiB
01-hand02.txt AC 52 ms 10596 KiB
01-hand03.txt AC 52 ms 10596 KiB
01-hand04.txt AC 52 ms 10592 KiB
01-hand05.txt AC 52 ms 10592 KiB
01-hand06.txt AC 52 ms 10596 KiB
01-hand07.txt AC 53 ms 10592 KiB
01-hand08.txt AC 53 ms 10596 KiB
01-hand09.txt AC 52 ms 10592 KiB
10-randomA00.txt AC 65 ms 10592 KiB
10-randomA01.txt AC 52 ms 10596 KiB
10-randomA02.txt AC 52 ms 10592 KiB
10-randomA03.txt AC 52 ms 10596 KiB
10-randomA04.txt AC 52 ms 10596 KiB
10-randomA05.txt AC 69 ms 10596 KiB
10-randomA06.txt AC 52 ms 10596 KiB
10-randomA07.txt AC 66 ms 10596 KiB
10-randomA08.txt AC 205 ms 10592 KiB
10-randomA09.txt AC 52 ms 10596 KiB
10-randomA10.txt AC 52 ms 10600 KiB
10-randomA11.txt AC 52 ms 10600 KiB
10-randomA12.txt AC 52 ms 10600 KiB
10-randomA13.txt AC 52 ms 10592 KiB
10-randomA14.txt AC 52 ms 10596 KiB
20-randomB00.txt AC 52 ms 10600 KiB
20-randomB01.txt AC 52 ms 10596 KiB
20-randomB02.txt AC 52 ms 10596 KiB
20-randomB03.txt AC 52 ms 10600 KiB
20-randomB04.txt AC 52 ms 10596 KiB
20-randomB05.txt AC 55 ms 10600 KiB
20-randomB06.txt AC 52 ms 10596 KiB
20-randomB07.txt AC 52 ms 10600 KiB
20-randomB08.txt AC 52 ms 10596 KiB
20-randomB09.txt AC 55 ms 10600 KiB
20-randomB10.txt AC 53 ms 10596 KiB
20-randomB11.txt AC 52 ms 10592 KiB
20-randomB12.txt AC 52 ms 10592 KiB
20-randomB13.txt AC 66 ms 10600 KiB
20-randomB14.txt AC 52 ms 10592 KiB
25-randomC00.txt AC 52 ms 10600 KiB
25-randomC01.txt AC 52 ms 10596 KiB
25-randomC02.txt AC 52 ms 10596 KiB
25-randomC03.txt AC 53 ms 10596 KiB
25-randomC04.txt AC 52 ms 10596 KiB
25-randomC05.txt AC 52 ms 10596 KiB
25-randomC06.txt AC 53 ms 10596 KiB
25-randomC07.txt AC 52 ms 10600 KiB
25-randomC08.txt AC 52 ms 10596 KiB
25-randomC09.txt AC 52 ms 10596 KiB
30-special00.txt AC 52 ms 10600 KiB
30-special01.txt AC 52 ms 10596 KiB
30-special02.txt AC 52 ms 10600 KiB
30-special03.txt AC 52 ms 10600 KiB
30-special04.txt AC 52 ms 10600 KiB