結果
| 問題 | No.581 XOR | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-06-14 20:03:05 | 
| 言語 | OCaml (5.2.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 799 bytes | 
| コンパイル時間 | 205 ms | 
| コンパイル使用メモリ | 21,572 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-09 01:12:41 | 
| 合計ジャッジ時間 | 658 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 8 | 
ソースコード
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)
            
            
            
        