結果
| 問題 |
No.2711 Connecting Lights
|
| ユーザー |
tenten
|
| 提出日時 | 2024-04-01 17:59:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,500 bytes |
| コンパイル時間 | 2,688 ms |
| コンパイル使用メモリ | 81,564 KB |
| 実行使用メモリ | 51,532 KB |
| 最終ジャッジ日時 | 2024-09-30 21:56:04 |
| 合計ジャッジ時間 | 6,398 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 2 |
ソースコード
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(0);
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();
}
}
}
tenten