結果

問題 No.915 Plus Or Multiple Operation
ユーザー square1001
提出日時 2020-09-03 16:08:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 72,768 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-07 03:50:13
合計ジャッジ時間 1,405 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int main() {
	int Q;
	cin >> Q;
	while (Q--) {
		int A, B, C;
		cin >> A >> B >> C;
		if (C == 1) {
			cout << -1 << endl;
		}
		else {
			int ops = inf;
			vector<int> seq = { A };
			do {
				int x = seq.back();
				seq.back() %= C;
				seq.push_back(x / C);
				int cost = int(seq.size()) - 1;
				for (int i : seq) {
					cost += (i + C - 2) / (C - 1);
				}
				ops = min(ops, cost);
			} while (C != 1 && seq.back() >= C);
			cout << 1LL * ops * B << endl;
		}
	}
	return 0;
}
0