結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-06 23:30:35 |
| 言語 | Haskell (9.10.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,020 bytes |
| コンパイル時間 | 8,246 ms |
| コンパイル使用メモリ | 173,952 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-13 13:50:07 |
| 合計ジャッジ時間 | 5,361 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 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
ソースコード
-- 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) 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 + s * b)