結果

問題 No.688 E869120 and Constructing Array 2
ユーザー htensaihtensai
提出日時 2019-12-10 08:45:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 1,000 ms
コード長 1,116 bytes
コンパイル時間 2,210 ms
コンパイル使用メモリ 75,772 KB
実行使用メモリ 56,548 KB
最終ジャッジ日時 2023-09-06 01:53:15
合計ジャッジ時間 4,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,648 KB
testcase_01 AC 124 ms
55,684 KB
testcase_02 AC 124 ms
55,912 KB
testcase_03 AC 124 ms
55,732 KB
testcase_04 AC 123 ms
55,588 KB
testcase_05 AC 123 ms
56,548 KB
testcase_06 AC 121 ms
55,808 KB
testcase_07 AC 121 ms
56,064 KB
testcase_08 AC 120 ms
55,596 KB
testcase_09 AC 121 ms
55,908 KB
testcase_10 AC 122 ms
56,228 KB
testcase_11 AC 123 ms
55,724 KB
testcase_12 AC 124 ms
56,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        if (k == 0) {
            System.out.println(1);
            System.out.println(1);
            return;
        }
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 2; i <= 30; i++) {
            map.put(i * (i - 1) / 2, i);
        }
        int count0 = 0;
        int count1 = 0;
        while (k > 0) {
            if (map.containsKey(k)) {
                count1 = map.get(k);
                if (count1 + count0 <= 30) {
                    break;
                }
            }
            count0++;
            k /= 2;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(count0 + count1).append("\n");
        for (int i = 0; i < count1; i++) {
            if (i != 0) {
                sb.append(" ");
            }
            sb.append("1");
        }
        for (int i = 0; i < count0; i++) {
            sb.append(" ").append("0");
        }
        System.out.println(sb);
    }
}
0