結果

問題 No.782 マイナス進数
ユーザー tentententen
提出日時 2023-11-15 20:50:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 2,312 bytes
コンパイル時間 2,998 ms
コンパイル使用メモリ 91,432 KB
実行使用メモリ 61,032 KB
最終ジャッジ日時 2023-11-15 20:51:01
合計ジャッジ時間 8,851 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
53,992 KB
testcase_01 AC 51 ms
54,016 KB
testcase_02 AC 143 ms
56,040 KB
testcase_03 AC 150 ms
57,928 KB
testcase_04 AC 151 ms
58,196 KB
testcase_05 AC 148 ms
56,388 KB
testcase_06 AC 148 ms
56,156 KB
testcase_07 AC 139 ms
58,852 KB
testcase_08 AC 135 ms
58,392 KB
testcase_09 AC 142 ms
56,048 KB
testcase_10 AC 147 ms
56,172 KB
testcase_11 AC 154 ms
58,336 KB
testcase_12 AC 155 ms
58,552 KB
testcase_13 AC 174 ms
61,032 KB
testcase_14 AC 142 ms
58,392 KB
testcase_15 AC 151 ms
58,464 KB
testcase_16 AC 154 ms
56,444 KB
testcase_17 AC 169 ms
56,532 KB
testcase_18 AC 155 ms
58,488 KB
testcase_19 AC 162 ms
58,364 KB
testcase_20 AC 155 ms
58,328 KB
testcase_21 AC 164 ms
58,296 KB
testcase_22 AC 145 ms
58,464 KB
testcase_23 AC 141 ms
58,448 KB
testcase_24 AC 175 ms
59,224 KB
testcase_25 AC 152 ms
58,484 KB
testcase_26 AC 162 ms
58,408 KB
testcase_27 AC 156 ms
58,488 KB
testcase_28 AC 152 ms
58,356 KB
testcase_29 AC 52 ms
53,984 KB
testcase_30 AC 52 ms
54,000 KB
testcase_31 AC 52 ms
54,004 KB
testcase_32 AC 53 ms
53,992 KB
testcase_33 AC 51 ms
53,988 KB
testcase_34 AC 51 ms
53,972 KB
testcase_35 AC 50 ms
53,988 KB
testcase_36 AC 51 ms
53,996 KB
testcase_37 AC 51 ms
53,980 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 n = sc.nextInt();
        int b = -sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (n-- > 0) {
            int x = sc.nextInt();
            if (x == 0) {
                sb.append("0\n");
                continue;
            }
            boolean isMinus = false;
            StringBuilder tmp = new StringBuilder();
            while (x > 0) {
                int mod = x % b;
                if (isMinus) {
                    if (mod == 0) {
                        tmp.append(mod);
                    } else {
                        tmp.append(b - mod);
                        x += b;
                    }
                } else {
                    tmp.append(mod);
                }
                x /= b;
                isMinus ^= 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