結果
| 問題 |
No.3018 目隠し宝探し
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-03 13:14:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,063 bytes |
| コンパイル時間 | 658 ms |
| コンパイル使用メモリ | 82,460 KB |
| 実行使用メモリ | 85,984 KB |
| 平均クエリ数 | 2.73 |
| 最終ジャッジ日時 | 2025-02-03 13:14:33 |
| 合計ジャッジ時間 | 6,670 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 18 WA * 3 |
ソースコード
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"? {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()