結果

問題 No.782 マイナス進数
ユーザー tentententen
提出日時 2023-07-07 16:09:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 2,370 bytes
コンパイル時間 2,930 ms
コンパイル使用メモリ 85,372 KB
実行使用メモリ 57,140 KB
最終ジャッジ日時 2023-09-28 16:46:13
合計ジャッジ時間 9,822 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,208 KB
testcase_01 AC 47 ms
49,340 KB
testcase_02 AC 143 ms
54,696 KB
testcase_03 AC 132 ms
55,056 KB
testcase_04 AC 147 ms
54,644 KB
testcase_05 AC 145 ms
55,064 KB
testcase_06 AC 143 ms
54,640 KB
testcase_07 AC 150 ms
54,760 KB
testcase_08 AC 148 ms
55,052 KB
testcase_09 AC 142 ms
54,900 KB
testcase_10 AC 144 ms
54,852 KB
testcase_11 AC 158 ms
54,940 KB
testcase_12 AC 154 ms
54,836 KB
testcase_13 AC 174 ms
57,140 KB
testcase_14 AC 152 ms
54,824 KB
testcase_15 AC 159 ms
54,708 KB
testcase_16 AC 152 ms
55,060 KB
testcase_17 AC 169 ms
55,028 KB
testcase_18 AC 155 ms
54,924 KB
testcase_19 AC 157 ms
55,132 KB
testcase_20 AC 154 ms
55,124 KB
testcase_21 AC 168 ms
54,916 KB
testcase_22 AC 157 ms
55,420 KB
testcase_23 AC 153 ms
55,256 KB
testcase_24 AC 180 ms
54,936 KB
testcase_25 AC 152 ms
54,904 KB
testcase_26 AC 153 ms
55,112 KB
testcase_27 AC 157 ms
54,868 KB
testcase_28 AC 156 ms
54,988 KB
testcase_29 AC 49 ms
49,360 KB
testcase_30 AC 50 ms
49,464 KB
testcase_31 AC 52 ms
49,616 KB
testcase_32 AC 51 ms
49,368 KB
testcase_33 AC 49 ms
49,536 KB
testcase_34 AC 49 ms
49,392 KB
testcase_35 AC 49 ms
49,388 KB
testcase_36 AC 50 ms
49,608 KB
testcase_37 AC 50 ms
49,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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();
        while (t-- > 0) {
            int n = sc.nextInt();
            if (n == 0) {
                sb.append("0\n");
                continue;
            }
            StringBuilder tmp = new StringBuilder();
            boolean isPlus = true;
            while (n > 0) {
                int mod = n % b;
                if (isPlus) {
                    tmp.append(mod);
                    n /= b;
                } else {
                    if (mod > 0) {
                        tmp.append(b - mod);
                        n /= b;
                        n++;
                    } else {
                        tmp.append(0);
                        n /= b;
                    }
                }
                isPlus ^= true;
            }
            sb.append(tmp.reverse()).append("\n");
        }
        System.out.print(sb);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0