結果

問題 No.915 Plus Or Multiple Operation
ユーザー roarisroaris
提出日時 2019-10-26 01:27:50
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 867 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 71,492 KB
最終ジャッジ日時 2023-08-07 00:32:52
合計ジャッジ時間 2,003 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
70,856 KB
testcase_01 AC 71 ms
71,088 KB
testcase_02 AC 71 ms
70,864 KB
testcase_03 AC 70 ms
71,492 KB
testcase_04 WA -
testcase_05 AC 71 ms
71,184 KB
testcase_06 AC 72 ms
71,284 KB
testcase_07 AC 71 ms
71,224 KB
testcase_08 AC 69 ms
71,060 KB
testcase_09 AC 70 ms
71,084 KB
testcase_10 WA -
testcase_11 AC 70 ms
71,248 KB
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

Q = int(input())

for i in range(Q):
    A, B, C = map(int, input().split())
    
    if C == 1:
        print(-1)
        continue
    
    bit = []
    
    while A >= C:
        bit.append(A%C)
        A //= C
    
    bit.append(A)
    bit.reverse()
    n = len(bit)
    
    if n == 1:
        print(1)
        continue
    
    if bit[0]*C+bit[1] <= 2*C-2:
        if n == 2:
            print(2)
            continue
        
        ope = 3 #足して足してビットシフト
        
        for i in range(2, n):
            if bit[i] != 0:
                ope += 1 #足す
            
            if i < n-1:
                ope += 1 #ビットシフト
    else:
        ope = 0
        
        for i in range(n):
            if bit[i] != 0:
                ope += 1
            
            if i < n-1:
                ope += 1
    
    print(B*ope)
0