結果

問題 No.297 カードの数式
ユーザー vain0vain0
提出日時 2015-11-06 23:59:59
言語 F#
(.NET 7)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 5,674 ms
コンパイル使用メモリ 164,776 KB
実行使用メモリ 25,460 KB
最終ジャッジ日時 2023-10-11 14:34:02
合計ジャッジ時間 8,580 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
23,052 KB
testcase_01 AC 96 ms
23,120 KB
testcase_02 AC 96 ms
23,204 KB
testcase_03 AC 96 ms
23,224 KB
testcase_04 WA -
testcase_05 AC 96 ms
25,208 KB
testcase_06 AC 96 ms
25,152 KB
testcase_07 AC 95 ms
23,156 KB
testcase_08 AC 96 ms
25,180 KB
testcase_09 AC 95 ms
23,320 KB
testcase_10 AC 95 ms
25,172 KB
testcase_11 AC 96 ms
25,328 KB
testcase_12 AC 96 ms
25,104 KB
testcase_13 AC 97 ms
25,168 KB
testcase_14 AC 97 ms
25,280 KB
testcase_15 AC 97 ms
25,240 KB
testcase_16 AC 97 ms
23,220 KB
testcase_17 AC 98 ms
25,112 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 95 ms
23,324 KB
testcase_23 AC 97 ms
23,160 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

open System

[<EntryPoint>]
let main argv =
  let n = Console.ReadLine() |> int
  let cs = Console.ReadLine().Split(' ') |> Array.map char
  let (ds, cnt_add, cnt_sub) =
    cs |> Array.fold (fun (ds, cnt_add, cnt_sub) -> function
      | '+' -> (ds, cnt_add + 1, cnt_sub)
      | '-' -> (ds, cnt_add, cnt_sub + 1)
      | c -> ((int (string c)) :: ds, cnt_add, cnt_sub)
      ) ([], 0, 0)

  let cnt_place =
    List.length ds - 1 - (cnt_add + cnt_sub)

  let ds = ds |> List.sort |> List.rev // decending

  let cons_digit ds n =
    let h = ds |> Seq.take n |> Seq.fold (fun x d -> x * 10 + d) 0
    let t = h :: (ds |> Seq.skip n |> List.ofSeq)
    t
    
  let f ds =
    + (ds |> Seq.take (cnt_add + 1) |> Seq.sum)
    - (ds |> Seq.skip (cnt_add + 1) |> Seq.sum)
    
  let ds1 = cons_digit ds (cnt_place + 1)

  let ma = f ds1
  let mi =
    if cnt_sub >= 1 then
      f (ds1 |> List.rev)
    else
      // 絶対値の最小化
      let ds2 = cons_digit (ds |> List.rev) (cnt_place + 1)
      f ds2
  
  printfn "%d %d" ma mi

  //exit code
  0
0