結果

問題 No.3018 目隠し宝探し
ユーザー isee
提出日時 2025-01-25 21:13:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 69,504 KB
平均クエリ数 2.68
最終ジャッジ日時 2025-01-26 00:08:39
合計ジャッジ時間 4,433 ms
ジャッジサーバーID
(参考情報)
judge5 / judge13
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import isqrt

def main():
    # 入力
    H, W = map(int, input().split())
    # 計算・出力
    def ask(x, y):
        print(f'? {x+1} {y+1}', flush=True)
        res = int(input())
        if res == -1: exit()
        return res
    def ans(x, y):
        print(f'! {x+1} {y+1}', flush=True)
        exit()
    def dist(x1, y1, x2, y2):
        return (x1 - x2) ** 2 + (y1 - y2) ** 2
    
    if H == 1 and W == 1:
        ans(0, 0)

    d1 = ask(0, 0)
    
    if H == 1:
        ans(0, isqrt(d1))
    if W == 1:
        ans(isqrt(d1), 0)
    
    N = W-1
    d2 = ask(0, N)

    # x^2 + y^2 = d1
    # x^2 + (N-y)^2 = d2
    # -> 2yN - N^2 = d1 - d2
    y = (d1 - d2 + N*N) // (2*N)
    x = isqrt(d1 - y*y)

    ans(x, y)

if __name__ == "__main__":
    main()
0