結果
| 問題 | No.1598 4×4 Grid | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2021-07-12 19:22:38 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2,392 ms / 4,000 ms | 
| コード長 | 2,042 bytes | 
| コンパイル時間 | 2,872 ms | 
| コンパイル使用メモリ | 78,816 KB | 
| 実行使用メモリ | 293,764 KB | 
| 最終ジャッジ日時 | 2024-07-02 03:34:38 | 
| 合計ジャッジ時間 | 29,728 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 7 | 
ソースコード
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();
    }
}
            
            
            
        