結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-10-22 20:17:48 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 519 bytes |
コンパイル時間 | 6,439 ms |
コンパイル使用メモリ | 174,340 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:04:34 |
合計ジャッジ時間 | 4,386 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Control.Applicative ((<$>)) getPair :: Int -> String -> Int getPair k s | s !! (k - 1) == '(' = getPair' 0 k 1 s | otherwise = getPair' 0 k (-1) s where getPair' n l d s | n == 0 && l /= k = if d < 0 then l + 1 else l - 1 | s !! (l - 1) == '(' = getPair' (n + 1) (l + d) d s | otherwise = getPair' (n - 1) (l + d) d s main :: IO () main = do (_ : k : _) <- map read . words <$> getLine s <- getLine print $ getPair k s