結果

問題 No.2597 Yet Another Topological Problem
ユーザー 👑 rin204
提出日時 2023-12-25 22:15:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 826 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 92,212 KB
最終ジャッジ日時 2024-09-27 14:45:44
合計ジャッジ時間 17,852 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

d = q // p
tot = d * (d + 1)
x = 180000 // 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")
assert len(XY) <= 250000, len(XY)
print(len(XY) - 1)
for x, y in XY:
    print(x, y)
0