結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー ks2mks2m
提出日時 2022-08-05 21:39:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 3,722 ms
コンパイル使用メモリ 73,936 KB
実行使用メモリ 67,644 KB
最終ジャッジ日時 2023-10-13 22:15:03
合計ジャッジ時間 10,805 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,312 KB
testcase_01 AC 123 ms
55,364 KB
testcase_02 AC 266 ms
67,172 KB
testcase_03 AC 121 ms
55,636 KB
testcase_04 AC 263 ms
67,420 KB
testcase_05 AC 270 ms
67,312 KB
testcase_06 AC 265 ms
67,644 KB
testcase_07 AC 179 ms
58,124 KB
testcase_08 AC 242 ms
62,848 KB
testcase_09 AC 157 ms
57,572 KB
testcase_10 AC 203 ms
60,316 KB
testcase_11 AC 161 ms
57,432 KB
testcase_12 AC 192 ms
58,624 KB
testcase_13 AC 189 ms
58,240 KB
testcase_14 AC 167 ms
57,968 KB
testcase_15 AC 180 ms
58,224 KB
testcase_16 AC 196 ms
58,164 KB
testcase_17 AC 127 ms
55,688 KB
testcase_18 AC 126 ms
55,504 KB
testcase_19 AC 127 ms
55,732 KB
testcase_20 AC 127 ms
55,732 KB
testcase_21 AC 128 ms
54,300 KB
testcase_22 AC 226 ms
61,208 KB
testcase_23 AC 195 ms
58,488 KB
testcase_24 AC 158 ms
57,592 KB
testcase_25 AC 234 ms
63,724 KB
testcase_26 AC 184 ms
57,956 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);
		int n = sc.nextInt();
		long s = sc.nextLong();
		sc.close();

		List<Integer> list = new ArrayList<>();
		long r = s;
		int x = n;
		while (r > 0) {
			if (x > r) {
				x = (int) r;
			}
			list.add(x);
			r -= x;
			x--;
		}

		System.out.println(list.size());
		StringBuilder sb = new StringBuilder();
		for (int i = list.size() - 1; i >= 0; i--) {
			sb.append(list.get(i)).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}
}
0