結果

問題 No.52 よくある文字列の問題
ユーザー poapoapoapoa
提出日時 2020-09-03 14:20:35
言語 Haskell
(9.8.2)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 465 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 162,512 KB
実行使用メモリ 8,512 KB
最終ジャッジ日時 2023-08-15 10:55:21
合計ジャッジ時間 2,885 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,328 KB
testcase_01 AC 3 ms
7,080 KB
testcase_02 AC 4 ms
8,144 KB
testcase_03 AC 2 ms
7,192 KB
testcase_04 AC 4 ms
8,512 KB
testcase_05 AC 4 ms
8,316 KB
testcase_06 AC 4 ms
8,376 KB
testcase_07 AC 3 ms
7,760 KB
testcase_08 AC 3 ms
7,292 KB
testcase_09 AC 3 ms
7,204 KB
testcase_10 AC 3 ms
7,196 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           Data.Set (Set)
import qualified Data.Set as Set

main :: IO ()
main = do
  s <- getLine
  print $ solve (length s) s

solve :: Int -> String -> Int
solve n k = Set.size $ go 0 (n - 1) "" Set.empty 
  where
    go :: Int -> Int -> String -> Set String -> Set String
    go l r s set
      | l > r = Set.insert s set
      | otherwise
      = Set.union (go (l + 1) r (s ++ [k !! l])  set) (go l (r - 1) (s ++ [k !! r]) set)
0