結果

問題 No.915 Plus Or Multiple Operation
ユーザー roarisroaris
提出日時 2019-10-26 01:25:17
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 743 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 65,408 KB
最終ジャッジ日時 2024-04-24 18:51:23
合計ジャッジ時間 1,481 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,840 KB
testcase_01 AC 43 ms
51,968 KB
testcase_02 AC 45 ms
51,840 KB
testcase_03 AC 43 ms
52,096 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 42 ms
52,096 KB
testcase_07 AC 42 ms
52,096 KB
testcase_08 AC 43 ms
51,712 KB
testcase_09 AC 41 ms
51,712 KB
testcase_10 RE -
testcase_11 AC 44 ms
52,224 KB
testcase_12 RE -
権限があれば一括ダウンロードができます

ソースコード

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 bit[0]*C+bit[1] <= 2*C-2:
        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