結果

問題 No.782 マイナス進数
ユーザー WataruaokiWataruaoki
提出日時 2019-01-21 22:15:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 3,357 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 210,024 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-13 17:22:25
合計ジャッジ時間 4,220 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 6 ms
4,352 KB
testcase_03 AC 7 ms
4,348 KB
testcase_04 AC 8 ms
4,352 KB
testcase_05 AC 6 ms
4,352 KB
testcase_06 AC 6 ms
4,352 KB
testcase_07 AC 9 ms
4,352 KB
testcase_08 AC 6 ms
4,352 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 6 ms
4,352 KB
testcase_11 AC 10 ms
4,348 KB
testcase_12 AC 9 ms
4,348 KB
testcase_13 AC 20 ms
4,352 KB
testcase_14 AC 10 ms
4,348 KB
testcase_15 AC 10 ms
4,356 KB
testcase_16 AC 10 ms
4,352 KB
testcase_17 AC 14 ms
4,348 KB
testcase_18 AC 9 ms
4,348 KB
testcase_19 AC 12 ms
4,352 KB
testcase_20 AC 9 ms
4,352 KB
testcase_21 AC 13 ms
4,352 KB
testcase_22 AC 10 ms
4,352 KB
testcase_23 AC 9 ms
4,352 KB
testcase_24 AC 19 ms
4,356 KB
testcase_25 AC 10 ms
4,348 KB
testcase_26 AC 11 ms
4,352 KB
testcase_27 AC 11 ms
4,352 KB
testcase_28 AC 9 ms
4,356 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 1 ms
4,368 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

using vc = vector<char>;
using vcc = vector<vc>;
using vb = vector<bool>;
using vbb = vector<vb>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using vd = vector<double>;
using vdd = vector<vd>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

vector<pii> prime_factorization(int n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pii> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}
vector<pli> prime_factorization(ll n){ // 素因数分解をしたvector<素数, 指数>を返す
  vector<pli> res;
  int tmp, root_n = floor(sqrt(n));
  if(n % 2 == 0){
    tmp = 1;
    n /= 2;
    while(n % 2 == 0){
      n /= 2;
      tmp++;
    }
    res.push_back(make_pair(2, tmp));
  }
  ll i = 3;
  while(i <= root_n && i <= n){
    if(n % i == 0){
      tmp = 1;
      n /= i;
      while(n % i == 0){
        n /= i;
        tmp++;
      }
      res.push_back(make_pair(i, tmp));
    }
    i += 2;
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}

// n は 2以上の素数表を返す
vb Primes(int n){
  vector<bool> res(n + 1, true);
  res.at(0) = false; res.at(1) = false;
  for(int i = 2; i <= sqrt(n); i++){
    if(res.at(i)){
      for(int j = 2 * i; j <= n; j += i){
        res.at(j) = false;
      }
    }
  }
  return res;
}
// ===================================================


class m_digit{
public:
  m_digit(int d);
  ~m_digit();
  std :: string turn_to_new_digit(int k);
  void warizan(int x, int &q, int &r);
private:
  int decimal;
  unsigned int abs_decimal;
};

m_digit :: m_digit(int d){
  decimal = d;
  abs_decimal = abs(d);
}
m_digit :: ~m_digit(){}

// d = qx + r : 0 <= r < x
void m_digit :: warizan(int x, int &q, int &r){
  if(x == 0){q = 0; r = 0;}
  else if(x < 0){
    int xx = -x;
    q = (xx / abs_decimal); r = xx % abs_decimal;
    if(r != 0){
      q++; r = abs_decimal - r;
    }
  }
  else{
    q = -(x / abs_decimal); r = x % abs_decimal;
  }
}

std :: string m_digit :: turn_to_new_digit(int k){
  std :: string res = "";
  int r;
  do{
    // cout << "k = " << k << ", r = " << r << "\n";
    warizan(k, k, r);
    res = (char)('0' + r) + res;
  }while(k != 0);
  return res;
}


int main(){
  int t, b;
  cin >> t >> b;
  m_digit solve(b);
  vi data(t);
  REP(i, t) cin >> data.at(i);
  REP(i, t){
    cout << solve.turn_to_new_digit(data.at(i)) << "\n";
  }
  return 0;
}
0