結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| ユーザー |
brthyyjp
|
| 提出日時 | 2022-01-31 16:41:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 2,000 ms |
| コード長 | 535 bytes |
| コンパイル時間 | 153 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 52,096 KB |
| 最終ジャッジ日時 | 2024-06-11 08:59:01 |
| 合計ジャッジ時間 | 1,279 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
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)
brthyyjp