結果

問題 No.1315 渦巻洞穴
ユーザー trineutrontrineutron
提出日時 2020-12-12 17:03:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,131 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 12,052 KB
実行使用メモリ 10,680 KB
最終ジャッジ日時 2023-10-20 02:09:06
合計ジャッジ時間 6,957 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,272 KB
testcase_01 AC 29 ms
10,272 KB
testcase_02 AC 32 ms
10,272 KB
testcase_03 AC 29 ms
10,272 KB
testcase_04 AC 28 ms
10,272 KB
testcase_05 AC 30 ms
10,272 KB
testcase_06 AC 30 ms
10,272 KB
testcase_07 AC 29 ms
10,272 KB
testcase_08 AC 29 ms
10,272 KB
testcase_09 AC 29 ms
10,272 KB
testcase_10 AC 34 ms
10,272 KB
testcase_11 AC 31 ms
10,272 KB
testcase_12 AC 29 ms
10,272 KB
testcase_13 AC 37 ms
10,448 KB
testcase_14 AC 36 ms
10,404 KB
testcase_15 AC 33 ms
10,328 KB
testcase_16 AC 37 ms
10,420 KB
testcase_17 AC 36 ms
10,412 KB
testcase_18 AC 39 ms
10,456 KB
testcase_19 AC 40 ms
10,432 KB
testcase_20 AC 39 ms
10,464 KB
testcase_21 AC 39 ms
10,428 KB
testcase_22 AC 39 ms
10,408 KB
testcase_23 AC 38 ms
10,460 KB
testcase_24 AC 31 ms
10,300 KB
testcase_25 AC 42 ms
10,564 KB
testcase_26 AC 46 ms
10,488 KB
testcase_27 AC 41 ms
10,464 KB
testcase_28 AC 41 ms
10,428 KB
testcase_29 AC 42 ms
10,572 KB
testcase_30 AC 41 ms
10,524 KB
testcase_31 AC 42 ms
10,464 KB
testcase_32 AC 42 ms
10,472 KB
testcase_33 AC 41 ms
10,568 KB
testcase_34 AC 40 ms
10,468 KB
testcase_35 AC 41 ms
10,464 KB
testcase_36 AC 40 ms
10,432 KB
testcase_37 AC 34 ms
10,348 KB
testcase_38 AC 39 ms
10,420 KB
testcase_39 AC 43 ms
10,516 KB
testcase_40 AC 44 ms
10,428 KB
testcase_41 AC 46 ms
10,504 KB
testcase_42 AC 44 ms
10,616 KB
testcase_43 AC 48 ms
10,504 KB
testcase_44 AC 46 ms
10,616 KB
testcase_45 AC 45 ms
10,680 KB
testcase_46 AC 44 ms
10,616 KB
testcase_47 AC 44 ms
10,504 KB
testcase_48 AC 44 ms
10,616 KB
testcase_49 AC 45 ms
10,504 KB
testcase_50 AC 45 ms
10,504 KB
testcase_51 AC 45 ms
10,616 KB
testcase_52 AC 45 ms
10,504 KB
testcase_53 AC 44 ms
10,616 KB
testcase_54 AC 44 ms
10,680 KB
testcase_55 AC 45 ms
10,616 KB
testcase_56 AC 44 ms
10,504 KB
testcase_57 AC 44 ms
10,616 KB
testcase_58 AC 44 ms
10,504 KB
testcase_59 AC 37 ms
10,428 KB
testcase_60 AC 37 ms
10,428 KB
testcase_61 AC 38 ms
10,428 KB
testcase_62 AC 38 ms
10,428 KB
testcase_63 AC 37 ms
10,428 KB
testcase_64 AC 37 ms
10,428 KB
testcase_65 AC 40 ms
10,428 KB
testcase_66 AC 41 ms
10,428 KB
testcase_67 AC 40 ms
10,428 KB
testcase_68 AC 55 ms
10,428 KB
testcase_69 AC 40 ms
10,428 KB
testcase_70 AC 41 ms
10,428 KB
testcase_71 AC 39 ms
10,428 KB
testcase_72 AC 40 ms
10,428 KB
testcase_73 AC 39 ms
10,428 KB
testcase_74 AC 39 ms
10,428 KB
testcase_75 AC 34 ms
10,272 KB
testcase_76 AC 33 ms
10,272 KB
testcase_77 AC 41 ms
10,464 KB
testcase_78 AC 37 ms
10,368 KB
testcase_79 AC 42 ms
10,460 KB
testcase_80 AC 42 ms
10,472 KB
testcase_81 AC 42 ms
10,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def pos(n):
    if n == 1:
        return 0, 0
    layer = int((math.sqrt(n) - 1) / 2)
    while (2 * layer + 1) ** 2 < n:
        layer += 1
    offset = (2 * layer - 1) ** 2
    edge = 2 * layer
    diff = n - offset - 1
    q, r = divmod(diff, edge)
    r += 1
    if q == 0:
        return layer, -layer + r
    elif q == 1:
        return layer - r, layer
    elif q == 2:
        return -layer, layer - r
    else:
        return -layer + r, -layer

def move(x, y):
    rev = {'L': 'R', 'R': 'L', 'U': 'D', 'D': 'U'}
    s = max(x, 0) * 'R' + max(-x, 0) * 'L' + max(y, 0) * 'U' + max(-y, 0) * 'D'
    res = ''
    for i in range(0, len(s) - 1, 2):
        res += s[i] + rev[s[i]] + s[i] + s[i + 1]
    if len(s) % 2:
        res += s[-1] + rev[s[-1]] + s[-1]
    return res

def move_rev(x, y):
    return move(x, y)[::-1]

s, t = map(int, input().split())
x0, y0 = pos(s)
x1, y1 = pos(t)
if (s + t) % 2 == 0:
    if s % 2 == 0:
        adj = 'DU'
    else:
        adj = ''
    ans = move(-x0, -y0) + 'RUL' + adj + move_rev(x1, y1 - 1)
else:
    ans = move(x1 - x0, y1 - y0)
print(0)
print(len(ans))
print(ans)
0