結果

問題 No.782 マイナス進数
ユーザー mamekinmamekin
提出日時 2019-02-10 21:42:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,209 bytes
コンパイル時間 1,035 ms
コンパイル使用メモリ 115,088 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-21 13:06:47
合計ジャッジ時間 3,706 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void solve(long long &n, int base, long long curr, long long minVal, long long maxVal, string& ans)
{
    if(minVal <= n && n <= maxVal)
        return;

    long long curr2 = curr * base;
    long long minVal2 = minVal + min(0LL, curr * (-base - 1));
    long long maxVal2 = maxVal + max(0LL, curr * (-base - 1));
    solve(n, base, curr2, minVal2, maxVal2, ans);

    int x = 0;
    while(!(minVal <= n && n <= maxVal)){
        ++ x;
        n -= curr;
    }
    ans += (char)('0' + x);
}

int main()
{
    int t, b;
    cin >> t >> b;

    while(--t >= 0){
        long long n;
        cin >> n;
        string ans;
        solve(n, b, 1, 0, 0, ans);
        cout << ans << endl;
    }

    return 0;
}
0