結果

問題 No.782 マイナス進数
ユーザー どららどらら
提出日時 2019-01-11 23:36:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 971 bytes
コンパイル時間 1,809 ms
コンパイル使用メモリ 169,072 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-20 11:43:29
合計ジャッジ時間 4,388 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 27 ms
4,380 KB
testcase_03 AC 28 ms
4,380 KB
testcase_04 AC 28 ms
4,380 KB
testcase_05 AC 27 ms
4,380 KB
testcase_06 AC 27 ms
4,380 KB
testcase_07 AC 30 ms
4,380 KB
testcase_08 AC 28 ms
4,380 KB
testcase_09 AC 26 ms
4,376 KB
testcase_10 AC 25 ms
4,384 KB
testcase_11 AC 31 ms
4,380 KB
testcase_12 AC 31 ms
4,376 KB
testcase_13 AC 45 ms
4,376 KB
testcase_14 AC 32 ms
4,380 KB
testcase_15 AC 33 ms
4,380 KB
testcase_16 AC 32 ms
4,380 KB
testcase_17 AC 37 ms
4,384 KB
testcase_18 AC 32 ms
4,380 KB
testcase_19 AC 35 ms
4,380 KB
testcase_20 AC 32 ms
4,380 KB
testcase_21 AC 38 ms
4,380 KB
testcase_22 AC 33 ms
4,376 KB
testcase_23 AC 31 ms
4,376 KB
testcase_24 AC 43 ms
4,384 KB
testcase_25 AC 32 ms
4,380 KB
testcase_26 AC 35 ms
4,380 KB
testcase_27 AC 33 ms
4,380 KB
testcase_28 AC 32 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

string solve(ll N, ll B){
  vector<int> v(60, 0);

  while(N != 0){
    ll p, q, r = 1, sum = 0;
    if(N > 0){
      p = 1;
      q = 0;
    }else{
      p = B;
      q = 1;
    }
    while(abs(sum + p*r) < abs(N)){
      r++;
      if(r == abs(B)){
        sum += p * (abs(B)-1);
        p *= B * B;
        q += 2;
        r = 1;
      }
    }
    v[q] = r;
    N -= p*r;
  }

  stringstream ss;
  bool flg = false;
  for(int i=v.size()-1; i>=0; i--){
    if(v[i] != 0) flg = true;
    if(flg) ss << v[i];
  }
  
  return ss.str();
}

int main(){
  int T, B;
  cin >> T >> B;
  rep(i,T){
    int n;
    cin >> n;
    cout << solve(n, B) << endl;
  }
  
  return 0;
}
0