結果

問題 No.915 Plus Or Multiple Operation
ユーザー beetbeet
提出日時 2019-10-25 22:19:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 837 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 197,564 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 18:43:33
合計ジャッジ時間 2,409 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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int q;
  cin>>q;
  while(q--){
    Int a,b,c;
    cin>>a>>b>>c;
    if(c==1){
      cout<<(a*b)<<endl;
      continue;
    }
    vector<Int> vs;
    while(a){
      vs.emplace_back(a%c);
      a/=c;
    }
    reverse(vs.begin(),vs.end());
    Int m=vs.size();
    //for(Int i=0;i<m;i++) cout<<i<<":"<<vs[i]<<endl;

    Int cnt=0;
    for(Int i=0;i<m;i++){
      if(i!=0) cnt++;
      if(vs[i]!=1||i+1>=m||vs[i+1]==0||vs[i+1]==c-1){
        if(vs[i]) cnt++;
        continue;
      }
      if(i!=0) cnt++;
      i++;cnt++;cnt++;
    }
    cout<<cnt*b<<endl;
  }
  return 0;
}
0