All pastes #496195 Raw Edit

reconstruct permutat

public text v1 · immutable
·published 2007-05-19 03:15 UTC
rendered paste body
;; http://acm.mipt.ru/judge/problems.pl?problem=061
;; rmathews AT gmail DOT com

(defun reconstruct (n list)
  (let ((result (loop for i from 1 to n
                      collect -1)))
    (dotimes (i n)
      (let ((pos (position 0 list)))
        (when (null pos)
          (return-from reconstruct "-1"))
        (dotimes (i (1+ pos))
          (setf (nth i list) (1- (nth i list))))
        (setf (nth pos result) (- n i))))
    result))