結果

問題 No.782 マイナス進数
ユーザー tentententen
提出日時 2021-11-02 18:03:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,712 bytes
コンパイル時間 2,882 ms
コンパイル使用メモリ 78,268 KB
実行使用メモリ 56,104 KB
最終ジャッジ日時 2024-04-20 03:59:13
合計ジャッジ時間 8,318 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,096 KB
testcase_01 AC 50 ms
50,660 KB
testcase_02 AC 133 ms
52,376 KB
testcase_03 AC 140 ms
54,552 KB
testcase_04 AC 143 ms
54,496 KB
testcase_05 AC 140 ms
52,500 KB
testcase_06 AC 125 ms
52,476 KB
testcase_07 AC 141 ms
54,236 KB
testcase_08 AC 137 ms
54,308 KB
testcase_09 AC 138 ms
52,644 KB
testcase_10 AC 136 ms
52,436 KB
testcase_11 AC 138 ms
54,744 KB
testcase_12 AC 144 ms
54,596 KB
testcase_13 AC 180 ms
56,104 KB
testcase_14 AC 147 ms
54,940 KB
testcase_15 AC 149 ms
54,716 KB
testcase_16 AC 146 ms
54,704 KB
testcase_17 AC 163 ms
54,700 KB
testcase_18 AC 145 ms
54,884 KB
testcase_19 AC 159 ms
54,600 KB
testcase_20 AC 150 ms
54,996 KB
testcase_21 AC 160 ms
54,524 KB
testcase_22 AC 135 ms
54,824 KB
testcase_23 AC 145 ms
54,704 KB
testcase_24 AC 176 ms
55,164 KB
testcase_25 AC 147 ms
54,600 KB
testcase_26 AC 150 ms
54,784 KB
testcase_27 AC 149 ms
55,020 KB
testcase_28 AC 149 ms
54,756 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 #

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();
            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