結果

問題 No.915 Plus Or Multiple Operation
ユーザー QCFiumQCFium
提出日時 2019-11-01 15:11:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 165,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 18:53:27
合計ジャッジ時間 2,388 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int64_t solve(int a, int b, int c) {
	if (c == 1) return (int64_t) b * a;
	std::vector<int> keta;
	for (; a; a /= c) keta.push_back(a % c);
	std::reverse(keta.begin(), keta.end());
	if (keta.size() == 1) return b;
	int64_t res = 0;
	if (keta[0] == 1 && keta[1] < c - 1) res += 2;
	else res += !!keta[1] + 2;
	int head = 2;
	for (; head < (int) keta.size(); head++) {
		if (keta[head]) res++;
		res++;
	}
	return res * b;
}

int main() {
	int q = ri();
	for (int i = 0; i < q; i++) {
		int a = ri(), b = ri(), c = ri();
		std::cout << solve(a, b, c) << std::endl;
	}
	
	return 0;
}
0