結果
問題 | No.225 文字列変更(medium) |
ユーザー | こまる |
提出日時 | 2020-10-13 19:55:46 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 22 ms / 5,000 ms |
コード長 | 1,744 bytes |
コンパイル時間 | 1,224 ms |
コンパイル使用メモリ | 184,372 KB |
実行使用メモリ | 17,456 KB |
最終ジャッジ日時 | 2023-09-28 00:16:18 |
合計ジャッジ時間 | 2,732 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
13,596 KB |
testcase_01 | AC | 21 ms
15,260 KB |
testcase_02 | AC | 2 ms
6,496 KB |
testcase_03 | AC | 2 ms
6,528 KB |
testcase_04 | AC | 2 ms
6,412 KB |
testcase_05 | AC | 2 ms
6,444 KB |
testcase_06 | AC | 2 ms
6,544 KB |
testcase_07 | AC | 3 ms
6,436 KB |
testcase_08 | AC | 2 ms
6,532 KB |
testcase_09 | AC | 3 ms
6,520 KB |
testcase_10 | AC | 2 ms
6,432 KB |
testcase_11 | AC | 2 ms
6,436 KB |
testcase_12 | AC | 22 ms
16,348 KB |
testcase_13 | AC | 22 ms
17,408 KB |
testcase_14 | AC | 22 ms
17,032 KB |
testcase_15 | AC | 22 ms
16,272 KB |
testcase_16 | AC | 22 ms
16,296 KB |
testcase_17 | AC | 22 ms
16,284 KB |
testcase_18 | AC | 21 ms
17,456 KB |
testcase_19 | AC | 22 ms
16,384 KB |
testcase_20 | AC | 22 ms
17,452 KB |
testcase_21 | AC | 22 ms
16,304 KB |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
{-# LANGUAGE BangPatterns #-} import Control.Monad.ST import Data.Bool import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Unboxed as VU import qualified Data.Vector.Unboxed.Mutable as VUM main :: IO () main = do getLine s <- VU.fromList <$> getLine t <- VU.fromList <$> getLine print $ levenshteinDistance s t stream :: Monad m => Int -> Int -> VFSM.Stream m Int stream !l !r = VFSM.Stream step l where step x | x < r = return $ VFSM.Yield x (x + 1) | otherwise = return $ VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] stream #-} rep :: Monad m => Int -> (Int -> m ()) -> m () rep n = flip VFSM.mapM_ (stream 0 n) {-# INLINE rep #-} rep' :: Monad m => Int -> (Int -> m ()) -> m () rep' n = flip VFSM.mapM_ (stream 0 (n + 1)) {-# INLINE rep' #-} rep1 :: Monad m => Int -> (Int -> m ()) -> m () rep1 n = flip VFSM.mapM_ (stream 1 n) {-# INLINE rep1 #-} rep1' :: Monad m => Int -> (Int -> m ()) -> m () rep1' n = flip VFSM.mapM_ (stream 1 (n + 1)) {-# INLINE rep1' #-} levenshteinDistance :: VU.Vector Char -> VU.Vector Char -> Int levenshteinDistance s t = runST $ do let !m = VU.length s let !n = VU.length t dp <- VUM.replicate ((m + 1) * (n + 1)) (1000000007 :: Int) rep' m $ \i -> VUM.unsafeWrite dp (i * (n + 1)) i rep' n $ \j -> VUM.unsafeWrite dp j j rep m $ \i -> rep n $ \j -> do item1 <- VUM.unsafeRead dp (i * (n + 1) + j) item2 <- VUM.unsafeRead dp (i * (n + 1) + (j + 1)) item3 <- VUM.unsafeRead dp ((i + 1) * (n + 1) + j) VUM.unsafeWrite dp ((i + 1) * (n + 1) + (j + 1)) (minimum [item1 + bool 0 1 (s VU.! i /= t VU.! j), item2 + 1, item3 + 1]) VUM.unsafeRead dp (m * (n + 1) + n)