結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2019-10-25 23:04:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 769 bytes |
| コンパイル時間 | 1,649 ms |
| コンパイル使用メモリ | 167,532 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-07 03:37:41 |
| 合計ジャッジ時間 | 2,193 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
ll solve(ll A, ll B, ll C){
if(C == 1) return -1;
if(A < C) return B;
ll ret = 100000000000LL;
ll x = 0;
while(true){
ret = min(ret, x + (A+C-2)/(C-1));
if(A%C > 0){
x++;
A -= A%C;
}
if(A == 0) break;
ret = min(ret, x + (A+C-2)/(C-1));
x++;
A /= C;
}
return B * ret;
}
int main(){
int Q;
cin >> Q;
rep(i,Q){
ll A, B, C;
cin >> A >> B >> C;
cout << solve(A, B, C) << endl;
}
return 0;
}
どらら