結果
| 問題 | No.3598 Queen vs. King |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-07-24 21:59:00 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,821 bytes |
| 記録 | |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 95,988 KB |
| 実行使用メモリ | 93,568 KB |
| 平均クエリ数 | 50.92 |
| 最終ジャッジ日時 | 2026-07-24 22:00:42 |
| 合計ジャッジ時間 | 3,247 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | RE * 10 |
ソースコード
from itertools import product
def can_reach(src, dst):
src_x, src_y = src
dst_x, dst_y = dst
for cx, cy in product((-1, 0, 1), repeat=2):
if cx == cy == 0:
continue
if cx * src_x + cy * src_y == cx * dst_x + cy * dst_y:
return True
return False
def receive():
x, y = [int(s) for s in input().split()]
if (x, y) in ((0, 0), (-1, -1)):
is_end = True
else:
is_end = False
return is_end, (x, y)
def put(x, y):
print(x, y)
def solve():
H, W = [int(s) for s in input().split()]
res, (x1, y1) = receive()
if res:
return
curr_x, curr_y = x1, 1
put(curr_x, curr_y)
res, (x2, y2) = receive()
if res:
return
for di, dj in product((-1, 1), repeat=2):
gi, gj = x2 + di, y2 + dj
if not (1 <= gi <= H and 1 <= gj <= W):
continue
if not can_reach((curr_x, curr_y), (gi, gj)):
continue
curr_x, curr_y = gi, gj
break
else:
for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)):
gi, gj = x2 + di, y2 + dj
if not (1 <= gi <= H and 1 <= gj <= W):
continue
if not can_reach((curr_x, curr_y), (gi, gj)):
continue
curr_x, curr_y = gi, gj
break
put(curr_x, curr_y)
res, (x3, y3) = receive()
if res:
return
for di, dj in product((-1, 1), repeat=2):
gi, gj = x3 + di, y3 + dj
if not (1 <= gi <= H and 1 <= gj <= W):
continue
if not can_reach((curr_x, curr_y), (gi, gj)):
continue
put(gi, gj)
break
res, _ = receive()
if res:
return
if __name__ == "__main__":
T = int(input())
for _ in range(T):
solve()