-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1454C.hs
More file actions
34 lines (26 loc) · 801 Bytes
/
1454C.hs
File metadata and controls
34 lines (26 loc) · 801 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
30
31
32
33
34
import Data.Foldable
import Data.List
main = do
cas <- read <$> getLine
mapM_ solveOneCase [1 .. cas]
solveOneCase _ = getLine >> getLine >>= print . solve . map read . words
solve :: [Int] -> Int
solve xs = minimum ans
where
distinct = map head $ group xs
ans = map appearTime . group . sort $ distinct
appearTime zs@(z:z') = length zs + 1 - theTwoEnd (head distinct) z - theTwoEnd (last distinct) z
theTwoEnd x y = if x == y then 1 else 0
{--
import Control.Monad -- for replicateM_
import Data.List -- for sort
solve :: Int -> [Int]
solve n = tail $ [1..n] ++ [1]
listToString = unwords . map show
deal :: IO()
deal = do
a <- readLn
putStrLn $ listToString $ solve a
main :: IO()
main = getLine >>= flip replicateM_ deal . read
--}