結果

問題 No.915 Plus Or Multiple Operation
ユーザー やむなくやむなく
提出日時 2019-10-25 21:54:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,630 bytes
コンパイル時間 1,531 ms
コンパイル使用メモリ 170,252 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 00:19:07
合計ジャッジ時間 2,314 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//
// Created by yamunaku on 2019/10/25.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int q;
    cin >> q;
    rep(_, q){
        ll a, b, c;
        cin >> a >> b >> c;
        if(c == 1){
            cout << -1 << endl;
            continue;
        }
        ll sz = 1, tmp = 1;
        while(tmp < a) tmp *= c, sz++;
        mti cost(sz, vi(sz, 0));
        rep(i, sz){
            repl(j, i, sz){
                ll tmp = a, t1 = 1, t2 = 1;
                rep(k, sz - 1 - j) t1 *= c;
                rep(k, sz - i) t2 *= c;
                tmp /= t1;
                tmp %= (t2/t1);
                cost[i][j] = (tmp + c - 2) / (c - 1);
            }
        }
        vl dp(sz);
        rep(i, sz){
            dp[i] = cost[0][i] + (sz - 1 - i);
            rep(j, i){
                dp[i] = min(dp[i], dp[j] + cost[j + 1][i]);
            }
        }
        cout << dp[sz - 1] * b << endl;
    }
    return 0;
}
0