結果
| 問題 | No.782 マイナス進数 |
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-12-25 13:56:35 |
| 言語 | Java (openjdk 26.0.2.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 195 ms / 2,000 ms |
| + 381µs | |
| コード長 | 1,127 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
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);
}
}
htensai