結果

問題 No.2561 みんな大好きmod 998
ユーザー tentententen
提出日時 2023-12-04 13:43:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 4,000 ms
コード長 2,035 bytes
コンパイル時間 7,325 ms
コンパイル使用メモリ 82,748 KB
実行使用メモリ 55,016 KB
最終ジャッジ日時 2023-12-04 13:43:47
合計ジャッジ時間 9,596 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,984 KB
testcase_01 AC 69 ms
55,016 KB
testcase_02 AC 53 ms
53,968 KB
testcase_03 AC 151 ms
55,008 KB
testcase_04 AC 135 ms
54,892 KB
testcase_05 AC 137 ms
55,000 KB
testcase_06 AC 135 ms
54,896 KB
testcase_07 AC 54 ms
53,988 KB
testcase_08 AC 53 ms
53,988 KB
testcase_09 AC 59 ms
51,912 KB
testcase_10 AC 52 ms
53,992 KB
testcase_11 AC 79 ms
54,900 KB
testcase_12 AC 53 ms
54,000 KB
testcase_13 AC 52 ms
53,996 KB
testcase_14 AC 53 ms
53,964 KB
testcase_15 AC 138 ms
55,012 KB
testcase_16 AC 52 ms
53,984 KB
testcase_17 AC 52 ms
53,992 KB
testcase_18 AC 54 ms
53,984 KB
testcase_19 AC 117 ms
55,008 KB
testcase_20 AC 53 ms
53,996 KB
testcase_21 AC 54 ms
53,992 KB
testcase_22 AC 53 ms
53,984 KB
testcase_23 AC 54 ms
53,984 KB
testcase_24 AC 58 ms
53,992 KB
testcase_25 AC 52 ms
53,984 KB
testcase_26 AC 83 ms
54,928 KB
testcase_27 AC 135 ms
54,896 KB
testcase_28 AC 87 ms
54,900 KB
testcase_29 AC 71 ms
55,000 KB
testcase_30 AC 81 ms
54,896 KB
testcase_31 AC 101 ms
54,992 KB
testcase_32 AC 76 ms
55,008 KB
testcase_33 AC 71 ms
55,004 KB
testcase_34 AC 139 ms
55,008 KB
testcase_35 AC 72 ms
55,000 KB
testcase_36 AC 76 ms
54,896 KB
testcase_37 AC 70 ms
54,908 KB
testcase_38 AC 78 ms
54,908 KB
testcase_39 AC 80 ms
54,904 KB
testcase_40 AC 80 ms
54,896 KB
testcase_41 AC 77 ms
55,000 KB
testcase_42 AC 88 ms
54,996 KB
testcase_43 AC 67 ms
54,892 KB
testcase_44 AC 78 ms
54,892 KB
testcase_45 AC 118 ms
54,984 KB
testcase_46 AC 73 ms
55,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] values;
    static int ans = 0;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        dfw(n - 1, k, 0);
        System.out.println(ans % 998);
    }
    
    static void dfw(int idx, int v, long w) {
        if (idx + 1 < v  || v < 0) {
            return;
        }
        if (idx < 0) {
            if (w % 998244353 <= w % 998) {
                ans++;
            }
            return;
        }
        dfw(idx - 1, v, w);
        dfw(idx - 1, v - 1, w + values[idx]);
    }
}
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