結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| ユーザー |
|
| 提出日時 | 2024-12-10 01:25:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,326 bytes |
| コンパイル時間 | 317 ms |
| コンパイル使用メモリ | 82,544 KB |
| 実行使用メモリ | 68,224 KB |
| 最終ジャッジ日時 | 2024-12-10 01:25:35 |
| 合計ジャッジ時間 | 1,952 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 2 |
ソースコード
## https://yukicoder.me/problems/no/915
from collections import deque
def main():
Q = int(input())
abc = []
for _ in range(Q):
a, b, c = map(int, input().split())
abc.append((a, b ,c))
for a, b, c in abc:
if c == 1:
print(a * b)
continue
queue = deque()
b_map = {a: 0}
queue.append(a)
while len(queue) > 0:
x = queue.popleft()
if x == 0:
break
if x % c == 0:
d = x // c
if d not in b_map:
b_map[d] = b_map[x] + 1
queue.append(d)
if x - (c - 1) >= 0:
e = x - (c - 1)
if e not in b_map:
b_map[e] = b_map[x] + 1
queue.append(e)
else:
d = x - (x % c)
if d not in b_map:
b_map[d] = b_map[x] + 1
queue.append(d)
if x - (c - 1)>= 0:
e = x - (c - 1)
if e not in b_map:
b_map[e] = b_map[x] + 1
queue.append(e)
print(b_map[0] * b)
if __name__ == "__main__":
main()