結果

問題 No.782 マイナス進数
コンテスト
ユーザー htensai
提出日時 2019-12-25 13:56:35
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 195 ms / 2,000 ms
+ 381µs
コード長 1,127 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,598 ms
コンパイル使用メモリ 84,476 KB
実行使用メモリ 49,204 KB
最終ジャッジ日時 2026-09-03 15:03:35
合計ジャッジ時間 9,819 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int b = - sc.nextInt();
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < t; i++) {
            boolean isPlus = true;
            int x = sc.nextInt();
            StringBuilder sb = new StringBuilder();
            if (x == 0) {
                ans.append(0).append("\n");
                continue;
            }
           while (x > 0) {
                if (isPlus) {
                    sb.append(x % b);
                    x /= b;
                    isPlus = false;
                } else {
                    if (x % b == 0) {
                        sb.append(0);
                        x /= b;
                    } else {
                        sb.append(b - x % b);
                        x /= b;
                        x++;
                    }
                    isPlus = true;
                }
            }
            ans.append(sb.reverse()).append("\n");
        }
        System.out.print(ans);
    }
}
0