結果

問題 No.915 Plus Or Multiple Operation
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-31 16:41:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 87,328 KB
実行使用メモリ 71,628 KB
最終ジャッジ日時 2023-09-02 02:19:25
合計ジャッジ時間 2,018 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,508 KB
testcase_01 AC 66 ms
71,352 KB
testcase_02 AC 68 ms
71,576 KB
testcase_03 AC 68 ms
71,344 KB
testcase_04 AC 70 ms
71,592 KB
testcase_05 AC 68 ms
71,372 KB
testcase_06 AC 67 ms
71,628 KB
testcase_07 AC 68 ms
71,284 KB
testcase_08 AC 66 ms
71,136 KB
testcase_09 AC 67 ms
71,500 KB
testcase_10 AC 67 ms
71,392 KB
testcase_11 AC 66 ms
71,600 KB
testcase_12 AC 69 ms
71,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
sys.setrecursionlimit(10**9)
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

q = int(input())
for _ in range(q):
    a, b, c = map(int, input().split())
    if c == 1:
        print(-1)
        continue
    memo = {}
    def dfs(x):
        if x == 0:
            return 0
        res = (x+c-2)//(c-1)
        if x == (x//c)*c:
            res = min(res, 1+dfs(x//c))
        else:
            res = min(res, 2+dfs(x//c))
        memo[x] = res
        return res
    ans = dfs(a)
    print(ans*b)
0