結果
| 問題 | 
                            No.1797 永遠のグリッド
                             | 
                    
| ユーザー | 
                             tenten
                         | 
                    
| 提出日時 | 2022-01-05 10:11:17 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                            (最新)
                                AC
                                 
                             
                            (最初)
                            
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 3,035 bytes | 
| コンパイル時間 | 2,241 ms | 
| コンパイル使用メモリ | 78,556 KB | 
| 実行使用メモリ | 67,816 KB | 
| 最終ジャッジ日時 | 2024-10-15 14:25:25 | 
| 合計ジャッジ時間 | 15,903 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 23 TLE * 4 | 
ソースコード
import java.io.*;
import java.util.*;
public class Main {
    static int k;
    static HashSet<Box> boxes = new HashSet<>();
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        Box.height = sc.nextInt();
        Box.width = sc.nextInt();
        k = sc.nextInt();
        makeBox(0, new int[Box.height * Box.width]);
        System.out.println(boxes.size());
    }
    
    static void makeBox(int idx, int[] values) {
        if (idx == Box.height * Box.width) {
            Box b = new Box(values);
            if (b.getType() != k) {
                return;
            }
            boxes.add(b);
            return;
        }
        for (int i = 0; i < k; i++) {
            values[idx] = i;
            makeBox(idx + 1, values);
        }
    }
    
    static class Box {
        static int height;
        static int width;
        static int[] counts = new int[]{1, 100, 10000};
        int[][] colors;
        int hash;
        boolean[] type = new boolean[3];
        
        public Box(int[] arr) {
            colors = new int[height][width];
            for (int i = 0; i < arr.length; i++) {
                colors[i / width][i % width] = arr[i];
                hash += counts[arr[i]];
                type[arr[i]] = true;
            }
        }
        
        public int hashCode() {
            return hash;
        }
        
        public int getType() {
            int count = 0;
            for (boolean x : type) {
                if (x) {
                    count++;
                }
            }
            return count;
        }
        
        public boolean equals(Object o) {
            Box b = (Box)o;
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    if (equals(b, i, j)) {
                        return true;
                    }
                }
            }
            return false;
        }
        
        private boolean equals(Box b, int r, int c) {
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    if (colors[(i + r) % height][(j + c) % width] != b.colors[i][j]) {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}
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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
            
            
            
        
            
tenten