Submission #857563


Source Code Expand

Copy
namespace DotNetLab.Fs.Console

open System
open System.Collections.Generic

[<AutoOpen>]
module Misc =
  type Long = int64
  let inline long x = int64 x

  let readLine f = Console.ReadLine().Split([|' '|]) |> Array.map f

  let combinationSums xs =
    let rec loop (s, n) i =
      seq {
        if i = (xs |> Array.length) then
          yield (s, n)
        else
          yield! loop (s, n) (i + 1)
          yield! loop (s + xs.[i], n + 1.0) (i + 1)
      }
    in
      loop (0.0, 0.0) 0

  let halves xs =
    xs
    |> combinationSums
    |> Seq.toArray
    |> Array.sortBy (fun (s, n) -> s / n)

  let upperBound pred (xs: array<'x>) =
    let rec loop lb ub =
      if ub - lb <= 1
      then ub
      else
        let i = (ub - lb) / 2 + lb
        if pred xs.[i]
        then loop i ub
        else loop lb i
    in
      loop (-1) (xs |> Array.length)

  let countHalf a (s, n) (hs: (float * float)[]) =
    let lb = hs |> upperBound (fun (s', n') -> (s + s') / (n + n') < a)
    let ub = hs |> upperBound (fun (s', n') -> (s + s') / (n + n') <= a)
    ub - lb |> long

module Program =
  [<EntryPoint>]
  let main _ =
    let [|_; a|] = readLine float
    let xs = readLine float

    let n = xs.Length / 2
    let ys = xs |> Array.skip n
    let xs = xs |> Array.take n

    let xhs = xs |> halves
    let yhs = ys |> halves

    let count = xhs |> Seq.sumBy (fun h -> countHalf a h yhs)

    printfn "%d" count

    // exit code
    0

Submission Info

Submission Time
Task C - Tak and Cards
User vain0
Language F# (Mono 4.0)
Score 0
Code Size 1519 Byte
Status WA
Exec Time 2113 ms
Memory 66308 KB

Compile Error

/imojudge/Main.fs(51,9): warning FS0025: Incomplete pattern matches on this expression. For example, the value '[|_; _; _|]' may indicate a case not covered by the pattern(s).

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 100
Status
AC × 1
WA × 3
AC × 5
WA × 7
AC × 5
WA × 10
TLE × 9
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt, example_04.txt
Subtask1 example_01.txt, example_02.txt, example_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt
All example_01.txt, example_02.txt, example_03.txt, example_04.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt
Case Name Status Exec Time Memory
example_01.txt WA 111 ms 5072 KB
example_02.txt AC 110 ms 5072 KB
example_03.txt WA 106 ms 5072 KB
example_04.txt WA 543 ms 22976 KB
subtask1_01.txt WA 108 ms 5328 KB
subtask1_02.txt WA 112 ms 5328 KB
subtask1_03.txt AC 112 ms 5328 KB
subtask1_04.txt AC 113 ms 5328 KB
subtask1_05.txt WA 112 ms 5328 KB
subtask1_06.txt WA 107 ms 5072 KB
subtask1_07.txt AC 110 ms 5072 KB
subtask1_08.txt WA 112 ms 5328 KB
subtask1_09.txt AC 108 ms 5328 KB
subtask2_01.txt TLE 2113 ms 57100 KB
subtask2_02.txt TLE 2113 ms 57100 KB
subtask2_03.txt TLE 2109 ms 57180 KB
subtask2_04.txt TLE 2109 ms 57100 KB
subtask2_05.txt TLE 2113 ms 57100 KB
subtask2_06.txt TLE 2109 ms 57100 KB
subtask2_07.txt TLE 2109 ms 57100 KB
subtask2_08.txt WA 527 ms 22976 KB
subtask2_09.txt WA 535 ms 22976 KB
subtask2_10.txt TLE 2110 ms 66308 KB
subtask2_11.txt TLE 2110 ms 65604 KB