結果
| 問題 |
No.2027 (1, 2, 3, …, N) 's Subset Sum
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2022-08-05 21:39:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 279 ms / 2,000 ms |
| コード長 | 671 bytes |
| コンパイル時間 | 3,456 ms |
| コンパイル使用メモリ | 76,228 KB |
| 実行使用メモリ | 55,664 KB |
| 最終ジャッジ日時 | 2024-09-15 17:58:02 |
| 合計ジャッジ時間 | 10,255 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
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());
}
}
ks2m