結果

問題 No.2597 Yet Another Topological Problem
ユーザー rin204
提出日時 2023-12-25 22:12:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 792 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,760 KB
実行使用メモリ 98,904 KB
最終ジャッジ日時 2024-09-27 14:44:27
合計ジャッジ時間 21,695 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 54 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

p, q = map(int, input().split())

if p == 1:
    print("Impossible")
    exit()

d = q // p
tot = d * (d + 1)
x = 240000 // tot
S = []
ud = "U"
rev = {"U": "D", "D": "U"}

X = []
l = 1
r = d
while l <= r:
    if len(X) % 2 == 0:
        X.append(r)
        r -= 1
    else:
        X.append(l)
        l += 1


for i in X:
    S.append(ud * i)
    S.append("R" * x * i)
    ud = rev[ud]
    S.append(ud * i)
for i in X[::-1]:
    S.append(ud * i)
    S.append("R" * x * i)
    ud = rev[ud]
    S.append(ud * i)

S = "".join(S)
x, y = 0, 0
XY = [(x, y)]
for s in S:
    if s == "U":
        y += 1
    elif s == "D":
        y -= 1
    elif s == "R":
        x += 1
    elif s == "L":
        x -= 1
    XY.append((x, y))


print("Possible")
print(len(XY) - 1)
for x, y in XY:
    print(x, y)
0