結果

問題 No.782 マイナス進数
ユーザー HaarHaar
提出日時 2019-01-11 23:52:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,168 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 166,328 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-20 21:41:50
合計ジャッジ時間 4,134 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,504 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 16 ms
4,376 KB
testcase_03 AC 16 ms
4,376 KB
testcase_04 AC 17 ms
4,376 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 16 ms
4,380 KB
testcase_07 AC 19 ms
4,380 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 16 ms
4,376 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 23 ms
4,376 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 18 ms
4,376 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 18 ms
4,384 KB
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 18 ms
4,376 KB
testcase_21 AC 20 ms
4,380 KB
testcase_22 AC 18 ms
4,376 KB
testcase_23 AC 18 ms
4,380 KB
testcase_24 AC 23 ms
4,380 KB
testcase_25 AC 18 ms
4,380 KB
testcase_26 AC 19 ms
4,380 KB
testcase_27 AC 18 ms
4,376 KB
testcase_28 AC 18 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, const vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

string minus_base(int n, int base){
  string ret;
  if(n == 0) ret.push_back('0');
  while(n != 0){
    int r = n%abs(base);
    if(r<0) r += abs(base);
    n = (n-r)/base;
    ret.push_back('0'+r);
  }
  reverse(ALL(ret));
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int T,B; cin >> T >> B;
  REP(i,T){
    int N; cin >> N;
    auto ans = minus_base(N, B);
    cout << ans << endl;
  }
  
  return 0;
}
0