結果

問題 No.782 マイナス進数
ユーザー rtia_iidxrtia_iidx
提出日時 2019-01-11 21:47:06
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,278 bytes
コンパイル時間 897 ms
使用メモリ 4,424 KB
最終ジャッジ日時 2023-01-06 10:45:31
合計ジャッジ時間 3,145 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,596 KB
testcase_01 AC 2 ms
3,520 KB
testcase_02 AC 17 ms
3,840 KB
testcase_03 AC 18 ms
3,712 KB
testcase_04 AC 18 ms
3,832 KB
testcase_05 AC 18 ms
3,712 KB
testcase_06 AC 17 ms
3,928 KB
testcase_07 AC 21 ms
3,788 KB
testcase_08 AC 19 ms
3,720 KB
testcase_09 AC 17 ms
3,852 KB
testcase_10 AC 17 ms
3,920 KB
testcase_11 AC 22 ms
3,932 KB
testcase_12 AC 21 ms
3,920 KB
testcase_13 AC 31 ms
4,424 KB
testcase_14 AC 21 ms
3,880 KB
testcase_15 AC 21 ms
3,716 KB
testcase_16 AC 20 ms
3,824 KB
testcase_17 AC 26 ms
4,256 KB
testcase_18 AC 20 ms
3,924 KB
testcase_19 AC 24 ms
4,296 KB
testcase_20 AC 21 ms
3,896 KB
testcase_21 AC 25 ms
4,296 KB
testcase_22 AC 21 ms
3,928 KB
testcase_23 AC 20 ms
3,924 KB
testcase_24 AC 31 ms
4,296 KB
testcase_25 AC 20 ms
3,876 KB
testcase_26 AC 23 ms
3,716 KB
testcase_27 AC 21 ms
3,872 KB
testcase_28 AC 20 ms
3,828 KB
testcase_29 AC 2 ms
3,500 KB
testcase_30 AC 2 ms
3,464 KB
testcase_31 AC 1 ms
3,528 KB
testcase_32 AC 2 ms
3,552 KB
testcase_33 AC 1 ms
3,508 KB
testcase_34 AC 1 ms
3,508 KB
testcase_35 AC 1 ms
3,404 KB
testcase_36 AC 1 ms
3,564 KB
testcase_37 AC 2 ms
3,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll t,b;
    cin >> t >> b;

    vector<ll> n(t);
    vector<string> ans;
    
    for(int i = 0; i < t; i++){
        cin >> n[i];
    }

    for(int i = 0; i < t; i++){
        stack<ll> tmp;
        ll x = 1;
        while(n[i] != 0){
            ll a = n[i]%abs(b);
            if(x > 0){
                tmp.push(a);
                n[i] -= a;
            }else{
                tmp.push((abs(b)-a)%abs(b));
                n[i] += (abs(b)-a)%abs(b);
            }
            n[i] /= abs(b);
            x *= -1;
        }
        ans.push_back("");
        if(tmp.empty()){
            ans.back() += '0';
        }
        while(!tmp.empty()){
            ans.back() += (char)('0' + tmp.top());
            tmp.pop();
        }
    }

    for(int i = 0; i < t; i++){
        cout << ans[i] << endl;
    }

    return 0;
}
0