結果
| 問題 | No.915 Plus Or Multiple Operation |
| コンテスト | |
| ユーザー |
brthyyjp
|
| 提出日時 | 2022-01-31 16:41:06 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 535 bytes |
| 記録 | |
| コンパイル時間 | 131 ms |
| コンパイル使用メモリ | 85,296 KB |
| 実行使用メモリ | 53,984 KB |
| 最終ジャッジ日時 | 2026-03-04 11:03:12 |
| 合計ジャッジ時間 | 1,032 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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