結果

問題 No.1315 渦巻洞穴
ユーザー りあんりあん
提出日時 2020-12-01 02:49:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 1,612 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 10,664 KB
最終ジャッジ日時 2023-10-11 03:18:13
合計ジャッジ時間 19,225 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,136 KB
testcase_01 AC 17 ms
8,216 KB
testcase_02 AC 16 ms
8,112 KB
testcase_03 AC 16 ms
8,252 KB
testcase_04 AC 17 ms
7,996 KB
testcase_05 AC 16 ms
8,056 KB
testcase_06 AC 17 ms
8,000 KB
testcase_07 AC 17 ms
8,052 KB
testcase_08 AC 16 ms
8,108 KB
testcase_09 AC 17 ms
8,112 KB
testcase_10 AC 16 ms
8,080 KB
testcase_11 AC 17 ms
8,108 KB
testcase_12 AC 17 ms
8,224 KB
testcase_13 AC 157 ms
9,396 KB
testcase_14 AC 131 ms
8,908 KB
testcase_15 AC 153 ms
8,804 KB
testcase_16 AC 174 ms
9,208 KB
testcase_17 AC 197 ms
9,080 KB
testcase_18 AC 177 ms
9,424 KB
testcase_19 AC 174 ms
9,164 KB
testcase_20 AC 241 ms
9,816 KB
testcase_21 AC 135 ms
9,424 KB
testcase_22 AC 216 ms
9,476 KB
testcase_23 AC 113 ms
8,744 KB
testcase_24 AC 164 ms
8,556 KB
testcase_25 AC 121 ms
8,932 KB
testcase_26 AC 161 ms
9,180 KB
testcase_27 AC 142 ms
9,272 KB
testcase_28 AC 141 ms
9,056 KB
testcase_29 AC 248 ms
10,108 KB
testcase_30 AC 214 ms
10,112 KB
testcase_31 AC 181 ms
9,588 KB
testcase_32 AC 118 ms
8,828 KB
testcase_33 AC 242 ms
9,640 KB
testcase_34 AC 209 ms
9,760 KB
testcase_35 AC 174 ms
9,256 KB
testcase_36 AC 222 ms
9,748 KB
testcase_37 AC 219 ms
9,452 KB
testcase_38 AC 193 ms
9,232 KB
testcase_39 AC 232 ms
10,200 KB
testcase_40 AC 223 ms
9,712 KB
testcase_41 AC 221 ms
10,576 KB
testcase_42 AC 245 ms
9,840 KB
testcase_43 AC 225 ms
10,576 KB
testcase_44 AC 324 ms
10,580 KB
testcase_45 AC 225 ms
10,428 KB
testcase_46 AC 332 ms
10,640 KB
testcase_47 AC 222 ms
10,404 KB
testcase_48 AC 236 ms
9,920 KB
testcase_49 AC 221 ms
10,572 KB
testcase_50 AC 215 ms
10,532 KB
testcase_51 AC 327 ms
10,664 KB
testcase_52 AC 215 ms
10,432 KB
testcase_53 AC 237 ms
9,848 KB
testcase_54 AC 262 ms
10,580 KB
testcase_55 AC 237 ms
9,864 KB
testcase_56 AC 212 ms
10,412 KB
testcase_57 AC 316 ms
10,464 KB
testcase_58 AC 220 ms
10,416 KB
testcase_59 AC 163 ms
9,444 KB
testcase_60 AC 173 ms
9,336 KB
testcase_61 AC 168 ms
9,148 KB
testcase_62 AC 202 ms
9,516 KB
testcase_63 AC 177 ms
9,360 KB
testcase_64 AC 190 ms
9,400 KB
testcase_65 AC 171 ms
9,352 KB
testcase_66 AC 183 ms
9,352 KB
testcase_67 AC 174 ms
9,164 KB
testcase_68 AC 225 ms
9,988 KB
testcase_69 AC 163 ms
9,268 KB
testcase_70 AC 185 ms
9,276 KB
testcase_71 AC 188 ms
9,324 KB
testcase_72 AC 223 ms
9,984 KB
testcase_73 AC 213 ms
9,736 KB
testcase_74 AC 179 ms
9,412 KB
testcase_75 AC 17 ms
8,212 KB
testcase_76 AC 17 ms
8,160 KB
testcase_77 AC 153 ms
9,060 KB
testcase_78 AC 154 ms
8,992 KB
testcase_79 AC 104 ms
8,792 KB
testcase_80 AC 175 ms
9,020 KB
testcase_81 AC 94 ms
8,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0