結果

問題 No.1315 渦巻洞穴
ユーザー りあんりあん
提出日時 2020-12-01 03:14:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,979 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 9,124 KB
最終ジャッジ日時 2023-10-11 03:19:04
合計ジャッジ時間 9,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,136 KB
testcase_01 AC 17 ms
8,116 KB
testcase_02 AC 17 ms
8,076 KB
testcase_03 AC 16 ms
8,124 KB
testcase_04 AC 16 ms
8,056 KB
testcase_05 AC 16 ms
8,076 KB
testcase_06 AC 16 ms
8,076 KB
testcase_07 AC 17 ms
8,072 KB
testcase_08 AC 16 ms
8,108 KB
testcase_09 AC 17 ms
8,224 KB
testcase_10 AC 17 ms
8,164 KB
testcase_11 AC 16 ms
8,112 KB
testcase_12 AC 16 ms
8,164 KB
testcase_13 AC 72 ms
8,792 KB
testcase_14 AC 64 ms
8,772 KB
testcase_15 AC 66 ms
8,600 KB
testcase_16 AC 81 ms
8,648 KB
testcase_17 AC 76 ms
8,608 KB
testcase_18 AC 82 ms
8,856 KB
testcase_19 AC 71 ms
8,956 KB
testcase_20 AC 85 ms
8,796 KB
testcase_21 AC 72 ms
8,716 KB
testcase_22 AC 78 ms
8,772 KB
testcase_23 AC 90 ms
8,856 KB
testcase_24 AC 85 ms
8,528 KB
testcase_25 AC 94 ms
8,608 KB
testcase_26 AC 95 ms
8,972 KB
testcase_27 AC 92 ms
9,044 KB
testcase_28 AC 96 ms
8,892 KB
testcase_29 AC 96 ms
8,932 KB
testcase_30 AC 94 ms
8,788 KB
testcase_31 AC 93 ms
8,888 KB
testcase_32 AC 91 ms
8,744 KB
testcase_33 AC 91 ms
8,668 KB
testcase_34 AC 93 ms
8,760 KB
testcase_35 AC 83 ms
8,788 KB
testcase_36 AC 84 ms
8,560 KB
testcase_37 AC 83 ms
8,568 KB
testcase_38 AC 76 ms
8,616 KB
testcase_39 AC 87 ms
8,956 KB
testcase_40 AC 94 ms
8,824 KB
testcase_41 AC 98 ms
9,080 KB
testcase_42 AC 100 ms
8,876 KB
testcase_43 AC 99 ms
8,972 KB
testcase_44 AC 98 ms
8,928 KB
testcase_45 AC 96 ms
8,960 KB
testcase_46 AC 98 ms
8,800 KB
testcase_47 AC 96 ms
9,000 KB
testcase_48 AC 100 ms
8,888 KB
testcase_49 AC 100 ms
9,028 KB
testcase_50 AC 95 ms
9,124 KB
testcase_51 AC 99 ms
8,928 KB
testcase_52 AC 98 ms
9,032 KB
testcase_53 AC 100 ms
8,892 KB
testcase_54 AC 99 ms
9,092 KB
testcase_55 AC 98 ms
8,872 KB
testcase_56 AC 96 ms
9,080 KB
testcase_57 AC 97 ms
8,808 KB
testcase_58 AC 100 ms
9,036 KB
testcase_59 AC 59 ms
8,636 KB
testcase_60 AC 56 ms
8,564 KB
testcase_61 AC 58 ms
8,620 KB
testcase_62 AC 56 ms
8,864 KB
testcase_63 AC 58 ms
9,004 KB
testcase_64 AC 58 ms
8,976 KB
testcase_65 AC 59 ms
8,980 KB
testcase_66 AC 58 ms
8,724 KB
testcase_67 AC 58 ms
8,932 KB
testcase_68 AC 57 ms
8,936 KB
testcase_69 AC 58 ms
8,716 KB
testcase_70 AC 58 ms
8,976 KB
testcase_71 AC 57 ms
8,948 KB
testcase_72 AC 58 ms
8,736 KB
testcase_73 AC 57 ms
9,040 KB
testcase_74 AC 56 ms
9,060 KB
testcase_75 AC 16 ms
8,108 KB
testcase_76 AC 16 ms
7,996 KB
testcase_77 AC 68 ms
8,924 KB
testcase_78 AC 56 ms
8,700 KB
testcase_79 AC 91 ms
8,736 KB
testcase_80 AC 77 ms
8,792 KB
testcase_81 AC 77 ms
8,752 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)


def get_move(frm, to):
    x, y = frm
    tx, ty = to
    command = []
    while (x, y) != (tx, ty):
        if x + 1 <= tx:
            command.append('RLR')
            x += 1
        elif x - 1 >= tx:
            command.append('LRL')
            x -= 1
        elif y + 1 <= ty:
            command.append('UDU')
            y += 1
        elif y - 1 >= ty:
            command.append('DUD')
            y -= 1
        else:
            assert(False)

        if x + 1 <= tx:
            command.append('R')
            x += 1
        elif x - 1 >= tx:
            command.append('L')
            x -= 1
        elif y + 1 <= ty:
            command.append('U')
            y += 1
        elif y - 1 >= ty:
            command.append('D')
            y -= 1
        else:
            assert((x, y) == (tx, ty))

    return command


def solve(s, t):
    if s % 2 != t % 2:
        return ''.join(get_move(to_xy(s), to_xy(t)))
    else:
        ans = []
        if s % 2 == 1:
            ans += get_move(to_xy(s), to_xy(4))
            ans.append('DRUL')
            ans += get_move(to_xy(4), to_xy(t))
        else:
            ans += get_move(to_xy(s), to_xy(1))
            ans.append('RULDUD')
            ans += get_move(to_xy(1), to_xy(t))
        return ''.join(ans)


s, t = map(int, input().split())
ans = solve(s, t)
print(0, len(ans), ans, sep='\n')
0