結果
問題 |
No.866 レベルKの正方形
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:50:12 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,010 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 82,640 KB |
実行使用メモリ | 849,796 KB |
最終ジャッジ日時 | 2025-03-20 20:50:20 |
合計ジャッジ時間 | 4,162 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 8 MLE * 1 -- * 13 |
ソースコード
H, W, K = map(int, input().split()) grid = [input().strip() for _ in range(H)] # Initialize prefix sums for each character prefix = [[[0]*(W+1) for _ in range(H+1)] for __ in range(26)] for c in range(26): char = chr(ord('a') + c) for i in range(1, H+1): for j in range(1, W+1): current = 1 if grid[i-1][j-1] == char else 0 prefix[c][i][j] = prefix[c][i-1][j] + prefix[c][i][j-1] - prefix[c][i-1][j-1] + current count = 0 max_size = min(H, W) for s in range(1, max_size + 1): for a in range(1, H - s + 2): for b in range(1, W - s + 2): a_end = a + s - 1 b_end = b + s - 1 unique = 0 for c in range(26): if unique > K: break total = prefix[c][a_end][b_end] - prefix[c][a-1][b_end] - prefix[c][a_end][b-1] + prefix[c][a-1][b-1] if total > 0: unique += 1 if unique == K: count += 1 print(count)