結果

問題 No.915 Plus Or Multiple Operation
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-10-25 22:11:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,005 bytes
コンパイル時間 1,769 ms
コンパイル使用メモリ 164,488 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-24 18:42:43
合計ジャッジ時間 2,007 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 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>

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 << c * b << 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();
    }
}
0