-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path379.hs
More file actions
29 lines (23 loc) · 782 Bytes
/
379.hs
File metadata and controls
29 lines (23 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# OPTIONS_GHC -O3 #-}
{-# LANGUAGE BangPatterns #-}
import Control.Applicative
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Array
import Data.Array.Base (unsafeAt)
solve :: [Int] -> Bool
solve xs = let !top = length xs - 1
arr = listArray (0,top) xs
vs = map (\idx -> idx+1 == (arr `unsafeAt` ((arr `unsafeAt` idx) - 1))) [0..top]
in and vs
parse :: B.ByteString -> [Int]
parse = map (takeInt . B.readInt) . B.words
takeInt :: Maybe (t, t1) -> t
takeInt (Just (!x,y)) = x
pp True = "ambiguous"
pp False = "not ambiguous"
getPerm [] = []
getPerm (_:x:xs) = x: getPerm xs
main = do
ls <- getPerm . takeWhile (/= B.pack "0") . B.lines <$> B.getContents
mapM_ (putStrLn . pp . solve . parse) ls
return ()