結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-26 23:27:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 2,000 ms |
| コード長 | 450 bytes |
| コンパイル時間 | 161 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 52,352 KB |
| 最終ジャッジ日時 | 2024-06-28 07:31:58 |
| 合計ジャッジ時間 | 1,403 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
dic = {}
a = b = c = 0
def dfs(x):
global dic,b,c
if x == 0:
return 0
if x in dic:
return dic[x]
c1 = (x+c-2)//(c-1)*b
c2 = b+dfs(x//c)
if x%c:
c2 += b
dic[x] = min(c1,c2)
return dic[x]
def solve():
global dic,a,b,c
a,b,c = map(int,input().split())
if c == 1:
return -1
dic = {}
return dfs(a)
q = int(input())
for _ in range(q):
print(solve())