結果

問題 No.723 2つの数の和
ユーザー taktak
提出日時 2019-02-27 16:32:42
言語 F#
(F# 4.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 1,773 bytes
コンパイル時間 4,079 ms
コンパイル使用メモリ 175,596 KB
実行使用メモリ 41,312 KB
最終ジャッジ日時 2023-09-05 09:23:26
合計ジャッジ時間 9,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
24,288 KB
testcase_01 AC 67 ms
22,360 KB
testcase_02 AC 66 ms
22,288 KB
testcase_03 AC 224 ms
38,156 KB
testcase_04 AC 264 ms
38,968 KB
testcase_05 AC 246 ms
40,032 KB
testcase_06 AC 261 ms
38,036 KB
testcase_07 AC 157 ms
33,972 KB
testcase_08 AC 168 ms
33,988 KB
testcase_09 AC 268 ms
40,812 KB
testcase_10 AC 153 ms
31,156 KB
testcase_11 AC 85 ms
28,920 KB
testcase_12 AC 182 ms
33,720 KB
testcase_13 AC 261 ms
36,712 KB
testcase_14 AC 119 ms
33,656 KB
testcase_15 AC 156 ms
31,852 KB
testcase_16 AC 201 ms
35,440 KB
testcase_17 AC 238 ms
39,128 KB
testcase_18 AC 102 ms
28,804 KB
testcase_19 AC 119 ms
24,804 KB
testcase_20 AC 67 ms
22,196 KB
testcase_21 AC 66 ms
24,180 KB
testcase_22 AC 66 ms
22,268 KB
testcase_23 AC 297 ms
41,312 KB
testcase_24 AC 130 ms
30,256 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

open System
open System.Text

type IO() =
  let size = 1 <<< 12
  let stream = Console.OpenStandardInput()
  let buffer = Array.zeroCreate size
  let ``!`` = byte '!'
  let ``~`` = byte '~'
  let mutable bufferPtr = 0
  
  let hasNextByte =
    let mutable bufferLen = 0
    fun () ->
      if bufferPtr < bufferLen then true
      else
        bufferPtr <- 0
        bufferLen <- stream.Read(buffer, 0, size)
        bufferLen > 0
  let readByte() =
    if hasNextByte() then
      let r = buffer.[bufferPtr]
      bufferPtr <- bufferPtr + 1
      r
    else failwith "error"
  let isAscii c = ``!`` <= c && c <= ``~``
  let nextCharByte() =
    let rec f() =
      let b = readByte()
      if isAscii b then b
      else f()
    f()
  let next() =
    let rec f (sb: StringBuilder) =
      let c = 
        match sb.Length with
        | 0 -> nextCharByte()
        | _ -> readByte()
      if isAscii c then  c |> char |> sb.Append |> f
      else sb 
    f <| new StringBuilder()
    |> fun x -> x.ToString()

  member __.string() = next()
  member __.char()   = nextCharByte() |> char
  member __.int()    = next() |> int
  member __.int64()  = next() |> int64
  member __.float()  = next() |> float

let solve a x =
  let count = a |> Array.countBy id
  let countKey = count |> Array.map fst
  let countMap = count |> Map.ofArray
  let pairNum key1 =
    let val1 = countMap.[key1] |> int64
    let key2 = x - key1 
    Map.tryFind key2 countMap
    |> function
    | Some val2 -> val1 * (int64 val2)
    | None -> 0L
  countKey
  |> Array.map pairNum
  |> Array.sum
  
let io = new IO()

let N, X = 
  let a = io.int()
  let b = io.int()
  a, b
let a = 
  let t = Array.zeroCreate N
  for i in 0 .. (N - 1) do
    t.[i] <- io.int()
  t

solve a X
|> Console.WriteLine
0