結果

問題 No.3018 目隠し宝探し
ユーザー u_kun
提出日時 2025-02-03 13:28:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 992 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 82,032 KB
平均クエリ数 2.59
最終ジャッジ日時 2025-02-03 13:28:45
合計ジャッジ時間 7,464 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

def calc_dist(base_row, base_col, se_row, se_col):
    # 1-indexで、(se_row, se_col)は(base_row, base_col)からどれだけ離れているか?ユークリッド距離の2乗。
    return (base_row - se_row)**2 + (base_col - se_col)**2

H, W = map(int, input().split())

if H == 1 and W == 1:
    print("! 1 1")
    exit()

######################################################
print("? 1 1")
d1 = int(input())  # 左上からの距離(の2乗)

ans_candidate = 0 # 答えの候補になるマスの個数

for row in range(1, H + 1):
    for col in range(1, W + 1):

        if calc_dist(1, 1, row, col) == d1:
            ans_candidate += 1

if ans_candidate == 1:
    for row in range(1, H + 1):
        for col in range(1, W + 1):

            if calc_dist(1, 1, row, col) == d1:
                print(f"! {row} {col}")
                exit()
######################################################
print(f"? {1} {W}")
d2 = int(input())  # 右上からの距離(の2乗)

ans_candidate = 0 # 答えの候補になるマスの個数

for row in range(1, H + 1):
    for col in range(1, W + 1):

        if calc_dist(1, 1, row, col) == d1 and calc_dist(1, W, row, col) == d2:
            ans_candidate += 1

if ans_candidate == 1:
    for row in range(1, H + 1):
        for col in range(1, W + 1):

            if calc_dist(1, 1, row, col) == d1 and calc_dist(1, W, row, col) == d2:
                print(f"! {row} {col}")
                exit()
0