結果

問題 No.723 2つの数の和
ユーザー taktak
提出日時 2019-02-27 16:26:52
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 1,754 bytes
コンパイル時間 7,316 ms
コンパイル使用メモリ 174,956 KB
実行使用メモリ 40,880 KB
最終ジャッジ日時 2023-09-05 09:22:33
合計ジャッジ時間 10,436 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
22,292 KB
testcase_01 AC 65 ms
22,200 KB
testcase_02 AC 67 ms
22,384 KB
testcase_03 AC 226 ms
38,020 KB
testcase_04 AC 270 ms
38,596 KB
testcase_05 AC 251 ms
39,672 KB
testcase_06 AC 259 ms
39,812 KB
testcase_07 AC 156 ms
33,692 KB
testcase_08 AC 167 ms
31,752 KB
testcase_09 AC 266 ms
38,516 KB
testcase_10 AC 153 ms
31,140 KB
testcase_11 AC 85 ms
26,884 KB
testcase_12 AC 183 ms
33,416 KB
testcase_13 AC 270 ms
40,496 KB
testcase_14 AC 118 ms
29,384 KB
testcase_15 AC 160 ms
33,752 KB
testcase_16 AC 205 ms
35,100 KB
testcase_17 AC 237 ms
36,892 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 64 ms
20,328 KB
testcase_21 AC 66 ms
22,212 KB
testcase_22 AC 65 ms
22,172 KB
testcase_23 AC 295 ms
40,880 KB
testcase_24 AC 131 ms
32,124 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]
    let key2 = x - key1
    Map.tryFind key2 countMap
    |> function
    | Some val2 -> val1 * val2
    | None -> 0
  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