結果

問題 No.915 Plus Or Multiple Operation
ユーザー nadarenadare
提出日時 2019-10-25 22:15:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 443 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 7,996 KB
最終ジャッジ日時 2023-08-07 00:24:18
合計ジャッジ時間 1,042 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 16 ms
7,816 KB
testcase_02 AC 16 ms
7,996 KB
testcase_03 AC 16 ms
7,996 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 16 ms
7,804 KB
testcase_07 AC 16 ms
7,924 KB
testcase_08 AC 15 ms
7,812 KB
testcase_09 AC 16 ms
7,848 KB
testcase_10 RE -
testcase_11 AC 16 ms
7,880 KB
testcase_12 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def inpl(): return list(map(int, input().split()))

for _ in range(int(input())):
    a, b, c = inpl()
    if c == 1:
        print(a*b)
        continue

    Q = []
    ans = 0
    
    while a:
        a, m = divmod(a, c)
        Q.append(m)

    if (len(Q) >= 2) & (Q[-1] == 1) & (1 <= Q[-2] <= c-2):
        ans += 3
        Q.pop()
        Q.pop()
    
    while Q:
        x = Q.pop()
        ans += 1 + (x > 0)
    
    print(b*(ans-1))
0