結果

問題 No.915 Plus Or Multiple Operation
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-10-25 23:04:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,244 bytes
コンパイル時間 1,848 ms
コンパイル使用メモリ 169,088 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 18:47:58
合計ジャッジ時間 2,095 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

    if(c == 1) {
        cout << c * b << endl;
        return;
    }

    ll c_pow = 1LL, ci = 0LL;
    for(ci=0;c_pow*c<=a;++ci) {
        c_pow = c_pow * c;
    }

    deque<ll> digits;
    ll a_copy = a, c_pow_copy = c_pow;
    for(ll i=0;i<=ci;++i) {
        digits.push_back(a_copy/c_pow_copy);
        a_copy -= a_copy / c_pow_copy * c_pow_copy;
        c_pow_copy /= c;
    }

    for(int i=0;i<ci;++i) {
        if(digits[i] == 1) {
            digits[i+1] += c;
            digits[i] = 0;
        }
    }
    while(digits.front() == 0) digits.pop_front();

    for(int i=0;i<digits.size();++i) {
        if(digits[i]) {
            ans += (digits[i]+c-2)/(c-1);
        }
        ++ans;
    }
    --ans;

    ans *= b;
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int q;
    cin >> q;
    while(q--) {
        solve();
    }
}
0