結果

問題 No.915 Plus Or Multiple Operation
ユーザー square1001square1001
提出日時 2020-09-03 16:23:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 593 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 72,848 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 19:00:14
合計ジャッジ時間 1,239 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

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 == 0 ? 0 : i / C + 1);
				}
				ops = min(ops, cost);
			} while (C != 1 && seq.back() >= C);
			cout << 1LL * ops * B << endl;
		}
	}
	return 0;
}
0