Submission #5416948


Source Code Expand

#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "32MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
;; -*- 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 (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
  (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 parse-number (s pos)
  (declare (simple-base-string s))
  (let ((res (make-array 0 :fill-pointer 0 :element-type 'base-char)))
    (loop for i from pos
          while (and (< i (length s))
                     (digit-char-p (schar s i)))
          do (vector-push-extend (schar s i) res))
    (values res (+ pos (length res)))))

(defun parse-args (s pos)
  (multiple-value-bind (expr new-pos) (parse-expr s pos)
    (if (char= #\, (schar s new-pos))
        (multiple-value-bind (args last-pos) (parse-args s (+ 1 new-pos))
          (values (cons expr args) last-pos))
        (values (list expr) new-pos))))

(defun parse-expr (s pos)
  (macrolet ((frob-op (op)
               `(progn
                  (assert (char= #\( (schar s (+ pos 1))))
                  (multiple-value-bind (args new-pos) (parse-args s (+ pos 2))
                    (assert (char= #\) (schar s new-pos)))
                    (values (cons ',op args) (+ new-pos 1))))))
    (case (schar s pos)
      (#\+ (frob-op +))
      (#\- (frob-op -))
      (#\* (frob-op *))
      (#\/ (frob-op /))
      ((#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
       (parse-number s pos)))))

(defun print-expr (ast)
  (typecase ast
    (string (write-string ast))
    (list (let ((op (car ast))
                (args (cdr ast)))
            (write-char #\()
            (let ((init t))
              (loop for arg in args
                    do (if init
                           (setq init nil)
                           (princ op))
                       (print-expr arg)))
            (write-char #\))))))

(defun main ()
  (let* ((s (coerce (read-line) 'simple-base-string)))
    (print-expr (parse-expr s 0))
    (terpri)))

#-swank(main)

Submission Info

Submission Time
Task B - 異世界数式
User sansaqua
Language Common Lisp (SBCL 1.1.14)
Score 400
Code Size 3446 Byte
Status AC
Exec Time 125 ms
Memory 29880 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
Case Name Status Exec Time Memory
01.txt AC 81 ms 21556 KiB
02.txt AC 78 ms 17596 KiB
03.txt AC 125 ms 29880 KiB
04.txt AC 99 ms 21560 KiB
05.txt AC 101 ms 21560 KiB
06.txt AC 100 ms 21560 KiB
07.txt AC 99 ms 21560 KiB
08.txt AC 98 ms 21556 KiB
09.txt AC 98 ms 21560 KiB
10.txt AC 94 ms 21556 KiB
11.txt AC 89 ms 19516 KiB
12.txt AC 84 ms 19644 KiB
13.txt AC 82 ms 17588 KiB
14.txt AC 79 ms 17588 KiB
sample_01.txt AC 63 ms 15420 KiB
sample_02.txt AC 64 ms 15416 KiB
sample_03.txt AC 64 ms 15416 KiB
sample_04.txt AC 64 ms 15412 KiB
sample_05.txt AC 63 ms 15416 KiB