結果

問題 No.1689 Set Cards
ユーザー tentententen
提出日時 2024-01-11 16:50:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 2,501 bytes
コンパイル時間 2,745 ms
コンパイル使用メモリ 90,040 KB
実行使用メモリ 65,192 KB
最終ジャッジ日時 2024-01-11 16:50:12
合計ジャッジ時間 6,852 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,980 KB
testcase_01 AC 53 ms
53,972 KB
testcase_02 AC 56 ms
53,988 KB
testcase_03 AC 55 ms
53,992 KB
testcase_04 AC 55 ms
53,988 KB
testcase_05 AC 54 ms
53,972 KB
testcase_06 AC 55 ms
53,996 KB
testcase_07 AC 54 ms
53,968 KB
testcase_08 AC 52 ms
53,988 KB
testcase_09 AC 53 ms
53,992 KB
testcase_10 AC 53 ms
54,004 KB
testcase_11 AC 141 ms
65,164 KB
testcase_12 AC 137 ms
65,116 KB
testcase_13 AC 118 ms
64,884 KB
testcase_14 AC 136 ms
65,008 KB
testcase_15 AC 94 ms
57,508 KB
testcase_16 AC 111 ms
60,692 KB
testcase_17 AC 78 ms
54,640 KB
testcase_18 AC 142 ms
65,164 KB
testcase_19 AC 113 ms
65,036 KB
testcase_20 AC 118 ms
64,992 KB
testcase_21 AC 97 ms
64,404 KB
testcase_22 AC 90 ms
64,348 KB
testcase_23 AC 103 ms
64,364 KB
testcase_24 AC 157 ms
65,192 KB
testcase_25 AC 131 ms
65,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    static int[][] dp;
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                values[i] |= (1 << (sc.nextInt() - 1));
            }
        }
        dp = new int[n][1 << 12];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(n - 1, (1 << 12) - 1));
    }
    
    static int dfw(int idx, int v) {
        if (v == 0) {
            return pow(2, idx + 1);
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][v] < 0) {
            dp[idx][v] = (dfw(idx - 1, v) + dfw(idx - 1, v & values[idx])) % MOD;
        }
        return dp[idx][v];
    }
    
    static int pow(int x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow((int)((long)x * x % MOD), p / 2);
        } else {
            return (int)(pow(x, p - 1) * (long)x % MOD);
        }
    }
}
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