結果

問題 No.592 括弧の対応 (2)
ユーザー pekempeypekempey
提出日時 2017-11-11 18:08:12
言語 Haskell
(9.8.2)
結果
AC  
実行時間 372 ms / 5,000 ms
コード長 347 bytes
コンパイル時間 9,892 ms
コンパイル使用メモリ 162,476 KB
実行使用メモリ 52,956 KB
最終ジャッジ日時 2023-08-16 07:43:48
合計ジャッジ時間 3,746 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,636 KB
testcase_01 AC 333 ms
49,880 KB
testcase_02 AC 372 ms
52,956 KB
testcase_03 AC 283 ms
48,844 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

ソースコード

diff #

import Data.List
import Control.Monad

main = getLine >> getLine >>= mapM_ print . solve

solve :: String -> [Int]
solve = map snd . sort . snd . foldl' f ([], []) . zip [1..]
  where
    f :: ([Int], [(Int, Int)]) -> (Int, Char) -> ([Int], [(Int, Int)])
    f (xs, ans) (i, '(') = (i:xs, ans)
    f (x:xs, ans) (i, ')') = (xs, (x, i):(i, x):ans)
0