結果
問題 | No.915 Plus Or Multiple Operation |
ユーザー |
|
提出日時 | 2023-03-24 20:37:47 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 477 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-09-18 16:35:37 |
合計ジャッジ時間 | 1,440 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
import sys sys.setrecursionlimit(10**6) def rec(x, c): if x <= 0: return 0 if x in memo: return memo[x] if x % c == 0: memo[x] = min(rec(x // c, c) + 1, (x + c - 2) // (c - 1)) else: memo[x] = min(rec(x - x % c, c) + 1, (x + c - 2) // (c - 1)) return memo[x] for _ in range(int(input())): a, b, c = map(int, input().split()) if c == 1: print(-1) else: memo = dict() print(rec(a, c) * b)