結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
23,160 KB
testcase_01 AC 93 ms
23,224 KB
testcase_02 AC 94 ms
25,244 KB
testcase_03 AC 93 ms
23,296 KB
testcase_04 WA -
testcase_05 AC 95 ms
23,172 KB
testcase_06 WA -
testcase_07 AC 94 ms
23,152 KB
testcase_08 AC 94 ms
25,148 KB
testcase_09 AC 94 ms
21,156 KB
testcase_10 AC 93 ms
23,224 KB
testcase_11 AC 93 ms
23,356 KB
testcase_12 AC 96 ms
23,248 KB
testcase_13 AC 95 ms
21,228 KB
testcase_14 AC 94 ms
25,276 KB
testcase_15 AC 94 ms
23,208 KB
testcase_16 AC 95 ms
25,292 KB
testcase_17 AC 96 ms
25,240 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 97 ms
25,148 KB
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 %d" ma mi

  //exit code
  0
0