結果

問題 No.2608 Divide into two
ユーザー ks2mks2m
提出日時 2024-01-19 21:56:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 153 ms / 1,000 ms
コード長 613 bytes
コンパイル時間 4,475 ms
コンパイル使用メモリ 74,192 KB
実行使用メモリ 57,980 KB
最終ジャッジ日時 2024-01-19 21:56:32
合計ジャッジ時間 4,519 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,820 KB
testcase_01 AC 153 ms
57,980 KB
testcase_02 AC 153 ms
57,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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