結果

問題 No.805 UMG
ユーザー iwotiwot
提出日時 2020-06-08 18:05:07
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 1,048 bytes
コンパイル時間 8,226 ms
コンパイル使用メモリ 168,192 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-04-29 11:07:43
合計ジャッジ時間 12,706 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 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 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 99 ms
7,680 KB
testcase_16 AC 85 ms
7,552 KB
testcase_17 AC 52 ms
7,552 KB
testcase_18 AC 142 ms
7,680 KB
testcase_19 AC 37 ms
7,552 KB
testcase_20 AC 128 ms
7,552 KB
testcase_21 AC 69 ms
7,808 KB
testcase_22 AC 82 ms
7,680 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

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

solve :: String -> Int -> Int
solve [] acc = acc
solve xs acc | length xs < 3 = acc
solve xs@('U' : xs') acc = solve (getNext xs) (acc + c)
    where steps = getSteps xs 0
          c = foldl (\acc' step -> if findUMG xs 0 step == Found then acc' + 1 else acc') 0 steps
solve xs acc = solve (getNext xs) acc

data UMG = Found | NotFound | Over deriving (Show, Eq)

findUMG :: String -> Int -> Int -> UMG
findUMG s start step = if start + step + step + 1 > length s
    then Over
    else if s !! start == 'U' && s !! (start+step) == 'M' && s !! (start+step*2) == 'G' then
        Found
    else
        NotFound

getNext :: String -> String
getNext (x : xs) = dropWhile (/= 'U') xs

getSteps :: String -> Int -> [Int]
getSteps [] start = []
getSteps (x : []) start = []
getSteps (x : xs) start =
    if length d > 0 then start + i : getSteps d (start + i) else getSteps (drop 1 d) (start + i)
    where d = dropWhile (/='M') xs
          i = length xs - length d + 1
0