結果

問題 No.9008 空白区切りで与えられる数値データの合計値を求める(テスト用)
ユーザー shoichiro-sasakishoichiro-sasaki
提出日時 2018-04-28 19:40:06
言語 OCaml
(5.1.0)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 21,788 KB
実行使用メモリ 48,804 KB
最終ジャッジ日時 2024-04-17 08:44:11
合計ジャッジ時間 2,339 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 AC 29 ms
10,092 KB
testcase_09 AC 45 ms
14,520 KB
testcase_10 AC 149 ms
43,180 KB
testcase_11 AC 151 ms
41,984 KB
testcase_12 AC 156 ms
43,304 KB
testcase_13 AC 156 ms
45,080 KB
testcase_14 AC 163 ms
44,024 KB
testcase_15 AC 166 ms
45,292 KB
testcase_16 AC 191 ms
48,804 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

open Scanf
open Printf

let ($) f x = f x
let scanIntlist n = let list = ref [] in
  for i = 1 to n do
    list := (scanf (if i < n then "%Ld " else "%Ld") (fun x -> x))::!list
  done; List.rev !list
    
let string2charlist s = let rec proc i res =
                          try proc (i+1) $ s.[i]::res
                          with Invalid_argument _ -> res
  in List.rev $ proc 0 []
       
let minInt l = let rec proc l res = match l with
      [] -> res
    | x::xs -> if x < res then proc xs x else proc xs res
  in if l == [] then raise $ Failure "null list" else proc l max_int

let maxInt l = let rec proc l res = match l with
      [] -> res
    | x::xs -> if x > res then proc xs x else proc xs res
  in if l == [] then raise $ Failure "null list" else proc l min_int

let rec listSum = function
    [] -> Int64.zero
  | x::xs -> Int64.add x (listSum xs)

let rec quick_sort = function
    ([] | [_]) as l -> l
  | pivot :: rest ->
     let rec partition left right = function
	 [] -> (quick_sort left) @ (pivot :: quick_sort right)
       | y :: ys -> if pivot < y then partition left (y :: right) ys
                    else partition (y :: left) right ys
     in partition [] [] rest;;

scanf "%d " $ fun n -> print_string $ Int64.to_string (listSum (scanIntlist n));;
0