結果

問題 No.782 マイナス進数
ユーザー Haar
提出日時 2019-01-11 23:52:20
言語 C++14
(gcc 8.2.0)
結果
AC  
実行時間 37 ms
コード長 2,168 Byte
コンパイル時間 1,523 ms
使用メモリ 8,916 KB
最終ジャッジ日時 2019-01-11 23:52:32

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
00_sample1.txt AC 2 ms
6,872 KB
00_sample2.txt AC 1 ms
6,872 KB
10_small_00.txt AC 28 ms
6,872 KB
10_small_01.txt AC 27 ms
6,868 KB
10_small_02.txt AC 28 ms
6,868 KB
10_small_03.txt AC 28 ms
6,868 KB
10_small_04.txt AC 30 ms
6,872 KB
10_small_05.txt AC 35 ms
6,872 KB
10_small_06.txt AC 28 ms
6,872 KB
10_small_07.txt AC 37 ms
6,872 KB
10_small_08.txt AC 28 ms
6,872 KB
11_large_00.txt AC 30 ms
6,872 KB
11_large_01.txt AC 30 ms
6,868 KB
11_large_02.txt AC 35 ms
6,872 KB
11_large_03.txt AC 30 ms
6,872 KB
11_large_04.txt AC 31 ms
6,868 KB
11_large_05.txt AC 29 ms
6,868 KB
11_large_06.txt AC 33 ms
6,868 KB
11_large_07.txt AC 30 ms
6,868 KB
11_large_08.txt AC 33 ms
6,872 KB
12_random_00.txt AC 30 ms
6,872 KB
12_random_01.txt AC 34 ms
6,872 KB
12_random_02.txt AC 30 ms
6,868 KB
12_random_03.txt AC 29 ms
6,872 KB
12_random_04.txt AC 35 ms
6,868 KB
12_random_05.txt AC 30 ms
6,872 KB
12_random_06.txt AC 31 ms
6,868 KB
12_random_07.txt AC 30 ms
6,872 KB
12_random_08.txt AC 30 ms
6,868 KB
20_corner_00.txt AC 2 ms
6,868 KB
20_corner_01.txt AC 2 ms
6,872 KB
20_corner_02.txt AC 2 ms
8,916 KB
20_corner_03.txt AC 1 ms
6,872 KB
20_corner_04.txt AC 2 ms
6,872 KB
20_corner_05.txt AC 1 ms
6,872 KB
20_corner_06.txt AC 2 ms
6,868 KB
20_corner_07.txt AC 1 ms
6,872 KB
20_corner_08.txt AC 3 ms
6,872 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