Submission #5932821
Source Code Expand
;; -*- 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 (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)
;; 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 ()
(let* ((n (read))
(ga (read))
(sa (read))
(ba (read))
(gb (read))
(sb (read))
(bb (read))
(res n))
(declare (uint16 n ga sa ba gb sb bb))
(when (and (>= ga gb) (>= sa sb) (>= ba bb))
(rotatef ga gb)
(rotatef sa sb)
(rotatef ba bb))
(when (and (>= ga gb) (<= sa sb) (>= ba bb))
(rotatef sa ga)
(rotatef sb gb))
(when (and (>= ga gb) (>= sa sb) (<= ba bb))
(rotatef ba ga)
(rotatef bb gb))
(when (and (>= ga gb) (<= sa sb) (<= ba bb))
(rotatef ga ba)
(rotatef gb bb))
(when (and (<= ga gb) (>= sa sb) (<= ba bb))
(rotatef sa ba)
(rotatef sb bb))
(cond ((and (<= ga gb) (<= sa sb) (<= ba bb))
(loop for gold from 0 to 5000
do (loop for silver from 0 to 5000
for mid-nuts = (- n (+ (* gold ga) (* silver sa)))
when (>= mid-nuts 0)
do (multiple-value-bind (bronze rest-nuts) (floor mid-nuts ba)
(let ((final-nuts (+ (* gold gb)
(* silver sb)
(* bronze bb)
rest-nuts)))
(setf res (max res final-nuts)))))))
((or (and (<= ga gb) (>= sa sb) (>= ba bb)))
(let ((mid-nuts (+ (mod n ga) (* gb (floor n ga)))))
(loop for silver from 0
for rest-nuts = (- mid-nuts (* silver sb))
while (>= rest-nuts 0)
do (let* ((bronze (floor rest-nuts bb))
(final-nuts (+ (* silver sa)
(* bronze ba)
(mod rest-nuts bb))))
(setf res (max res final-nuts))))))
((or (and (<= ga gb) (<= sa sb) (>= ba bb)))
(let ((mid-nuts (loop with res = 0
for gold from 0
for rest-nuts = (- n (* gold ga))
while (>= rest-nuts 0)
do (let ((silver (floor rest-nuts sa)))
(setf res (max res (+ (* gold gb)
(* silver sb)
(mod rest-nuts sa)))))
finally (return res))))
(setf res (max res (+ (mod mid-nuts bb) (* ba (floor mid-nuts bb)))))))
(t (error "Huh?")))
(println res)))
#-swank(main)
;; For Test
#+swank
(defun io-equal (in-string out-string &optional (func #'main))
"Passes IN-STRING to *STANDARD-INPUT*, executes FUNC, and checks the string
output to *STANDARD-OUTPUT* is equal to OUT-STRING."
(labels ((ensure-last-lf (s)
(if (and (> (length s) 0)
(eql (char s (- (length s) 1)) #\Linefeed))
s
(uiop:strcat s uiop:+lf+))))
(equal (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 func)))))))
#+swank
(defun get-clipbrd ()
(with-output-to-string (out)
(run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))
#+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*))
(let ((*standard-output* out))
(etypecase thing
(null ; Runs #'MAIN with the string on clipboard
(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 ; Runs #'MAIN with the string in a text file
(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 "23
1 1 1
2 1 1
"
"46
")))
Submission Info
| Submission Time | |
|---|---|
| Task | D - Squirrel Merchant |
| User | sansaqua |
| Language | Common Lisp (SBCL 1.1.14) |
| Score | 600 |
| Code Size | 6081 Byte |
| Status | AC |
| Exec Time | 282 ms |
| Memory | 22628 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt |
| All | 00.txt, 41.txt, 42.txt, 45.txt, 50.txt, 55.txt, 60.txt, 65.txt, 70.txt, 75.txt, 80.txt, 81.txt, 82.txt, 83.txt, 84.txt, 85.txt, 86.txt, 87.txt, 88.txt, 89.txt, 90.txt, 91.txt, 92.txt, 93.txt, 94.txt, 95.txt, a01.txt, a02.txt, a03.txt, a04.txt, a05.txt, a06.txt, a07.txt, a08.txt, a09.txt, a10.txt, a11.txt, a12.txt, a13.txt, a14.txt, a15.txt, a16.txt, a17.txt, a18.txt, a19.txt, a20.txt, a21.txt, a22.txt, a23.txt, a24.txt, a25.txt, a26.txt, a27.txt, a28.txt, a29.txt, a30.txt, a31.txt, a32.txt, a33.txt, a34.txt, a35.txt, a36.txt, a37.txt, a38.txt, a39.txt, a40.txt, s1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00.txt | AC | 184 ms | 22628 KiB |
| 41.txt | AC | 89 ms | 12768 KiB |
| 42.txt | AC | 89 ms | 12776 KiB |
| 45.txt | AC | 54 ms | 12772 KiB |
| 50.txt | AC | 54 ms | 12772 KiB |
| 55.txt | AC | 54 ms | 12772 KiB |
| 60.txt | AC | 54 ms | 12772 KiB |
| 65.txt | AC | 54 ms | 12768 KiB |
| 70.txt | AC | 56 ms | 12776 KiB |
| 75.txt | AC | 54 ms | 12776 KiB |
| 80.txt | AC | 89 ms | 12768 KiB |
| 81.txt | AC | 93 ms | 12768 KiB |
| 82.txt | AC | 95 ms | 12772 KiB |
| 83.txt | AC | 54 ms | 12768 KiB |
| 84.txt | AC | 54 ms | 12768 KiB |
| 85.txt | AC | 180 ms | 12772 KiB |
| 86.txt | AC | 55 ms | 12772 KiB |
| 87.txt | AC | 141 ms | 12776 KiB |
| 88.txt | AC | 55 ms | 12768 KiB |
| 89.txt | AC | 54 ms | 12772 KiB |
| 90.txt | AC | 149 ms | 12772 KiB |
| 91.txt | AC | 89 ms | 12772 KiB |
| 92.txt | AC | 89 ms | 12772 KiB |
| 93.txt | AC | 92 ms | 12772 KiB |
| 94.txt | AC | 55 ms | 12772 KiB |
| 95.txt | AC | 54 ms | 12772 KiB |
| a01.txt | AC | 59 ms | 12772 KiB |
| a02.txt | AC | 58 ms | 12776 KiB |
| a03.txt | AC | 58 ms | 12772 KiB |
| a04.txt | AC | 59 ms | 12776 KiB |
| a05.txt | AC | 56 ms | 12768 KiB |
| a06.txt | AC | 55 ms | 12772 KiB |
| a07.txt | AC | 55 ms | 12772 KiB |
| a08.txt | AC | 55 ms | 12768 KiB |
| a09.txt | AC | 68 ms | 12772 KiB |
| a10.txt | AC | 68 ms | 12772 KiB |
| a11.txt | AC | 56 ms | 12772 KiB |
| a12.txt | AC | 58 ms | 12772 KiB |
| a13.txt | AC | 282 ms | 12772 KiB |
| a14.txt | AC | 104 ms | 12768 KiB |
| a15.txt | AC | 153 ms | 12776 KiB |
| a16.txt | AC | 121 ms | 12772 KiB |
| a17.txt | AC | 96 ms | 12772 KiB |
| a18.txt | AC | 90 ms | 12772 KiB |
| a19.txt | AC | 92 ms | 12772 KiB |
| a20.txt | AC | 282 ms | 12772 KiB |
| a21.txt | AC | 90 ms | 12768 KiB |
| a22.txt | AC | 102 ms | 12772 KiB |
| a23.txt | AC | 92 ms | 12776 KiB |
| a24.txt | AC | 90 ms | 12772 KiB |
| a25.txt | AC | 89 ms | 12772 KiB |
| a26.txt | AC | 89 ms | 12776 KiB |
| a27.txt | AC | 91 ms | 12772 KiB |
| a28.txt | AC | 89 ms | 12772 KiB |
| a29.txt | AC | 90 ms | 12772 KiB |
| a30.txt | AC | 89 ms | 12772 KiB |
| a31.txt | AC | 89 ms | 12768 KiB |
| a32.txt | AC | 92 ms | 12768 KiB |
| a33.txt | AC | 89 ms | 12768 KiB |
| a34.txt | AC | 90 ms | 12772 KiB |
| a35.txt | AC | 89 ms | 12772 KiB |
| a36.txt | AC | 89 ms | 12772 KiB |
| a37.txt | AC | 90 ms | 12772 KiB |
| a38.txt | AC | 89 ms | 12772 KiB |
| a39.txt | AC | 89 ms | 12776 KiB |
| a40.txt | AC | 89 ms | 12772 KiB |
| s1.txt | AC | 89 ms | 12772 KiB |