結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
vain0
|
| 提出日時 | 2015-11-06 23:50:29 |
| 言語 | F# (F# 4.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 869 bytes |
| コンパイル時間 | 6,905 ms |
| コンパイル使用メモリ | 186,340 KB |
| 実行使用メモリ | 37,500 KB |
| 最終ジャッジ日時 | 2024-09-13 13:07:00 |
| 合計ジャッジ時間 | 17,366 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 23 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (245 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
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
vain0