結果
| 問題 |
No.915 Plus Or Multiple Operation
|
| コンテスト | |
| ユーザー |
noisy_noimin
|
| 提出日時 | 2019-10-25 23:39:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,002 bytes |
| コンパイル時間 | 1,591 ms |
| コンパイル使用メモリ | 167,264 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-07 03:39:23 |
| 合計ジャッジ時間 | 2,089 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
{ 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
void solve() {
ll a, b, c, ans = INF;
cin >> a >> b >> c;
if(c == 1) {
cout << -1 << endl;
return;
}
ll c_pow = 1LL, ci = 0LL;
for(ci=0;c_pow<=a;++ci) {
ll tmpans = ci, c_pow_copy = c_pow, a_copy = a;
while(c_pow > 0LL) {
if(a/c_pow != 0) {
tmpans += (a/c_pow + c-2) / (c-1);
a -= a/c_pow*c_pow;
}
c_pow /= c;
}
ans = min(ans, tmpans);
c_pow = c_pow_copy * c;
a = a_copy;
}
ans *= b;
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int q;
cin >> q;
while(q--) {
solve();
}
}
noisy_noimin