結果

問題 No.1871 divisXor
ユーザー ks2mks2m
提出日時 2022-03-11 22:43:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 76,704 KB
実行使用メモリ 57,860 KB
最終ジャッジ日時 2023-10-23 19:15:12
合計ジャッジ時間 9,238 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
57,528 KB
testcase_01 AC 137 ms
57,536 KB
testcase_02 AC 137 ms
57,184 KB
testcase_03 AC 134 ms
57,860 KB
testcase_04 AC 136 ms
57,480 KB
testcase_05 AC 136 ms
57,536 KB
testcase_06 AC 137 ms
57,528 KB
testcase_07 AC 135 ms
57,568 KB
testcase_08 AC 137 ms
57,500 KB
testcase_09 AC 137 ms
57,216 KB
testcase_10 AC 136 ms
57,500 KB
testcase_11 AC 138 ms
55,492 KB
testcase_12 AC 137 ms
57,512 KB
testcase_13 AC 139 ms
57,544 KB
testcase_14 AC 136 ms
57,680 KB
testcase_15 AC 135 ms
57,448 KB
testcase_16 AC 137 ms
57,476 KB
testcase_17 AC 136 ms
57,364 KB
testcase_18 AC 137 ms
57,496 KB
testcase_19 AC 137 ms
57,452 KB
testcase_20 AC 137 ms
57,572 KB
testcase_21 AC 138 ms
57,564 KB
testcase_22 AC 138 ms
57,496 KB
testcase_23 AC 137 ms
57,676 KB
testcase_24 AC 136 ms
57,476 KB
testcase_25 AC 137 ms
55,184 KB
testcase_26 AC 135 ms
57,536 KB
testcase_27 AC 134 ms
57,576 KB
testcase_28 AC 136 ms
57,388 KB
testcase_29 AC 136 ms
57,572 KB
testcase_30 AC 138 ms
57,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();

		List<Long> list = new ArrayList<>();
		for (int i = 39; i >= 0; i--) {
			if ((n >> i & 1) == 1 ^ list.size() % 2 == 1) {
				list.add(1L << i);
			}
		}
		if (list.isEmpty()) {
			System.out.println(-1);
		} else {
			System.out.println(list.size());
			StringBuilder sb = new StringBuilder();
			for (long e : list) {
				sb.append(e).append(' ');
			}
			sb.deleteCharAt(sb.length() - 1);
			System.out.println(sb.toString());
		}
	}
}
0