結果

問題 No.915 Plus Or Multiple Operation
コンテスト
ユーザー roaris
提出日時 2019-10-26 01:27:50
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 867 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 147 ms
コンパイル使用メモリ 85,768 KB
実行使用メモリ 54,180 KB
最終ジャッジ日時 2026-05-07 11:59:54
合計ジャッジ時間 1,262 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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