結果

問題 No.915 Plus Or Multiple Operation
ユーザー fine
提出日時 2019-10-25 23:27:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 797 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 170,404 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-07 03:39:08
合計ジャッジ時間 2,165 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll solve(ll a, ll b, ll c) {
    if (c == 1) return -1;

    vector<ll> v;
    ll aa = a;
    while (aa > 0) {
        v.push_back(aa % c);
        aa /= c;
    }
    reverse(v.begin(), v.end());

    int sz = v.size();
    if (sz == 1) return 1;

    ll ans = 0;
    if (v[1] == 0) ans += 2;
    else if (v[0] * c + v[1] <= 2 * (c - 1)) ans += 2;
    else ans += 3;

    ans += max(sz - 2, 0);
    for (int i = 2; i < sz; i++) {
        ans += (v[i] > 0);
    }
    ans *= b;
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        cout << solve(a, b, c) << "\n";
    }
    return 0;
}
0