結果

問題 No.581 XOR
ユーザー maimai8maimai8
提出日時 2020-06-14 20:03:05
言語 OCaml
(5.1.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 21,576 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:56:52
合計ジャッジ時間 712 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let () =
  let rec convert n =
    if n < 2 then string_of_int n else if n mod 2 = 1 then "1" ^ convert (n/2) else "0" ^ convert (n/2) in
  Scanf.scanf "%d %d\n" @@ fun a c ->
  let a', c' = convert a, convert c in
  let str = ref "" in
  let len = max (String.length a' - 1) (String.length c' - 1) in
  let minlen = min (String.length a' - 1) (String.length c' - 1) in
  let maxstr = if (String.length a' - 1) > (String.length c' - 1) then a' else c' in
  for i = 0 to len do
    if i > minlen then str := !str ^ String.make 1 maxstr.[i]
    else if a'.[i] = c'.[i] then str := !str ^ "0" else str := !str ^ "1"
  done;
  let ans = ref 0. in
  for i = 0 to String.length !str - 1 do
    if !str.[i] = '1' then ans := !ans +. (2. ** float_of_int i)
  done;
  Printf.printf "%d\n" (int_of_float !ans)
0