結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー tentententen
提出日時 2022-08-08 15:35:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,413 bytes
コンパイル時間 3,830 ms
コンパイル使用メモリ 78,040 KB
実行使用メモリ 65,776 KB
最終ジャッジ日時 2023-10-19 05:13:34
合計ジャッジ時間 9,351 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,500 KB
testcase_01 AC 56 ms
52,380 KB
testcase_02 AC 218 ms
65,340 KB
testcase_03 AC 56 ms
53,500 KB
testcase_04 AC 208 ms
65,776 KB
testcase_05 AC 209 ms
65,252 KB
testcase_06 AC 216 ms
65,120 KB
testcase_07 AC 113 ms
57,156 KB
testcase_08 AC 178 ms
62,456 KB
testcase_09 AC 104 ms
55,264 KB
testcase_10 AC 137 ms
57,636 KB
testcase_11 AC 115 ms
57,512 KB
testcase_12 AC 128 ms
57,480 KB
testcase_13 AC 116 ms
57,152 KB
testcase_14 AC 99 ms
55,044 KB
testcase_15 AC 113 ms
57,220 KB
testcase_16 AC 131 ms
57,580 KB
testcase_17 AC 56 ms
53,520 KB
testcase_18 AC 57 ms
52,376 KB
testcase_19 AC 57 ms
53,504 KB
testcase_20 AC 58 ms
53,504 KB
testcase_21 AC 59 ms
53,516 KB
testcase_22 AC 167 ms
60,612 KB
testcase_23 AC 122 ms
57,556 KB
testcase_24 AC 91 ms
54,984 KB
testcase_25 AC 182 ms
60,808 KB
testcase_26 AC 116 ms
57,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long s = sc.nextLong();
        ArrayList<Integer> ans = new ArrayList<>();
        for (int i = n; i >= 1; i--) {
            if (s >= i) {
                s -= i;
                ans.add(i);
            }
        }
        StringBuilder sb = new StringBuilder();
        sb.append(ans.size()).append("\n");
        for (int i = 0; i < ans.size(); i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(ans.get(ans.size() - 1 - i));
        }
        System.out.println(sb);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0