結果
問題 |
No.22 括弧の対応
|
ユーザー |
|
提出日時 | 2016-07-28 21:48:23 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 519 bytes |
コンパイル時間 | 1,773 ms |
コンパイル使用メモリ | 171,520 KB |
実行使用メモリ | 5,760 KB |
最終ジャッジ日時 | 2024-07-20 07:14:20 |
合計ジャッジ時間 | 2,509 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 import Control.Monad import Data.List import Data.Maybe paren :: [Int] -> [(Char, Int)] -> [(Int, Int)] paren (s : ss) [] = [] paren (s : ss) ((x, i) : xs) | x == '(' = paren (i : s : ss) xs | otherwise = (s, i) : paren ss xs solve n k s = if a == k then b else a where (a, b) = fromJust . find (\ (a, b) -> a == k || b == k) . paren [-1] $ zip s [1 .. n] main = do [n, k] <- map read . words <$> getLine :: IO [Int] s <- getLine print $ solve n k s