結果

問題 No.3 ビットすごろく
ユーザー takumijintakumijin
提出日時 2019-10-11 12:11:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 837 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 8,504 KB
最終ジャッジ日時 2023-08-15 22:17:15
合計ジャッジ時間 2,588 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,748 KB
testcase_01 AC 15 ms
7,832 KB
testcase_02 AC 14 ms
7,820 KB
testcase_03 AC 20 ms
8,304 KB
testcase_04 WA -
testcase_05 AC 29 ms
8,296 KB
testcase_06 AC 22 ms
8,236 KB
testcase_07 AC 18 ms
8,216 KB
testcase_08 AC 25 ms
8,232 KB
testcase_09 AC 31 ms
8,444 KB
testcase_10 WA -
testcase_11 AC 33 ms
8,332 KB
testcase_12 AC 28 ms
8,296 KB
testcase_13 WA -
testcase_14 AC 35 ms
8,456 KB
testcase_15 AC 40 ms
8,464 KB
testcase_16 AC 36 ms
8,444 KB
testcase_17 AC 40 ms
8,300 KB
testcase_18 AC 19 ms
8,340 KB
testcase_19 AC 40 ms
8,324 KB
testcase_20 AC 16 ms
7,884 KB
testcase_21 AC 15 ms
8,268 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 41 ms
8,504 KB
testcase_25 AC 41 ms
8,336 KB
testcase_26 AC 15 ms
8,308 KB
testcase_27 AC 21 ms
8,244 KB
testcase_28 WA -
testcase_29 AC 30 ms
8,336 KB
testcase_30 AC 15 ms
7,780 KB
testcase_31 AC 15 ms
7,776 KB
testcase_32 AC 29 ms
8,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
n=int(input())
if n==1:
    print(1)
    sys.exit()
if n==2:
    print(2)
    sys.exit()
data=[0]*(n+1)
data[2]=1
flag=[0]*(n+1)
flag[1]=1
flag[2]=1
que=[[2]]
count=2
while que:
    h=que.pop()
    H=[]
    for u in h:
        data[u]=count
        cnt=0
        for i in range(14):
            if (u>>i)&1==1:
                cnt+=1
        if u+cnt==n:
            print(count+1)
            break
        if u+cnt>n:
            if flag[2*n-u-cnt]==0:
                H.append(2*n-u-cnt)
                flag[2*n-u-cnt]=1
        else:
            if flag[u+cnt]==0:
                H.append(u+cnt)
                flag[u+cnt]=1
        if flag[u-cnt]==0:
            H.append(u-cnt)
            flag[u-cnt]=1
    else:
        if H:
            que.append(H)
        count+=1
        continue
    break
else:
    print(-1)
0