結果
問題 |
No.1315 渦巻洞穴
|
ユーザー |
![]() |
提出日時 | 2020-12-12 10:20:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 1,929 bytes |
コンパイル時間 | 371 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 62,464 KB |
最終ジャッジ日時 | 2024-09-19 21:47:14 |
合計ジャッジ時間 | 6,653 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 79 |
ソースコード
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline def XY(n): if n == 1: return 0, 0 for i in range(1, 10**5, 2): if i ** 2 >= n: k = i break C = k**2 - (k-2)**2 RD = k ** 2 LD = RD - C // 4 LU = LD - C // 4 RU = LU - C // 4 if n <= RU: return k//2, k//2 - (RU - n) elif RU < n <= LU: return -(k//2) + (LU - n), k//2 elif LU < n <= LD: return -(k//2), -(k//2) + (LD - n) else: return k//2 - (RD - n), -(k//2) def move(sx, sy, tx, ty): assert (abs(tx - sx) + abs(ty - sy))%2 == 0 ret = [] if abs(tx - sx) & 1: ret.append("ULRL") sx -= 1 sy += 1 if tx < sx: for _ in range((sx - tx) // 2): ret.append("LLRL") if tx > sx: for _ in range((tx - sx) // 2): ret.append("RRLR") if ty < sy: for _ in range((sy - ty) // 2): ret.append("DDUD") if ty > sy: for _ in range((ty - sy) // 2): ret.append("UUDU") return ret s, t = map(int, input().split()) sx, sy = XY(s) tx, ty = XY(t) ans = ["RLR"] sx += 1 if abs(s-t) % 2 == 1: ans.extend(move(sx, sy, tx, ty)) else: if s % 2 == 1: ans.extend(move(sx, sy, -1, 0)) ans.append("R") ans.append("RU") ans.extend(move(1, 1, tx, ty)) else: ans.extend(move(sx, sy, -1, 1)) ans.append("R") ans.append("DDLDDRUU") # sample 3 ans.extend(move(0, -1, tx, ty)) ANS = "".join(ans) assert len(ANS) <= 200000 print(0) print(len(ANS)) print(ANS) if __name__ == '__main__': main()