結果

問題 No.1689 Set Cards
ユーザー tentententen
提出日時 2021-10-11 10:58:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 3,485 ms
コンパイル使用メモリ 74,120 KB
実行使用メモリ 66,728 KB
最終ジャッジ日時 2023-10-13 11:29:38
合計ジャッジ時間 6,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,536 KB
testcase_01 AC 45 ms
49,344 KB
testcase_02 AC 48 ms
49,288 KB
testcase_03 AC 47 ms
49,216 KB
testcase_04 AC 47 ms
49,516 KB
testcase_05 AC 47 ms
49,380 KB
testcase_06 AC 48 ms
49,268 KB
testcase_07 AC 46 ms
49,344 KB
testcase_08 AC 45 ms
49,384 KB
testcase_09 AC 45 ms
49,536 KB
testcase_10 AC 46 ms
49,584 KB
testcase_11 AC 138 ms
65,876 KB
testcase_12 AC 137 ms
65,868 KB
testcase_13 AC 103 ms
65,952 KB
testcase_14 AC 109 ms
65,840 KB
testcase_15 AC 97 ms
56,808 KB
testcase_16 AC 111 ms
65,172 KB
testcase_17 AC 80 ms
53,832 KB
testcase_18 AC 135 ms
65,920 KB
testcase_19 AC 108 ms
65,784 KB
testcase_20 AC 111 ms
64,804 KB
testcase_21 AC 82 ms
64,512 KB
testcase_22 AC 86 ms
64,660 KB
testcase_23 AC 101 ms
65,400 KB
testcase_24 AC 161 ms
66,728 KB
testcase_25 AC 123 ms
65,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] values;
    static long[][] dp;
    static final int MOD = 998244353;
    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 long[n][1 << 12];
        for (long[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(n - 1, (1 << 12) - 1));
    }
    
    static long dfw(int idx, int mask) {
        if (mask == 0) {
            return pow(2, idx + 1);
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][mask] < 0) {
            dp[idx][mask] = (dfw(idx - 1, mask) + dfw(idx - 1, mask & values[idx])) % MOD;
        }
        return dp[idx][mask];
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
}

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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0