結果

問題 No.915 Plus Or Multiple Operation
ユーザー mamekinmamekin
提出日時 2019-10-25 21:52:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,455 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 126,828 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-07 00:18:36
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int q;
    cin >> q;
    while(--q >= 0){
        int a, b, c;
        cin >> a >> b >> c;
        if(c == 1){
            cout << (a * (long long)b) << endl;
            continue;
        }

        set<int> s;
        queue<int> q;
        s.insert(a);
        q.push(a);

        long long ans = 0;
        while(*s.begin() != 0){
            ans += b;
            int n = q.size();
            while(--n >= 0){
                int x = q.front();
                q.pop();

                vector<int> v = {x / c * c};
                if(x % c == 0)
                    v.push_back(x / c);
                if(c - 1 <= x)
                    v.push_back(x - (c - 1));

                for(int y : v){
                    if(s.find(y) == s.end()){
                        s.insert(y);
                        q.push(y);
                    }
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}
0