結果

問題 No.915 Plus Or Multiple Operation
ユーザー ganariyaganariya
提出日時 2019-10-25 21:59:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,775 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 140,828 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 18:39:55
合計ジャッジ時間 1,880 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------


int main() {

    int Q;
    cin >> Q;

    while (Q--) {
        LL A, B, C;
        cin >> A >> B >> C;

        if (C == 1) {
            cout << A * B << endl;
            continue;
        }

        string ans = "";
        LL cnt = 1;
        while (A != 0) {
            if (A > C && A <= 2 * C) {
                cnt += 2;
                if (A != 2 * C)cnt++;
                break;
            }
            if (A % C == 0) ans += '0';
            else ans += '1';
            A /= C;
        }
        reverse(ans.begin(), ans.end());
        for (int i = 1; i < ans.size(); i++) {
            if (ans[i] != '0')cnt++;
            cnt++;
        }
        cout << cnt * B << endl;
    }

    return 0;
}









































0