結果

問題 No.297 カードの数式
ユーザー vain0vain0
提出日時 2015-11-06 23:50:29
言語 F#
(.NET 7)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 3,595 ms
コンパイル使用メモリ 161,092 KB
実行使用メモリ 27,336 KB
最終ジャッジ日時 2023-10-11 14:25:17
合計ジャッジ時間 7,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
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 t1 = ds |> Seq.take (cnt_place + 1) |> Seq.fold (fun x d -> x * 10 + d) 0
  let ds1 = t1 :: (ds |> Seq.skip (cnt_place + 1) |> List.ofSeq)

  let f ds =
    + (ds |> Seq.take (cnt_add + 1) |> Seq.sum)
    - (ds |> Seq.skip (cnt_add + 1) |> Seq.sum)

  let ma = f ds1
  let mi = f (ds1 |> List.rev)
  
  printfn "%d" ma
  printfn "%d" mi

  //exit code
  0
0