結果

問題 No.782 マイナス進数
ユーザー kagasankagasan
提出日時 2020-04-25 17:56:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,794 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 168,764 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 07:43:29
合計ジャッジ時間 4,367 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

const ll X = 70;

int main(){

    ll N, B;
    cin >> N >> B;
    B = -B;

    ll hoge[X][10];
    for(ll i = 0, p = 1; i < X; i++, p *= (-B)){
        rep(j, B){
            hoge[i][j] = j * p;
        }
    }
    ll mn[X], mx[X];
    mn[0] = 0;
    mx[0] = B - 1;
    for(ll i = 1; i < X; i++){
        mn[i] = mn[i - 1];
        mx[i] = mx[i - 1];
        if(hoge[i][B - 1] > 0)mx[i] += hoge[i][B - 1];
        else mn[i] += hoge[i][B - 1];
    }
    rep(n, N){
        ll t;
        cin >> t;
        ll idx = 0;
        rep(i, X)if(mn[i] <= t && t <= mx[i]){
            idx = i;
            break;
        }         
        for(;idx > 0;idx--){
            rrep(j, B){
                ll tmp = t - hoge[idx][j];
                if(mn[idx - 1] <= tmp && tmp <= mx[idx - 1]){
                    cout << j;
                    t = tmp;
                    break;
                }
            }
        }
        rep(j, B)if(hoge[idx][j] == t)cout << j;
        cout << endl;
    }
    

    return 0;
}
0