Created
October 17, 2012 13:27
-
-
Save smihica/3905525 to your computer and use it in GitHub Desktop.
オフラインリアルタイムどう書く第四回の参考問題 解答(Arc) ref: http://qiita.com/items/d38561f842913ddb3734
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(= x 5 n (- (* x x) 1)) | |
(def get-tbl bans | |
(let o (map [rem nil `(,(if (< (mod _ x) (- x 1)) (+ _ 1)) ;right | |
,(if (< (/ _ x) (- x 1)) (+ _ x)) ; bottom | |
,(if (> (mod _ x) 0) (- _ 1)) ;left | |
,(if (>= (/ _ x) 1) (- _ x)))] ; about | |
(range 0 n)) | |
(aif (car bans) | |
(each x it (= (o (x 0)) (rem (x 1) (o (x 0))) | |
(o (x 1)) (rem (x 0) (o (x 1)))))) o)) | |
(def count (i h tbl) | |
(if (is i n) 1 | |
(apply + (mappend [if (no (mem _ h)) `(,(count _ (cons i h) tbl))] | |
(tbl i))))) | |
(def solve (xs) | |
(let ban-syms (read (+ "(" xs ")")) | |
(let bans (map [map [- (coerce _ 'int) 97] | |
(coerce (coerce _ 'string) 'cons)] ban-syms) | |
(count 0 nil (get-tbl bans))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(solve "") ;; -> 8512 | |
(solve "af") ;; -> 4256 | |
(solve "xy") ;; -> 4256 | |
(solve "pq qr rs st di in ns sx") ;; -> 184 | |
(solve "af pq qr rs st di in ns sx") ;; -> 92 | |
(solve "bg ch di ij no st") ;; -> 185 | |
(solve "bc af ch di no kp mr ns ot pu rs") ;; -> 16 | |
(solve "ab af") ;; -> 0 | |
(solve "ty xy") ;; -> 0 | |
(solve "bg ch ej gh lm lq mr ot rs sx") ;; -> 11 | |
(solve "ty ch hi mn kp mr rs sx") ;; -> 18 | |
(solve "xy ch hi mn kp mr rs sx") ;; -> 32 | |
(solve "ch hi mn kp mr rs sx") ;; -> 50 | |
(solve "ab cd uv wx") ;; -> 621 | |
(solve "gh mn st lq qr") ;; -> 685 | |
(solve "fg gl lm mr rs") ;; -> 171 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment