結果
問題 | No.1598 4×4 Grid |
ユーザー | tenten |
提出日時 | 2021-07-12 19:22:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,195 ms / 4,000 ms |
コード長 | 2,042 bytes |
コンパイル時間 | 2,605 ms |
コンパイル使用メモリ | 75,348 KB |
実行使用メモリ | 303,384 KB |
最終ジャッジ日時 | 2023-09-14 20:43:53 |
合計ジャッジ時間 | 26,775 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,195 ms
303,384 KB |
testcase_01 | AC | 2,079 ms
300,888 KB |
testcase_02 | AC | 2,069 ms
302,820 KB |
testcase_03 | AC | 2,106 ms
303,188 KB |
testcase_04 | AC | 2,062 ms
302,776 KB |
testcase_05 | AC | 2,050 ms
302,652 KB |
testcase_06 | AC | 2,065 ms
302,760 KB |
testcase_07 | AC | 2,109 ms
302,624 KB |
testcase_08 | AC | 2,081 ms
302,576 KB |
testcase_09 | AC | 2,041 ms
302,304 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int k = sc.nextInt(); int[] counts = new int[1 << 16]; ArrayList<HashMap<Integer, Long>> dp = new ArrayList<>(); for (int i = 0; i < (1 << 16); i++) { for (int j = 0; j < 16; j++) { if (j % 4 == 3) { continue; } if (((i & (1 << j)) == 0) != ((i & (1 << (j + 1))) == 0)) { counts[i]++; } } for (int j = 0; j < 12; j++) { if (((i & (1 << j)) == 0) != ((i & (1 << (j + 4))) == 0)) { counts[i]++; } } dp.add(new HashMap<>()); } dp.get(0).put(0, 1L); for (int i = 1; i < (1 << 16); i++) { for (int j = 0; j < 16; j++) { if ((i & (1 << j)) == 0) { continue; } for (Map.Entry<Integer, Long> entry : dp.get(i ^ (1 << j)).entrySet()) { int key = entry.getKey(); long value = entry.getValue(); dp.get(i).put(key + counts[i], dp.get(i).getOrDefault(key + counts[i], 0L) + value); } } } System.out.println(dp.get((1 << 16) - 1).getOrDefault(k, 0L)); } } 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(); } }