結果

問題 No.1797 永遠のグリッド
ユーザー tentententen
提出日時 2022-01-05 10:08:28
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,155 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 78,360 KB
実行使用メモリ 67,784 KB
最終ジャッジ日時 2024-04-23 14:14:42
合計ジャッジ時間 13,879 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
36,936 KB
testcase_01 AC 44 ms
36,488 KB
testcase_02 AC 44 ms
36,888 KB
testcase_03 AC 46 ms
36,896 KB
testcase_04 AC 46 ms
37,272 KB
testcase_05 AC 44 ms
37,216 KB
testcase_06 AC 46 ms
36,896 KB
testcase_07 AC 45 ms
36,948 KB
testcase_08 AC 44 ms
36,520 KB
testcase_09 AC 67 ms
38,716 KB
testcase_10 AC 45 ms
36,640 KB
testcase_11 AC 45 ms
37,240 KB
testcase_12 AC 52 ms
36,632 KB
testcase_13 AC 51 ms
36,588 KB
testcase_14 AC 45 ms
37,088 KB
testcase_15 AC 47 ms
37,096 KB
testcase_16 AC 47 ms
36,960 KB
testcase_17 AC 459 ms
63,624 KB
testcase_18 AC 1,794 ms
66,476 KB
testcase_19 AC 45 ms
37,080 KB
testcase_20 AC 1,910 ms
66,924 KB
testcase_21 AC 461 ms
65,380 KB
testcase_22 AC 147 ms
40,836 KB
testcase_23 AC 1,877 ms
67,784 KB
testcase_24 AC 160 ms
42,824 KB
testcase_25 AC 543 ms
67,240 KB
testcase_26 TLE -
testcase_27 AC 46 ms
37,112 KB
testcase_28 AC 44 ms
37,240 KB
testcase_29 AC 458 ms
65,768 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;
        int[][] colors;
        int hash;
        int[] type = new int[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 += pow(100, arr[i]);
                type[arr[i]]++;
            }
        }
        
        static int pow(int x, int p) {
            if (p == 0) {
                return 1;
            } else {
                return x * pow(x, p - 1);
            }
        }
        
        public int hashCode() {
            return hash;
        }
        
        public int getType() {
            int count = 0;
            for (int x : type) {
                if (x > 0) {
                    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