結果

問題 No.688 E869120 and Constructing Array 2
ユーザー Tsukasa_Type
提出日時 2018-05-18 23:02:35
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,080 bytes
コンパイル時間 2,648 ms
コンパイル使用メモリ 88,216 KB
実行使用メモリ 47,156 KB
最終ジャッジ日時 2024-07-07 13:34:04
合計ジャッジ時間 8,271 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other WA * 9 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import static java.lang.System.*;
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		Map<Integer,Integer> map = new TreeMap<>();
		for (int i=2; i<=30; i++) {
			map.put(i*(i-1)/2, i);
		}

		List<Integer> ans = new ArrayList<>();

		long n = sc.nextLong();
		if (n == 0) out.println(1);
		if (map.containsKey((int)n)) {
			for (int i=0; i<map.get((int)n); i++) {
				ans.add(1);
			}
			printList(ans);
		}
		else {
			for (Map.Entry<Integer,Integer> e: map.entrySet()) {
				if (is2n(n/e.getKey())) {
					
					for (int i=0; i<map.get(e.getKey()); i++) {
						ans.add(1);
					}
					long t = n/e.getKey();
					while (t%2 == 0) {
						t /= 2;
						ans.add(0);
					}
					printList(ans);
					
					t = n/e.getKey();
					break;
				}
			}
		}
	}

	static void printList(List<Integer> list) {
		for (int i=0; i<list.size(); i++) {
			out.print((i==0?"":" ")+list.get(i));
		}
	}

	static boolean is2n(long l) {
		while (l%2 == 0) {
			l /= 2;
		}
		if (l == 1) return true;
		return false;
	}
}
0