結果

問題 No.1315 渦巻洞穴
ユーザー convexineqconvexineq
提出日時 2020-12-12 12:18:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,960 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 81,856 KB
実行使用メモリ 73,008 KB
最終ジャッジ日時 2023-10-20 02:03:46
合計ジャッジ時間 9,016 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,628 KB
testcase_01 AC 38 ms
53,628 KB
testcase_02 AC 37 ms
53,628 KB
testcase_03 AC 38 ms
53,628 KB
testcase_04 AC 37 ms
53,628 KB
testcase_05 AC 38 ms
53,628 KB
testcase_06 AC 37 ms
53,628 KB
testcase_07 AC 37 ms
53,628 KB
testcase_08 AC 38 ms
53,628 KB
testcase_09 AC 38 ms
53,628 KB
testcase_10 AC 38 ms
53,628 KB
testcase_11 AC 38 ms
53,628 KB
testcase_12 AC 37 ms
53,628 KB
testcase_13 AC 48 ms
67,092 KB
testcase_14 AC 48 ms
65,808 KB
testcase_15 AC 44 ms
62,528 KB
testcase_16 AC 49 ms
65,024 KB
testcase_17 AC 47 ms
64,088 KB
testcase_18 AC 52 ms
68,440 KB
testcase_19 AC 53 ms
67,416 KB
testcase_20 AC 51 ms
68,536 KB
testcase_21 AC 50 ms
65,580 KB
testcase_22 AC 52 ms
67,664 KB
testcase_23 AC 51 ms
67,400 KB
testcase_24 AC 43 ms
61,660 KB
testcase_25 AC 55 ms
71,192 KB
testcase_26 AC 58 ms
73,008 KB
testcase_27 AC 57 ms
72,168 KB
testcase_28 AC 56 ms
71,848 KB
testcase_29 AC 55 ms
70,644 KB
testcase_30 AC 53 ms
69,756 KB
testcase_31 AC 51 ms
68,556 KB
testcase_32 AC 56 ms
71,152 KB
testcase_33 AC 54 ms
69,412 KB
testcase_34 AC 52 ms
68,156 KB
testcase_35 AC 53 ms
68,572 KB
testcase_36 AC 51 ms
66,212 KB
testcase_37 AC 43 ms
62,772 KB
testcase_38 AC 49 ms
65,028 KB
testcase_39 AC 52 ms
67,704 KB
testcase_40 AC 56 ms
70,480 KB
testcase_41 AC 59 ms
72,660 KB
testcase_42 AC 57 ms
71,648 KB
testcase_43 AC 58 ms
72,660 KB
testcase_44 AC 57 ms
71,648 KB
testcase_45 AC 58 ms
72,660 KB
testcase_46 AC 57 ms
71,648 KB
testcase_47 AC 59 ms
72,664 KB
testcase_48 AC 56 ms
71,648 KB
testcase_49 AC 57 ms
72,660 KB
testcase_50 AC 58 ms
72,660 KB
testcase_51 AC 57 ms
71,648 KB
testcase_52 AC 58 ms
72,660 KB
testcase_53 AC 56 ms
71,648 KB
testcase_54 AC 57 ms
72,660 KB
testcase_55 AC 57 ms
71,648 KB
testcase_56 AC 57 ms
72,660 KB
testcase_57 AC 56 ms
71,648 KB
testcase_58 AC 58 ms
72,664 KB
testcase_59 AC 50 ms
65,580 KB
testcase_60 AC 50 ms
65,580 KB
testcase_61 AC 50 ms
65,584 KB
testcase_62 AC 50 ms
65,580 KB
testcase_63 AC 58 ms
65,584 KB
testcase_64 AC 50 ms
65,584 KB
testcase_65 AC 50 ms
66,144 KB
testcase_66 AC 50 ms
65,584 KB
testcase_67 AC 51 ms
66,140 KB
testcase_68 AC 50 ms
65,584 KB
testcase_69 AC 50 ms
65,584 KB
testcase_70 AC 49 ms
66,144 KB
testcase_71 AC 49 ms
65,584 KB
testcase_72 AC 50 ms
65,584 KB
testcase_73 AC 49 ms
65,580 KB
testcase_74 AC 49 ms
65,580 KB
testcase_75 AC 37 ms
53,628 KB
testcase_76 AC 37 ms
53,628 KB
testcase_77 AC 50 ms
67,820 KB
testcase_78 AC 44 ms
63,352 KB
testcase_79 AC 50 ms
67,112 KB
testcase_80 AC 55 ms
70,756 KB
testcase_81 AC 55 ms
70,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def pos(a):
    r = int(a**0.5)
    if r%2==0: r -= 1
    x,y = r//2,-(r//2)
    if r*r == a: return x,y
    a -= r*r+1
    x += 1
    if a <= r:
        return x,y+a
    a -= r
    y += r
    if a <= r+1:
        return x-a,y
    a -= r+1
    x -= r+1
    if a <= r+1:
        return x,y-a
    a -= r+1
    y -= r+1
    if a <= r+1:
        return x+a,y

def num(x,y):
    v = max(abs(x),abs(y))
    a = (2*v+1)*(2*v+1)
    if x==v and y==-v: return a
    if y==-v:
        return a-(v-x)
    a -= 2*v
    if x==-v:
        return a-(y+v)
    a -= 2*v
    if y==v:
        return a-(x+v)
    a -= 2*v
    return a-(v-y)

def check(s,t,res):
    sx,sy = pos(s)
    for i in res:
        dx,dy = [(-1,0),(1,0),(0,1),(0,-1)]["LRUD".index(i)]
        sx += dx
        sy += dy
        s ^= num(sx,sy)
    assert num(sx,sy) == t
    assert s==0
    return
    
def go(dx,dy):
    #print(dx,dy,(dx+dy)%2,"dx,dy")
    #assert (dx+dy)%2 == 1
    res = []
    while 1:
        if dx > 0:
            res += ["R","L","R"]
            dx -= 1
        elif dx < 0:
            res += ["L","R","L"]
            dx += 1
        elif dy > 0:
            res += ["U","D","U"]
            dy -= 1
        elif dy < 0:
            res += ["D","U","D"]
            dy += 1
        if dx==0 and dy==0: break
        if dx > 0:
            res += ["R"]
            dx -= 1
        elif dx < 0:
            res += ["L"]
            dx += 1
        elif dy > 0:
            res += ["U"]
            dy -= 1
        elif dy < 0:
            res += ["D"]
            dy += 1
    return res

s,t = map(int,input().split())
sx,sy = pos(s)
tx,ty = pos(t)
if (sx+sy+tx+ty)%2:
    res = go(tx-sx,ty-sy)
else:
    if (sx+sy)%2 == 0:
        res = go(1-sx,-sy) #今2
        res += ["L","R","U","D"]#今2
        res += go(tx-1,ty)
    else:
        res = go(-sx,-sy) #今1
        res += ["R","U","D","L","R","L"]#今1
        res += go(tx,ty)

print(0)
print(len(res))
print("".join(res))
0