;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Fix check-pmov ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; variables ; 2d-lists (defparameter *row* 0) (defparameter *col* 0) (defparameter *map* nil) (defparameter *p-movs* nil) (defparameter *blacks* nil) (defparameter *stack* nil) (defparameter *ints* nil) (defparameter *cells* nil) ; functions (defun convert-to-int (c) (cond ((char= c #\ ) (push (parse-integer (coerce (reverse *stack*) 'string)) *ints*) (setf *stack* nil) ) (t (push c *stack*)) ) ) (defun input-row-col () (setf s (read-line)) (loop for c across s do (convert-to-int c) finally (push (parse-integer (coerce (reverse *stack*) 'string)) *ints*) ) (setf *ints* (reverse *ints*)) (setf *row* (car *ints*)) (setf *col* (cadr *ints*)) ) (defun create-blacks () ; Loop through the numbers the amount of ; times equal to the row. (loop for i from 0 to (1- *row*) do (setf s (read-line)) (loop for c across s for col from 0 to (1- (length s)) do (if (equal #\# c) (push (list i col) *blacks*)) ) ) (setf *blacks* (reverse *blacks*)) ) (defun create-p-movs () (setf initial-cell (car *blacks*)) (loop for b in *blacks* do (if (equal initial-cell '(0 0)) (setf *p-movs* *blacks*) (push (mapcar #'- b initial-cell) *p-movs*) ) ) ; Use the cdr of the list because ; the first element represents no move. (setf *p-movs* (cdr *p-movs*)) ) (defun input () (input-row-col) (create-blacks) ) ; When a black cell exists at the place obtained ; by parallel translation, ; ERACE a present cell and the corresponding element from blacks. ; p-mov: (row column) ; now: (row column) (defun b-check (p-mov now) (cond ; not black ((equal *cells* (remove-if (lambda (l) (equal l (mapcar #'+ p-mov now))) *cells*)) nil) ; now doesn't exist in blacks ((equal *cells* (remove-if (lambda (l) (equal l now)) *cells*)) nil) (t ; erase now (setf *cells* (remove-if (lambda (l) (equal l now)) *cells*)) (setf *cells* (remove-if (lambda (l) (equal l (mapcar #'+ p-mov now))) *cells*)) t) ) ) (defun check-pmov (p-mov) ; Make a copy to use since ; the contents of the list will be changed. (setf *cells* *blacks*) (loop for now in *cells* do ; The current cell has already been erased. (tagbody (cond ((equal *cells* (remove-if (lambda (l) (equal l now)) *cells*)) (go END)) ) (if (null (b-check p-mov now)) (return-from check-pmov nil)) (if (null *cells*) (return-from check-pmov t)) END ) ) nil ) (defun color () (input) ; initial check (cond ((or (oddp (length *blacks*)) (> (length *blacks* (* *row* *col*)))) (princ 'NO) (return-from color)) ) (create-p-movs) ; Test by each p-mov (loop for p-mov in *p-movs* do (cond ((check-pmov p-mov) (princ 'YES) (return-from color))) ) (princ 'NO) ) (defun n179 () (color) ) (n179)