結果

問題 No.2711 Connecting Lights
ユーザー tentententen
提出日時 2024-04-01 18:00:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 354 ms / 5,000 ms
コード長 2,505 bytes
コンパイル時間 2,506 ms
コンパイル使用メモリ 81,440 KB
実行使用メモリ 68,080 KB
最終ジャッジ日時 2024-04-01 18:01:05
合計ジャッジ時間 7,469 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,968 KB
testcase_01 AC 56 ms
53,948 KB
testcase_02 AC 57 ms
53,992 KB
testcase_03 AC 56 ms
53,976 KB
testcase_04 AC 56 ms
53,964 KB
testcase_05 AC 94 ms
58,744 KB
testcase_06 AC 58 ms
53,984 KB
testcase_07 AC 59 ms
54,380 KB
testcase_08 AC 85 ms
55,544 KB
testcase_09 AC 255 ms
63,248 KB
testcase_10 AC 83 ms
56,300 KB
testcase_11 AC 145 ms
65,004 KB
testcase_12 AC 188 ms
63,880 KB
testcase_13 AC 121 ms
63,248 KB
testcase_14 AC 78 ms
55,272 KB
testcase_15 AC 147 ms
63,104 KB
testcase_16 AC 92 ms
58,928 KB
testcase_17 AC 96 ms
58,816 KB
testcase_18 AC 107 ms
57,172 KB
testcase_19 AC 95 ms
60,772 KB
testcase_20 AC 181 ms
65,884 KB
testcase_21 AC 92 ms
61,156 KB
testcase_22 AC 63 ms
54,500 KB
testcase_23 AC 74 ms
58,384 KB
testcase_24 AC 200 ms
60,756 KB
testcase_25 AC 220 ms
61,056 KB
testcase_26 AC 351 ms
66,028 KB
testcase_27 AC 201 ms
66,020 KB
testcase_28 AC 354 ms
68,080 KB
testcase_29 AC 98 ms
64,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static Map<Integer, List<Integer>> maps = new HashMap<>();
    static int[][] dp;
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        if (m == 1) {
            System.out.println(1 << n);
            return;
        }
        int k = sc.nextInt();
        for (int i = 1; i < (1 << n); i++) {
            if (getPop(i) >= k) {
                maps.put(i, new ArrayList<>());
            }
        }
        for (int x : maps.keySet()) {
            for (int y : maps.keySet()) {
                if (getPop(x & y) >= k) {
                    maps.get(x).add(y);
                }
            }
        }
        dp = new int[m - 1][1 << n];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        int ans = 0;
        for (int x : maps.keySet()) {
            ans += dfw(m - 2, x);
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static int dfw(int idx, int v) {
        if (idx < 0) {
            return 1;
        }
        if (dp[idx][v] < 0) {
            dp[idx][v] = 0;
            for (int x : maps.get(v)) {
                dp[idx][v] += dfw(idx - 1, x);
                dp[idx][v] %= MOD;
            }
        }
        return dp[idx][v];
    }
    
    static int getPop(int x) {
        int pop = 0;
        while (x > 0) {
            pop += x % 2;
            x >>= 1;
        }
        return pop;
    }
}
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