ログインしてください。
提出 #37417172
ソースコード 拡げる
{-# LANGUAGE MultiParamTypeClasses #-}
module Main where
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import Data.Maybe ( fromJust )
main :: IO ()
main = B.interact (encode . solve . decode)
decode :: B.ByteString -> [[String]]
decode = map (map B.unpack . B.words) . B.lines
readInt :: B.ByteString -> Int
readInt = fst . fromJust . B.readInt
encode :: [[Int]] -> B.ByteString
encode = B.unlines . map (B.unwords . map showInt)
showInt :: Int -> B.ByteString
showInt = B.pack . show
solve :: [[String]] -> [[Int]]
solve dss = case dss of
[s]:[t]:_ -> [[ length (lcs s t)] ]
lcs :: Eq a => [a] -> [a] -> [a]
lcs xs = fst . head . foldr phi row0
where
row0 = replicate (length xs + 1) nil
phi y row = foldr (step y) [nil] (zip3 xs row (tail row))
step y (x,cs1,cs2) row
| x == y = (x `cons` cs2) : row
| otherwise = longer cs1 (head row) : row
longer :: Sized a -> Sized a -> Sized a
longer xs@(_,m) ys@(_,n)
| m < n = ys
| otherwise = xs
type Sized a = ([a], Int)
nil :: Sized a
nil = ([],0)
cons :: a -> Sized a -> Sized a
cons x (xs,n) = (x:xs, succ n)
提出情報
| 提出日時 | |
|---|---|
| 問題 | A20 - LCS |
| ユーザ | nobsun |
| 言語 | Haskell (GHC 8.8.3) |
| 得点 | 1000 |
| コード長 | 1172 Byte |
| 結果 | AC |
| 実行時間 | 765 ms |
| メモリ | 224532 KiB |
コンパイルエラー
Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 1000 / 1000 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, sample_01.txt, sample_02.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| in01.txt | AC | 6 ms | 3476 KiB |
| in02.txt | AC | 2 ms | 3452 KiB |
| in03.txt | AC | 2 ms | 3472 KiB |
| in04.txt | AC | 2 ms | 3468 KiB |
| in05.txt | AC | 760 ms | 219376 KiB |
| in06.txt | AC | 757 ms | 224532 KiB |
| in07.txt | AC | 765 ms | 221508 KiB |
| in08.txt | AC | 656 ms | 119060 KiB |
| in09.txt | AC | 667 ms | 117040 KiB |
| in10.txt | AC | 665 ms | 119084 KiB |
| in11.txt | AC | 436 ms | 144660 KiB |
| in12.txt | AC | 218 ms | 75028 KiB |
| in13.txt | AC | 56 ms | 19464 KiB |
| in14.txt | AC | 4 ms | 4616 KiB |
| in15.txt | AC | 216 ms | 46356 KiB |
| in16.txt | AC | 71 ms | 14612 KiB |
| in17.txt | AC | 14 ms | 5932 KiB |
| in18.txt | AC | 2 ms | 3772 KiB |
| in19.txt | AC | 355 ms | 134464 KiB |
| in20.txt | AC | 613 ms | 157984 KiB |
| in21.txt | AC | 67 ms | 15808 KiB |
| sample_01.txt | AC | 3 ms | 3468 KiB |
| sample_02.txt | AC | 2 ms | 3496 KiB |