結果

問題 No.22 括弧の対応
ユーザー kuuso1kuuso1
提出日時 2015-04-16 01:12:19
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 531 bytes
コンパイル時間 4,686 ms
コンパイル使用メモリ 173,824 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-07-20 06:59:45
合計ジャッジ時間 2,890 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,888 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:7:1: warning: [GHC-94817] [-Wtabs]
    Tab character found here, and in 8 further locations.
    Suggested fix: Please use spaces instead.
  |
7 |         [n,k] <- (map read . words) <$> getLine
  | ^^^^^^^^

Main.hs:16:12: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
16 |         in head res2
   |            ^^^^

Main.hs:21:12: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
21 |         | (head s) == '(' = x:(f (tail s) xs (x:ys))
   |            ^^^^

Main.hs:21:35: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
21 |         | (head s) == '(' = x:(f (tail s) xs (x:ys))
   |                                   ^^^^

Main.hs:22:29: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Data.List, but defined in GHC.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
   |
22 |         | otherwise       = head ys : (f (tail s) xs (tail ys))
   |                             ^^^^

Main.hs:22:43: warning: [GHC-63394] [-Wx-pa

ソースコード

diff #

import Control.Monad
import Control.Applicative
import Data.List

main ::IO()
main=do
	[n,k] <- (map read . words) <$> getLine
	s <- getLine 
	putStrLn $ show ( solve s k n )

solve :: String -> Int -> Int -> Int
solve s k n =
	let res = f s [1..n] []
	    trgt = res !! (k-1)
	    res2 = [snd x|x <- (zip res [1..n]),(fst x)==trgt, (snd x)/=k]
	in head res2

f:: String -> [Int] -> [Int] -> [Int] 
f "" _ _  = []
f s (x:xs) ys
	| (head s) == '(' = x:(f (tail s) xs (x:ys))
	| otherwise       = head ys : (f (tail s) xs (tail ys))
0