結果

問題 No.380 悪の台本
ユーザー くれちーくれちー
提出日時 2017-02-14 17:02:24
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 3,119 bytes
コンパイル時間 7,761 ms
コンパイル使用メモリ 175,104 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-11-06 23:22:17
合計ジャッジ時間 8,483 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 14 ms
7,936 KB
testcase_05 AC 18 ms
7,936 KB
testcase_06 AC 14 ms
8,064 KB
testcase_07 AC 23 ms
7,936 KB
testcase_08 AC 11 ms
8,448 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   = head' . words $ str
        speech = unwords . tail' . words $ str

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

main = interact $ unlines . solve . lines
0