結果

問題 No.3 ビットすごろく
ユーザー yama6k16yama6k16
提出日時 2019-11-30 23:16:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,005 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 8,604 KB
最終ジャッジ日時 2023-08-13 09:55:17
合計ジャッジ時間 2,544 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,356 KB
testcase_01 AC 16 ms
8,244 KB
testcase_02 AC 16 ms
8,324 KB
testcase_03 AC 19 ms
8,112 KB
testcase_04 AC 17 ms
8,312 KB
testcase_05 AC 22 ms
8,420 KB
testcase_06 AC 19 ms
8,460 KB
testcase_07 AC 18 ms
8,008 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 22 ms
8,396 KB
testcase_13 AC 18 ms
8,400 KB
testcase_14 AC 25 ms
8,528 KB
testcase_15 AC 27 ms
8,396 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 18 ms
8,276 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 16 ms
8,296 KB
testcase_22 AC 26 ms
8,428 KB
testcase_23 AC 27 ms
8,452 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 16 ms
8,424 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 17 ms
8,244 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
N = int(input())
current = [0] * (N + 1)
current[0] = 1
bit =  [0] * (N + 1)
bit[0] = 1
P = 0
if N == 1:
    print(1)
else:
    for i in range(1, N + 1):
        forward = 0
        bit[i] = current[i - 1]
        while bit[i] >= 1:
            if bit[i] % 2 == 1:
                forward += 1
                bit[i] = math.floor(bit[i]/2)
            else:
                bit[i] = int(bit[i]/2)
            #print(forward)   
        current[i] = current[i - 1] + forward
        if current[i] < N:
            current[i] = current[i]
        elif current[i] > N:
            current[i] = current[i-1] - forward
            for j in range(i):
                pen = current[j] - current[i]
                if pen == 0:
                    P += 1
            
    
        if current[i] == N:
            print(i + 1)
            break
        elif (current[i] > N) or (current[i] < 1):
            print(-1)
            break
        if P > 0:
            print(-1)
            break
        
0