結果
| 問題 |
No.1315 渦巻洞穴
|
| コンテスト | |
| ユーザー |
りあん
|
| 提出日時 | 2020-12-01 02:49:34 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 412 ms / 2,000 ms |
| コード長 | 1,612 bytes |
| コンパイル時間 | 83 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 13,520 KB |
| 最終ジャッジ日時 | 2024-09-13 02:46:38 |
| 合計ジャッジ時間 | 20,842 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 79 |
ソースコード
def to_xy(num):
dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)
k, p, d = 0, 1, 1
x, y = 0, 0
while p < num:
for i in range(2):
s = min(d, num - p)
p += s
x += s * dx[k + i]
y += s * dy[k + i]
k ^= 2
d += 1
return x, y
def to_num(x, y):
k = max(abs(x), abs(y))
s = k * 2 + 1
if y == -k:
return s * s - (s - 1) * 0 - (k - x)
elif x == -k:
return s * s - (s - 1) * 1 - (k + y)
elif y == k:
return s * s - (s - 1) * 2 - (k + x)
else:
return s * s - (s - 1) * 3 - (k - y)
# return (command, xor)
# xor: except frm num
def get_move(frm, to):
x, y = frm
tx, ty = to
command = []
xor = 0
# RUDL
while x < tx:
x += 1
command.append('R')
xor ^= to_num(x, y)
while y < ty:
y += 1
command.append('U')
xor ^= to_num(x, y)
while y > ty:
y -= 1
command.append('D')
xor ^= to_num(x, y)
while x > tx:
x -= 1
command.append('L')
xor ^= to_num(x, y)
return command, xor
def solve(s, t):
_, xor = get_move(s, t)
ans = []
if xor != 0:
ans += get_move(s, to_xy(xor))[0]
ans += get_move(to_xy(xor), s)[0]
ans += get_move(s, t)[0]
else:
_, xor = get_move(t, s)
ans += get_move(s, t)[0]
ans += get_move(t, to_xy(xor))[0]
ans += get_move(to_xy(xor), t)[0]
return ''.join(ans)
s, t = map(int, input().split())
ans = solve(to_xy(s), to_xy(t))
print(0, len(ans), ans, sep='\n')
りあん