結果

問題 No.688 E869120 and Constructing Array 2
ユーザー tentententen
提出日時 2020-09-03 20:10:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 1,000 ms
コード長 988 bytes
コンパイル時間 3,551 ms
コンパイル使用メモリ 79,136 KB
実行使用メモリ 41,756 KB
最終ジャッジ日時 2024-11-24 00:06:56
合計ジャッジ時間 5,000 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
41,124 KB
testcase_01 AC 130 ms
41,352 KB
testcase_02 AC 128 ms
41,416 KB
testcase_03 AC 125 ms
41,292 KB
testcase_04 AC 126 ms
41,484 KB
testcase_05 AC 119 ms
41,344 KB
testcase_06 AC 127 ms
41,396 KB
testcase_07 AC 126 ms
41,368 KB
testcase_08 AC 129 ms
41,756 KB
testcase_09 AC 126 ms
41,436 KB
testcase_10 AC 119 ms
39,972 KB
testcase_11 AC 126 ms
41,496 KB
testcase_12 AC 129 ms
41,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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