結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
50,580 KB
testcase_01 AC 47 ms
50,104 KB
testcase_02 AC 129 ms
52,584 KB
testcase_03 AC 137 ms
54,648 KB
testcase_04 AC 135 ms
54,512 KB
testcase_05 AC 133 ms
54,512 KB
testcase_06 AC 131 ms
52,356 KB
testcase_07 AC 128 ms
54,200 KB
testcase_08 AC 128 ms
54,668 KB
testcase_09 AC 128 ms
52,244 KB
testcase_10 AC 126 ms
52,364 KB
testcase_11 AC 139 ms
54,700 KB
testcase_12 AC 139 ms
54,512 KB
testcase_13 AC 164 ms
56,624 KB
testcase_14 AC 133 ms
54,564 KB
testcase_15 AC 124 ms
54,796 KB
testcase_16 AC 137 ms
54,616 KB
testcase_17 AC 147 ms
54,584 KB
testcase_18 AC 140 ms
54,868 KB
testcase_19 AC 145 ms
54,732 KB
testcase_20 AC 138 ms
54,948 KB
testcase_21 AC 146 ms
54,636 KB
testcase_22 AC 136 ms
54,748 KB
testcase_23 AC 139 ms
54,924 KB
testcase_24 AC 159 ms
57,068 KB
testcase_25 AC 134 ms
55,076 KB
testcase_26 AC 148 ms
54,944 KB
testcase_27 AC 136 ms
54,916 KB
testcase_28 AC 123 ms
54,832 KB
testcase_29 AC 47 ms
50,508 KB
testcase_30 AC 46 ms
49,936 KB
testcase_31 AC 49 ms
50,240 KB
testcase_32 AC 50 ms
50,448 KB
testcase_33 AC 47 ms
50,348 KB
testcase_34 AC 46 ms
50,172 KB
testcase_35 AC 47 ms
50,236 KB
testcase_36 AC 46 ms
50,268 KB
testcase_37 AC 46 ms
50,084 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