結果
問題 |
No.3018 目隠し宝探し
|
ユーザー |
|
提出日時 | 2025-02-03 13:10:01 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,010 bytes |
コンパイル時間 | 1,339 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 85,536 KB |
平均クエリ数 | 2.77 |
最終ジャッジ日時 | 2025-02-03 13:10:10 |
合計ジャッジ時間 | 6,468 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 17 WA * 3 RE * 1 |
ソースコード
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()) ###################################################### 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"? {H} {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(H, 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(H, W, row, col) == d2: print(f"! {row} {col}") exit() ##################################################### # 候補は二つしかないはず。 ans_row_1 = None ans_col_1 = None ans_row_2 = None ans_col_2 = None 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(H, W, row, col) == d2: if ans_row_1 == None: ans_row_1, ans_col_1 = row, col else: ans_row_2, ans_col_2 = row, col print(f"? {ans_row_1} {ans_col_1}") if int(input()) == 0: print(f"! {ans_row_1} {ans_col_1}") exit() print(f"! {ans_row_2} {ans_col_2}") exit()