結果

問題 No.297 カードの数式
ユーザー Leonardone
提出日時 2015-11-06 23:42:59
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,030 bytes
コンパイル時間 4,772 ms
コンパイル使用メモリ 173,312 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 02:21:54
合計ジャッジ時間 5,720 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #
プレゼンテーションモードにする

-- yukicoder My Practice
-- author: Leonardone @ NEETSDKASU
import Data.List
main = do
n <- getLine
c <- getLine
putStrLn $ solve c
solve c =
let
cc = words c
(mc, nm) = partition (== "-") cc
(pc, np) = partition (== "+") nm
sc = sort np
fn1 _ 0 s cs = (s, cs)
fn1 f n s (c:cs) = fn1 f (n - 1) (f s $ read c) cs
lm = length mc
lp = length pc
(sm1, nm1) = fn1 (-) lm 0 sc
(sm2, nm2) = fn1 (+) lp sm1 nm1
maxsum = sm2 + (read $ reverse $ concat nm2)
(sx1, nx1) = fn1 (+) (lp + 1) 0 sc
(sx2, nx2) = if lm < 2
then (sx1, nx1)
else fn1 (-) (lm - 1) sx1 nx1
minsum = if lm == 0
then fn2 (lp + 1) (reverse sc) 1 0
else sx2 - (read $ reverse $ concat nx2)
in
unwords $ map show [maxsum, minsum]
fn2 _ [] _ s = s
fn2 n xs b s =
let
(ys, zs) = splitAt n xs
sm = sum $ map read ys
in
fn2 n zs (b * 10) (sm * b + s)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0