結果

問題 No.3246 80% Accuracy Calculator
ユーザー tomerun
提出日時 2025-08-22 23:00:09
言語 Crystal
(1.14.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 13,501 ms
コンパイル使用メモリ 312,004 KB
実行使用メモリ 26,228 KB
平均クエリ数 1061.53
最終ジャッジ日時 2025-08-22 23:00:29
合計ジャッジ時間 18,511 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

def get(var)
  c = 60.times.map do
    puts "? #{var}"
    read_line.to_i
  end.to_a.tally
  c.keys.max_by { |k| c[k] }
end

def add(v0, v1, v2, expect)
  while true
    puts "+ #{v0} #{v1} #{v2}"
    res = read_line.to_i
    if res != 0
      exit 1
    end
    break if get(v2) == expect
  end
end

x = get("A")
y = get("B")
vars = ["A", "B", "C"] # cur, buf, ans
ans = 0
if y % 2 == 1
  add("A", "C", "B", x)
  ans += x
  vars = ["A", "C", "B"]
end
y >>= 1
while y > 0
  add(vars[0], vars[0], vars[1], x * 2)
  x *= 2
  if y % 2 == 1
    add(vars[1], vars[2], vars[0], ans + x)
    ans += x
    vars = [vars[1], vars[2], vars[0]]
  else
    vars.swap(0, 1)
  end
  y >>= 1
end
puts "! #{vars[2]}"
0