結果

問題 No.688 E869120 and Constructing Array 2
ユーザー htensai
提出日時 2019-12-10 08:45:41
言語 Java
(openjdk 23)
結果
AC  
実行時間 131 ms / 1,000 ms
コード長 1,116 bytes
コンパイル時間 2,163 ms
コンパイル使用メモリ 79,492 KB
実行使用メモリ 54,424 KB
最終ジャッジ日時 2024-06-23 20:55:46
合計ジャッジ時間 4,671 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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