結果

問題 No.3 ビットすごろく
ユーザー kwnwsdnckwnwsdnc
提出日時 2018-03-29 23:45:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 745 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 8,976 KB
最終ジャッジ日時 2023-09-08 06:50:29
合計ジャッジ時間 16,729 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,800 KB
testcase_01 AC 16 ms
7,784 KB
testcase_02 AC 15 ms
7,792 KB
testcase_03 RE -
testcase_04 AC 16 ms
7,772 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 17 ms
7,836 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 16 ms
7,932 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 15 ms
7,732 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 15 ms
7,872 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def count(n):
    a=0
    num=str(bin(n))
    ln=len(num)
    for i in range(ln):
        if num[i]=='1':
            a+=1
    return a

def minus(m,i):
    n=m[i]
    if i==0:
        return -1
    if (str(n-count(n)) in str(m))==False:
        return n-count(n)
    else:
        return minus(m,i-1)
        
def sugoroku(N):
    p=[]
    p.append(1)
    i=0
    if N==1:
        return 0
    while 1>0:
        if p[i]+count(p[i])==N:
            return i+1+1
        elif p[i]+count(p[i])<N:
            p.append(p[i]+count(p[i]))
            i+=1
        else:
            if minus(p,i)==-1:
                return -1
            else:
                p.append(minus(p,i))
                i+=1           


N=int(input())
print(sugoroku(N))
0