Last active
December 14, 2023 03:51
-
-
Save nobsun/0db256f6fdb4ecc084ae35efbeebf385 to your computer and use it in GitHub Desktop.
This file contains 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
{-# LANGUAGE GHC2021 #-} | |
{-# LANGUAGE ImportQualifiedPost #-} | |
{-# LANGUAGE LexicalNegation #-} | |
{-# LANGUAGE LambdaCase, MultiWayIf #-} | |
{-# LANGUAGE NPlusKPatterns #-} | |
{-# LANGUAGE NoStarIsType, TypeFamilyDependencies, TypeInType #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE OverloadedRecordDot, NoFieldSelectors, DuplicateRecordFields #-} | |
module Main where | |
import qualified Data.ByteString.Char8 as B | |
import Data.Maybe ( fromJust ) | |
import Data.Array | |
import Data.List | |
main :: IO () | |
main = B.interact (encode . wrap solve . decode) | |
wrap :: Solve -> ([[Int]] -> [[Int]]) | |
wrap solv dss = case dss of | |
[m,n]:as:_ -> [[solv m n as]] | |
_ -> error "invalid input form" | |
type Solve = Int -> Int -> [Int] -> Int | |
solve :: Solve | |
solve _m _n _as = undefined | |
-- | |
class InterfaceForOJS a where | |
readB :: B.ByteString -> a | |
readBs :: B.ByteString -> [a] | |
readBs = Prelude.map readB . B.words | |
decode :: B.ByteString -> [[a]] | |
decode = Prelude.map readBs . B.lines | |
showB :: a -> B.ByteString | |
showBs :: [a] -> B.ByteString | |
showBs = B.unwords . Prelude.map showB | |
encode :: [[a]] -> B.ByteString | |
encode = B.unlines . Prelude.map showBs | |
instance InterfaceForOJS B.ByteString where | |
readB = id | |
readBs = B.words | |
showB = id | |
showBs = B.unwords | |
instance InterfaceForOJS Int where | |
readB = Main.readInt | |
showB = Main.showInt | |
instance InterfaceForOJS String where | |
readB = readStr | |
showB = showStr | |
instance InterfaceForOJS Double where | |
readB = readDbl | |
showB = showDbl | |
instance InterfaceForOJS Char where | |
readB = B.head | |
showB = B.singleton | |
readBs = B.unpack | |
showBs = B.pack | |
readInt :: B.ByteString -> Int | |
readInt = fst . fromJust . B.readInt | |
showInt :: Int -> B.ByteString | |
showInt = B.pack . show | |
readStr :: B.ByteString -> String | |
readStr = B.unpack | |
showStr :: String -> B.ByteString | |
showStr = B.pack | |
readDbl :: B.ByteString -> Double | |
readDbl = read . B.unpack | |
showDbl :: Double -> B.ByteString | |
showDbl = B.pack . show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment