結果
| 問題 |
No.457 (^^*)
|
| コンテスト | |
| ユーザー |
okaduki
|
| 提出日時 | 2016-12-15 00:59:19 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 1,255 ms / 2,000 ms |
| コード長 | 1,145 bytes |
| コンパイル時間 | 6,333 ms |
| コンパイル使用メモリ | 181,108 KB |
| 実行使用メモリ | 10,112 KB |
| 最終ジャッジ日時 | 2024-11-30 08:11:24 |
| 合計ジャッジ時間 | 12,629 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
コンパイルメッセージ
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:17:31: 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."
|
17 | 3 -> head rs
| ^^^^
Main.hs:18:36: 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."
|
18 | 0 -> sub (tail rs) (B.tail s)
| ^^^^
Main.hs:20:36: 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."
|
20 | _ -> sub (tail rs) (B.tail s)
| ^^^^
Main.hs:23:31: 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."
|
23 | calcacc = B.foldr (\c acc -> (head acc + if c == ')' then 1 else 0):acc) [0]
| ^^^^
[2 of 2] Linking a.out
ソースコード
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace
calcr :: [Integer] -> B.ByteString -> Integer -> Integer
calcr (r:rs) s acc = if s == B.empty then acc
else calcr rs bs (if B.head s == '('
then acc + sub rs bs 0
else acc)
where
bs = B.tail s
sub rs s lv = if s == B.empty then 0
else case lv of
3 -> head rs
0 -> sub (tail rs) (B.tail s)
(if B.head s == '*' then lv+1 else lv)
_ -> sub (tail rs) (B.tail s)
(if B.head s == '^' then lv+1 else lv)
calcacc = B.foldr (\c acc -> (head acc + if c == ')' then 1 else 0):acc) [0]
rev = B.map (\c -> case c of
'(' -> ')'
')' -> '('
_ -> c) . B.reverse
main = do
s <- B.getLine
let rs = rev s
printf "%d %d\n" (calcr (calcacc rs) rs 0) (calcr (calcacc s) s 0)
okaduki