AtCoder Regular Contest 002

Submission #6892570

Source codeソースコード

;; -*- coding: utf-8 -*-
(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))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) 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 calc (s l1 l2 r1 r2)
  (declare #.OPT
           (simple-base-string s))
  (let ((n (length s))
        (res 0)
        (index 0))
    (declare (uint32 n res index))
    (loop
      (cond ((= index n)
             (return res))
            ((= index (- n 1))
             (incf index))
            ((or (and (char= l1 (aref s index))
                      (char= l2 (aref s (+ index 1))))
                 (and (char= r1 (aref s index))
                      (char= r2 (aref s (+ index 1)))))
             (incf index 2))
            (t (incf index)))
      (incf res))))

(defun main ()
  (let* ((n (read))
         (s (coerce (read-line) 'simple-base-string))
         (button '(#\A #\B #\X #\Y))
         (res n))
    (declare (uint32 res n))
    (dolist (l1 button)
      (dolist (l2 button)
        (dolist (r1 button)
          (dolist (r2 button)
            (setf res (min res (calc s l1 l2 r1 r2)))))))
    (println res)))

#-swank (main)

Submission

Task問題 C - コマンド入力
User nameユーザ名 sansaqua
Created time投稿日時
Language言語 Common Lisp (SBCL 1.1.14)
Status状態 AC
Score得点 100
Source lengthソースコード長 2295 Byte
File nameファイル名
Exec time実行時間 73 ms
Memory usageメモリ使用量 11104 KB

Test case

Set

Set name Score得点 / Max score Cases
All 100 / 100 00_retmax.txt,00_retmin.txt,00_sample_00.txt,00_sample_01.txt,00_sample_02.txt,01_rnd_00.txt,01_rnd_01.txt,01_rnd_02.txt,01_rnd_03.txt,01_rnd_04.txt,01_rnd_05.txt,01_rnd_06.txt,01_rnd_07.txt,01_rnd_08.txt,01_rnd_09.txt,01_rnd_10.txt,01_rnd_11.txt,01_rnd_12.txt,01_rnd_13.txt,01_rnd_14.txt,01_rnd_15.txt,01_rnd_16.txt,01_rnd_17.txt,01_rnd_18.txt,01_rnd_19.txt,02_twothree_00.txt,02_twothree_01.txt,02_twothree_02.txt,02_twothree_03.txt,02_twothree_04.txt,02_twothree_05.txt,02_twothree_06.txt,02_twothree_07.txt,02_twothree_08.txt,02_twothree_09.txt,02_twothree_10.txt,02_twothree_11.txt,02_twothree_12.txt,02_twothree_13.txt,02_twothree_14.txt,02_twothree_15.txt,02_twothree_16.txt,02_twothree_17.txt,02_twothree_18.txt,02_twothree_19.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_retmax.txt AC 73 ms 11104 KB
00_retmin.txt AC 36 ms 8552 KB
00_sample_00.txt AC 36 ms 8552 KB
00_sample_01.txt AC 36 ms 8552 KB
00_sample_02.txt AC 36 ms 8548 KB
01_rnd_00.txt AC 38 ms 8548 KB
01_rnd_01.txt AC 37 ms 8548 KB
01_rnd_02.txt AC 37 ms 8548 KB
01_rnd_03.txt AC 37 ms 8544 KB
01_rnd_04.txt AC 37 ms 8548 KB
01_rnd_05.txt AC 37 ms 8552 KB
01_rnd_06.txt AC 37 ms 8548 KB
01_rnd_07.txt AC 37 ms 8544 KB
01_rnd_08.txt AC 37 ms 8548 KB
01_rnd_09.txt AC 37 ms 8548 KB
01_rnd_10.txt AC 37 ms 8548 KB
01_rnd_11.txt AC 37 ms 8548 KB
01_rnd_12.txt AC 37 ms 8544 KB
01_rnd_13.txt AC 37 ms 8548 KB
01_rnd_14.txt AC 37 ms 8548 KB
01_rnd_15.txt AC 37 ms 8552 KB
01_rnd_16.txt AC 37 ms 8544 KB
01_rnd_17.txt AC 37 ms 8548 KB
01_rnd_18.txt AC 37 ms 8548 KB
01_rnd_19.txt AC 37 ms 8548 KB
02_twothree_00.txt AC 37 ms 8548 KB
02_twothree_01.txt AC 36 ms 8552 KB
02_twothree_02.txt AC 37 ms 8552 KB
02_twothree_03.txt AC 37 ms 8548 KB
02_twothree_04.txt AC 37 ms 8544 KB
02_twothree_05.txt AC 37 ms 8548 KB
02_twothree_06.txt AC 36 ms 8548 KB
02_twothree_07.txt AC 36 ms 8544 KB
02_twothree_08.txt AC 36 ms 8548 KB
02_twothree_09.txt AC 36 ms 8548 KB
02_twothree_10.txt AC 36 ms 8548 KB
02_twothree_11.txt AC 37 ms 8548 KB
02_twothree_12.txt AC 37 ms 8552 KB
02_twothree_13.txt AC 36 ms 8548 KB
02_twothree_14.txt AC 36 ms 8548 KB
02_twothree_15.txt AC 36 ms 8548 KB
02_twothree_16.txt AC 36 ms 8544 KB
02_twothree_17.txt AC 37 ms 8544 KB
02_twothree_18.txt AC 36 ms 8548 KB
02_twothree_19.txt AC 37 ms 8544 KB