結果

問題 No.1189 Sum is XOR
ユーザー tenten
提出日時 2024-07-22 17:07:43
言語 Java
(openjdk 23)
結果
MLE  
実行時間 -
コード長 2,023 bytes
コンパイル時間 3,050 ms
コンパイル使用メモリ 78,412 KB
実行使用メモリ 764,132 KB
最終ジャッジ日時 2024-07-22 17:08:11
合計ジャッジ時間 27,073 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 MLE * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    static int[] values;
    static int[][][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (k > 10) {
            System.out.println(0);
            return;
        }
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        dp = new int[k][n][1 << 10];
        for (int[][] arr1 : dp) {
            for (int[] arr2 : arr1) {
                Arrays.fill(arr2, -1);
            }
        }
        System.out.println(dfw(k - 1, n - 1, (1 << 10) - 1));
    }
    
    static int dfw(int c, int idx, int v) {
        if (c < 0) {
            return 1;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[c][idx][v] < 0) {
            dp[c][idx][v] = (dfw(c, idx - 1, v) + ((v & values[idx]) == 0 ? 0 : dfw(c - 1, idx - 1, v ^ values[idx]))) % MOD;
        }
        return dp[c][idx][v];
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}


0