結果

問題 No.688 E869120 and Constructing Array 2
ユーザー htensaihtensai
提出日時 2019-12-10 08:43:42
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 994 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 72,696 KB
実行使用メモリ 56,160 KB
最終ジャッジ日時 2023-09-06 01:50:30
合計ジャッジ時間 5,220 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,004 KB
testcase_01 AC 126 ms
55,780 KB
testcase_02 AC 127 ms
55,680 KB
testcase_03 AC 125 ms
55,924 KB
testcase_04 AC 126 ms
55,936 KB
testcase_05 AC 126 ms
55,612 KB
testcase_06 AC 124 ms
55,988 KB
testcase_07 AC 125 ms
55,892 KB
testcase_08 AC 127 ms
55,916 KB
testcase_09 WA -
testcase_10 AC 126 ms
55,856 KB
testcase_11 AC 123 ms
54,012 KB
testcase_12 AC 125 ms
55,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        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