結果

問題 No.782 マイナス進数
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-06-12 02:51:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,797 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 148,228 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 08:53:33
合計ジャッジ時間 3,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 30 ms
4,376 KB
testcase_03 AC 33 ms
4,376 KB
testcase_04 AC 35 ms
4,376 KB
testcase_05 AC 32 ms
4,376 KB
testcase_06 AC 31 ms
4,376 KB
testcase_07 AC 40 ms
4,380 KB
testcase_08 AC 32 ms
4,376 KB
testcase_09 AC 30 ms
4,380 KB
testcase_10 AC 31 ms
4,376 KB
testcase_11 AC 43 ms
4,376 KB
testcase_12 AC 42 ms
4,376 KB
testcase_13 AC 62 ms
4,376 KB
testcase_14 AC 41 ms
4,380 KB
testcase_15 AC 42 ms
4,380 KB
testcase_16 AC 41 ms
4,376 KB
testcase_17 AC 50 ms
4,376 KB
testcase_18 AC 41 ms
4,376 KB
testcase_19 AC 46 ms
4,380 KB
testcase_20 AC 42 ms
4,380 KB
testcase_21 AC 51 ms
4,376 KB
testcase_22 AC 43 ms
4,380 KB
testcase_23 AC 41 ms
4,380 KB
testcase_24 AC 62 ms
4,376 KB
testcase_25 AC 41 ms
4,380 KB
testcase_26 AC 47 ms
4,376 KB
testcase_27 AC 44 ms
4,376 KB
testcase_28 AC 43 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 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,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.12 02:51:21
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

vector< int > f(ll n, int b) {
    vector< int > res;
    while (n) {
        res.push_back(n % b);
        n /= b;
    }
    for (int i = 0; i < 10; i++) {
        res.push_back(0);
    }
    return res;
}
int main() {
    int t, b;
    cin >> t >> b;
    b = -b;
    for (int _ = 0; _ < t; _++) {
        ll n;
        cin >> n;
        if (n == 0) {
            cout << 0 << endl;
            continue;
        }
        auto v = f(n, b);
        
        ll mod = b;
        ll total = 0, true_total = 0;
        vector< int > ans(v.size());
        for (int i = 0; i < v.size(); i++, mod *= b) {
            true_total += v[i] * mod / b;
            if (i & 1) {
                for (int j = 0; j < b; j++) {
                    if ((true_total + mod / b * j - total) % mod == 0) {
                        ans[i] = j;
                        total -= mod / b * j;
                        break;
                    } else if (j == b - 1) {
                        
                    }
                }
            } else {
                for (int j = 0; j < b; j++) {
                    if (true_total % mod == (mod / b * j + total) % mod) {
                        ans[i] = j;
                        total += mod / b * j;
                        break;
                    } else if (j == b - 1) {
                        
                    }
                }
            }
        }
        bool one = false;
        for (int i = ans.size()-1; i >= 0; i--) {
            if (ans[i] != 0 || one) {
                cout << ans[i];
                one = true;
            }
        }
        cout << endl;
    }
    return 0;
}
0