結果
問題 |
No.915 Plus Or Multiple Operation
|
ユーザー |
|
提出日時 | 2019-10-26 01:28:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 869 bytes |
コンパイル時間 | 190 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 52,480 KB |
最終ジャッジ日時 | 2024-11-07 03:41:14 |
合計ジャッジ時間 | 1,272 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
Q = int(input()) for i in range(Q): A, B, C = map(int, input().split()) if C == 1: print(-1) continue bit = [] while A >= C: bit.append(A%C) A //= C bit.append(A) bit.reverse() n = len(bit) if n == 1: print(B) continue if bit[0]*C+bit[1] <= 2*C-2: if n == 2: print(2*B) continue ope = 3 #足して足してビットシフト for i in range(2, n): if bit[i] != 0: ope += 1 #足す if i < n-1: ope += 1 #ビットシフト else: ope = 0 for i in range(n): if bit[i] != 0: ope += 1 if i < n-1: ope += 1 print(B*ope)