結果
| 問題 |
No.805 UMG
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-08 18:05:07 |
| 言語 | Haskell (9.10.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,048 bytes |
| コンパイル時間 | 9,404 ms |
| コンパイル使用メモリ | 169,216 KB |
| 実行使用メモリ | 14,752 KB |
| 最終ジャッジ日時 | 2024-11-18 14:02:18 |
| 合計ジャッジ時間 | 22,741 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 TLE * 5 |
コンパイルメッセージ
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
ソースコード
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