結果

問題 No.3 ビットすごろく
ユーザー arito_asuarito_asu
提出日時 2020-06-10 19:22:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 8,440 KB
最終ジャッジ日時 2023-09-05 17:40:38
合計ジャッジ時間 4,550 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,780 KB
testcase_01 WA -
testcase_02 AC 16 ms
7,960 KB
testcase_03 AC 32 ms
7,952 KB
testcase_04 WA -
testcase_05 AC 80 ms
7,852 KB
testcase_06 AC 35 ms
7,860 KB
testcase_07 AC 23 ms
7,968 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 77 ms
7,856 KB
testcase_13 WA -
testcase_14 AC 146 ms
7,776 KB
testcase_15 AC 214 ms
8,352 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 25 ms
7,860 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 15 ms
7,776 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 15 ms
7,876 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

inp = int(input())

def bitJusawi(goal):
    move = lambda x: list(map(int, list(bin(x)[2:]))).count(1)
    his = [] ; loc = 0; ops = 0; rem = goal - loc
    while goal != loc:
        his.append(loc)
        rem = goal - loc
        if ops == 0:
            ops = 1; loc = 1
        else:
            ops += 1
            rng = move(loc)
            if rem >= rng:
                loc += rng
            else:
                bounce = goal - ((loc + rng) - goal)
                if loc - rng < bounce:
                    loc = bounce
                else:
                    loc -= rng
        cond = []
        for i in range(2,goal//2+1,2):
            if ops >= i:
                h = i // 2
                cond.append(loc == his[-h] == his[-i])
        stuck = any(cond)
        if stuck:
            return -1
    
    return ops

print(bitJusawi(inp))
0