結果

問題 No.2027 (1, 2, 3, …, N) 's Subset Sum
ユーザー tentententen
提出日時 2023-04-19 16:04:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 1,956 bytes
コンパイル時間 3,274 ms
コンパイル使用メモリ 92,844 KB
実行使用メモリ 72,432 KB
最終ジャッジ日時 2024-04-22 17:03:32
合計ジャッジ時間 8,726 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
37,932 KB
testcase_01 AC 72 ms
38,168 KB
testcase_02 AC 337 ms
72,400 KB
testcase_03 AC 72 ms
37,676 KB
testcase_04 AC 313 ms
72,432 KB
testcase_05 AC 325 ms
70,808 KB
testcase_06 AC 359 ms
70,340 KB
testcase_07 AC 141 ms
46,676 KB
testcase_08 AC 279 ms
66,192 KB
testcase_09 AC 123 ms
44,824 KB
testcase_10 AC 194 ms
60,092 KB
testcase_11 AC 133 ms
46,864 KB
testcase_12 AC 159 ms
52,384 KB
testcase_13 AC 149 ms
49,908 KB
testcase_14 AC 124 ms
42,492 KB
testcase_15 AC 153 ms
52,904 KB
testcase_16 AC 173 ms
58,800 KB
testcase_17 AC 82 ms
37,952 KB
testcase_18 AC 79 ms
38,012 KB
testcase_19 AC 75 ms
38,180 KB
testcase_20 AC 91 ms
38,004 KB
testcase_21 AC 79 ms
38,184 KB
testcase_22 AC 225 ms
62,120 KB
testcase_23 AC 176 ms
54,968 KB
testcase_24 AC 128 ms
42,580 KB
testcase_25 AC 234 ms
68,100 KB
testcase_26 AC 144 ms
46,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        ArrayList<Integer> list = dfw(sc.nextInt(), sc.nextLong());
        System.out.println(list.size());
        System.out.println(list.stream().map(x -> x.toString()).collect(Collectors.joining(" ")));
    }
    
    static ArrayList<Integer> dfw(int idx, long x) {
        if (x == 0) {
            return new ArrayList<>();
        }
        if (idx <= x) {
            ArrayList<Integer> list = dfw(idx - 1, x - idx);
            list.add(idx);
            return list;
        } else {
            return dfw(idx - 1, x);
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0