結果

問題 No.1797 永遠のグリッド
ユーザー tentententen
提出日時 2022-01-05 10:11:17
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,035 bytes
コンパイル時間 2,400 ms
コンパイル使用メモリ 79,012 KB
実行使用メモリ 79,168 KB
最終ジャッジ日時 2024-04-23 14:16:59
合計ジャッジ時間 15,633 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
50,052 KB
testcase_01 AC 54 ms
50,332 KB
testcase_02 AC 55 ms
50,048 KB
testcase_03 AC 54 ms
50,120 KB
testcase_04 AC 55 ms
50,408 KB
testcase_05 AC 55 ms
50,348 KB
testcase_06 AC 55 ms
50,456 KB
testcase_07 AC 54 ms
49,924 KB
testcase_08 AC 54 ms
50,440 KB
testcase_09 AC 89 ms
51,584 KB
testcase_10 AC 54 ms
49,860 KB
testcase_11 AC 54 ms
50,432 KB
testcase_12 AC 64 ms
50,692 KB
testcase_13 AC 65 ms
50,576 KB
testcase_14 AC 55 ms
50,356 KB
testcase_15 AC 53 ms
50,348 KB
testcase_16 AC 55 ms
50,428 KB
testcase_17 AC 516 ms
76,692 KB
testcase_18 TLE -
testcase_19 AC 55 ms
50,036 KB
testcase_20 TLE -
testcase_21 AC 502 ms
76,556 KB
testcase_22 AC 153 ms
52,828 KB
testcase_23 TLE -
testcase_24 AC 178 ms
55,176 KB
testcase_25 AC 604 ms
78,168 KB
testcase_26 TLE -
testcase_27 AC 54 ms
50,388 KB
testcase_28 AC 54 ms
50,028 KB
testcase_29 AC 514 ms
76,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0