結果
問題 | No.2608 Divide into two |
ユーザー | ks2m |
提出日時 | 2024-01-19 21:56:26 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 140 ms / 1,000 ms |
コード長 | 613 bytes |
コンパイル時間 | 2,129 ms |
コンパイル使用メモリ | 74,400 KB |
実行使用メモリ | 41,760 KB |
最終ジャッジ日時 | 2024-09-28 04:23:34 |
合計ジャッジ時間 | 3,223 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 2 |
ソースコード
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int z = 0; z < t; z++) { int n = sc.nextInt(); int n2 = n * (n + 1) / 2; if (n2 % 2 == 1) { System.out.println(-1); continue; } char[] ans = new char[n]; Arrays.fill(ans, '0'); int goal = n2 / 2; int sum = 0; for (int i = n - 1; i >= 0; i--) { if (sum + i + 1 <= goal) { ans[i] = '1'; sum += i + 1; } } System.out.println(ans); } sc.close(); } }