結果
| 問題 | 
                            No.1797 永遠のグリッド
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-01-01 00:25:41 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 544 bytes | 
| コンパイル時間 | 200 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 51,152 KB | 
| 最終ジャッジ日時 | 2024-10-09 10:21:01 | 
| 合計ジャッジ時間 | 16,964 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | -- * 3 | 
| other | AC * 18 TLE * 1 -- * 8 | 
ソースコード
import numpy as np
import itertools
H, W, K = map(int, input().split())
pow_table = (K ** np.arange(H * W, dtype=np.int32)).reshape((H, W))
pow_hash = lambda x: np.sum(x * pow_table)
st = set()
for t in itertools.product(range(K), repeat=H * W):
    if len(set(t)) != K:
        continue
    grid = np.array(t).reshape((H, W))
    g4 = np.tile(grid, (2, 2))
    for h, w in itertools.product(range(H), range(W)):
        if pow_hash(g4[h:h + H, w:w + W].data) in st:
            break
    else:
        st.add(pow_hash(grid))
print(len(st))