結果

問題 No.380 悪の台本
ユーザー くれちーくれちー
提出日時 2017-02-14 17:11:12
言語 Haskell
(9.8.2)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 3,189 bytes
コンパイル時間 3,804 ms
コンパイル使用メモリ 177,024 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-24 14:55:22
合計ジャッジ時間 4,462 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 17 ms
7,936 KB
testcase_05 AC 20 ms
7,808 KB
testcase_06 AC 15 ms
7,936 KB
testcase_07 AC 23 ms
7,808 KB
testcase_08 AC 16 ms
10,880 KB
testcase_09 AC 14 ms
7,936 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:4:45: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, 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."
  |
4 | head' str = if length str == 0 then "" else head str
  |                                             ^^^^

Main.hs:7:47: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Prelude, 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."
  |
7 | tail' str = if length str == 0 then [""] else tail str
  |                                               ^^^^

Main.hs:16:56: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Prelude, 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."
   |
16 |     | ln <  lh = n `eqStr` take ln h || n `isInfixOf'` tail h
   |                                                        ^^^^

Main.hs:25:41: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘tail’
    (imported from Prelude, 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."
   |
25 |     | otherwise           = delete' x $ tail y
   |                                         ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Char (ord, toUpper)

head' :: [String] -> String
head' str = if length str == 0 then "" else head str

tail' :: [String] -> [String]
tail' str = if length str == 0 then [""] else tail str

leave :: Int -> [a] -> [a]
leave n xs = drop (length xs - n) xs

isInfixOf' :: String -> String -> Bool
isInfixOf' n h
    | ln >  lh = False
    | ln == lh = n `eqStr` h
    | ln <  lh = n `eqStr` take ln h || n `isInfixOf'` tail h
    where
        ln = length n
        lh = length h

delete' :: String -> String -> String
delete' x y
    | lx > ly             = y
    | x `eqStr` take lx y = drop lx y
    | otherwise           = delete' x $ tail y
    where
        lx = length x
        ly = length y

eqAlpha :: Char -> Char -> Bool
eqAlpha c1 c2 = toUpper c1 == toUpper c2

eqStr :: String -> String -> Bool
eqStr s1 s2 = and [cond1, cond2]
    where
        cond1 = length s1 == length s2
        cond2 = and $ zipWith eqAlpha s1 s2

isSymbol :: Char -> Bool
isSymbol c = or [cond1, cond2, cond3, cond4]
    where
        code  = ord c
        cond1 =  32 <= code && code <=  47
        cond2 =  58 <= code && code <=  64
        cond3 =  91 <= code && code <=  96
        cond4 = 123 <= code && code <= 126

is_digi :: (String, String) -> Bool
is_digi (name, speech) = and [cond1, cond2] && or [cond3, cond4]
    where
        speech' = leave 6 speech
        cond1   = name == "digi"
        cond2   = "nyo" `isInfixOf'` speech'
        cond3   = and . (map isSymbol) . (delete' "nyo") $ speech'
        cond4   = leave 3 speech' `eqStr` "nyo"

is_petit :: (String, String) -> Bool
is_petit (name, speech) = and [cond1, cond2] && or [cond3, cond4]
    where
        speech' = leave 6 speech
        cond1   = name == "petit"
        cond2   = "nyu" `isInfixOf'` speech'
        cond3   = and . (map isSymbol) . (delete' "nyu") $ speech'
        cond4   = leave 3 speech' `eqStr` "nyu"

is_rabi :: (String, String) -> Bool
is_rabi (name, speech) = and [cond1, cond2]
    where
        cond1 = name == "rabi"
        cond2 = or . (map (not . isSymbol)) $ speech

is_gema :: (String, String) -> Bool
is_gema (name, speech) = and [cond1, cond2] && or [cond3, cond4]
    where
        speech' = leave 7 speech
        cond1   = name == "gema"
        cond2   = "gema" `isInfixOf'` speech'
        cond3   = and . (map isSymbol) . (delete' "gema") $ speech'
        cond4   = leave 4 speech' `eqStr` "gema"

is_piyo :: (String, String) -> Bool
is_piyo (name, speech) = and [cond1, cond2] && or [cond3, cond4]
    where
        speech' = leave 6 speech
        cond1   = name == "piyo"
        cond2   = "pyo" `isInfixOf'` speech'
        cond3   = and . (map isSymbol) . (delete' "pyo") $ speech'
        cond4   = leave 3 speech' `eqStr` "pyo"

isCollect :: String -> Bool
isCollect str = or $ map ($ (name, speech))
    [is_digi, is_petit, is_rabi, is_gema, is_piyo]
    where
        name   = (takeWhile (== ' ') str) ++ (head' . words $ str)
        speech = (unwords . tail' . words $ str) ++ (takeWhile (== ' ') $ reverse str)

solve :: [String] -> [String]
solve =  map ((\x -> if x then "CORRECT (maybe)" else "WRONG!") . isCollect)

main = interact $ unlines . solve . lines
0