結果

問題 No.3598 Queen vs. King
コンテスト
ユーザー Kude
提出日時 2026-07-24 22:06:40
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 191 ms / 2,000 ms
+ 2µs
コード長 1,280 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 237 ms
コンパイル使用メモリ 96,104 KB
実行使用メモリ 84,864 KB
平均クエリ数 1787.50
最終ジャッジ日時 2026-07-24 22:06:50
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code


for _ in range(int(input())):
    h, w = map(int, input().split())
    flip = h > w
    if flip:
        h, w = w, h
    def get():
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if flip:
            y, x = x, y
        return x, y
    def give(x, y):
        if flip:
            y, x = x, y
        print(x+1, y+1)
    x, y = get()
    if x == -1: continue
    if x == h-2 and y == w-2:
        give(0, w - h)
        x, y = get()
        if x == -1: continue
        if x - y < h - w:
            d = x
            give(d, w-h+d)
            x, y = get()
            if x == -1: continue
            give(x, w-2)
            x, y = get()
            assert x == -1
            continue
        else:
            d = y - (w-h)
            give(d, w-h+d)
            x, y = get()
            if x == -1: continue
            give(h-2, y)
            x, y = get()
            assert x == -1
            continue
    elif x == h-2:
        give(0, w-2)
        x, y = get()
        if x == -1: continue
        give(x, w-2)
        x, y = get()
        assert x == -1
        continue
    else:
        give(h-2, 0)
        x, y = get()
        if x == -1: continue
        give(h-2, y)
        x, y = get()
        assert x == -1
        continue
0