結果

問題 No.915 Plus Or Multiple Operation
ユーザー LayCurseLayCurse
提出日時 2019-10-25 21:30:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,942 bytes
コンパイル時間 2,586 ms
コンパイル使用メモリ 205,368 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 18:31:39
合計ジャッジ時間 3,326 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 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 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int Lj4PdHRW;
  int A;
  int B;
  int C;
  long long res;
  int KL2GvlyY = rd_int();
  for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
    rd(A);
    rd(B);
    rd(C);
    if(C==1){
      wt_L(-1);
      wt_L('\n');
      continue;
    }
    res = 0;
    for(;;){
      if(C <= A  &&  A <= 2*(C-1)){
        res += 2*B;
        break;
      }
      if(A%C){
        res += B;
        A -= (A%C);
      }
      if(!A){
        break;
      }
      A /= C;
      res += B;
    }
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191012-1

// --- original code ---
// {
//   int A, B, C;
//   ll res;
//   REP(rd_int()){
//     rd(A,B,C);
//     if(C==1) wt(-1), continue;
//     res = 0;
//     for(;;){
//       if(C <= A <= 2(C-1)) res += 2B, break;
//       if(A%C) res += B, A -= (A%C);
//       if(!A) break;
//       A /= C; res += B;
//     }
//     wt(res);
//   }
// }
0