結果

問題 No.782 マイナス進数
ユーザー tentententen
提出日時 2021-11-02 18:05:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,812 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 77,524 KB
実行使用メモリ 57,484 KB
最終ジャッジ日時 2024-04-20 04:01:07
合計ジャッジ時間 7,832 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
50,480 KB
testcase_01 AC 47 ms
50,092 KB
testcase_02 AC 123 ms
51,976 KB
testcase_03 AC 137 ms
54,324 KB
testcase_04 AC 133 ms
54,544 KB
testcase_05 AC 126 ms
54,668 KB
testcase_06 AC 125 ms
52,212 KB
testcase_07 AC 133 ms
54,284 KB
testcase_08 AC 129 ms
54,556 KB
testcase_09 AC 125 ms
52,148 KB
testcase_10 AC 124 ms
52,608 KB
testcase_11 AC 139 ms
54,944 KB
testcase_12 AC 124 ms
54,972 KB
testcase_13 AC 173 ms
57,484 KB
testcase_14 AC 143 ms
54,644 KB
testcase_15 AC 137 ms
54,668 KB
testcase_16 AC 134 ms
54,928 KB
testcase_17 AC 151 ms
54,764 KB
testcase_18 AC 135 ms
54,804 KB
testcase_19 AC 141 ms
54,724 KB
testcase_20 AC 130 ms
54,876 KB
testcase_21 AC 149 ms
54,460 KB
testcase_22 AC 132 ms
54,932 KB
testcase_23 AC 134 ms
54,712 KB
testcase_24 AC 161 ms
57,452 KB
testcase_25 AC 141 ms
54,664 KB
testcase_26 AC 139 ms
54,604 KB
testcase_27 AC 139 ms
54,880 KB
testcase_28 AC 141 ms
54,876 KB
testcase_29 AC 48 ms
50,320 KB
testcase_30 AC 46 ms
50,080 KB
testcase_31 AC 47 ms
50,316 KB
testcase_32 AC 48 ms
50,564 KB
testcase_33 AC 46 ms
50,284 KB
testcase_34 AC 48 ms
50,552 KB
testcase_35 AC 50 ms
50,164 KB
testcase_36 AC 47 ms
50,460 KB
testcase_37 AC 46 ms
50,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int t = sc.nextInt();
        int b = -sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < t; i++) {
            int x = sc.nextInt();
            if (x == 0) {
                sb.append("0\n");
                continue;
            }
            boolean isPlus = true;
            StringBuilder tmp = new StringBuilder();
            while (x > 0) {
                if (isPlus) {
                    tmp.append(x % b);
                    x /= b;
                } else {
                    int mod = x % b;
                    if (mod == 0) {
                        tmp.append("0");
                        x /= b;
                    } else {
                        tmp.append(b - mod);
                        x /= b;
                        x++;
                    }
                }
                isPlus ^= true;
            }
            sb.append(tmp.reverse()).append("\n");
        }
        System.out.print(sb);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0