結果

問題 No.866 レベルKの正方形
ユーザー mkawa2mkawa2
提出日時 2021-05-24 22:41:32
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,240 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 531,544 KB
最終ジャッジ日時 2024-04-21 08:11:13
合計ジャッジ時間 10,034 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
53,028 KB
testcase_01 AC 47 ms
53,088 KB
testcase_02 AC 48 ms
53,340 KB
testcase_03 AC 48 ms
53,648 KB
testcase_04 AC 49 ms
54,104 KB
testcase_05 AC 49 ms
53,832 KB
testcase_06 AC 47 ms
52,676 KB
testcase_07 AC 47 ms
52,884 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def BI(): return sys.stdin.buffer.readline().rstrip()
inf = 10**16

h, w, k = LI()
max_e = min(h, w).bit_length()-1
tt = [[0]*h*w for _ in range(max_e+1)]
tt[0] = [1 << c-97 for _ in range(h) for c in BI()]

for e in range(max_e):
    d = 1 << e
    for i in range(h):
        if i+d*2 > h: break
        for j in range(w):
            if j+d*2 > w: break
            ij = i*w+j
            tt[e+1][ij] = tt[e][ij] | tt[e][ij+d] | tt[e][ij+d*w] | tt[e][ij+d*w+d]

# i行目[l,r]を1辺とする正方形内の文字種類数
def cnt_in_square(i, l, r):
    d = r-l+1
    if i+d > h: return inf
    if l == r: return 1
    e = (d-1).bit_length()-1
    m = d-(1 << e)
    ij = i*w+l
    s = tt[e][ij] | tt[e][ij+m] | tt[e][ij+m*w] | tt[e][ij+m*w+m]
    return bin(s).count("1")

ans = 0
for i in range(h):
    r0 = r1 = 0
    for l in range(w):
        if r0 < l: r0 = l
        while r0 < w and cnt_in_square(i, l, r0) < k:
            r0 += 1
            if r0 == w: break
        if r1 < r0: r1 = r0
        while r1 < w and cnt_in_square(i, l, r1) <= k:
            r1 += 1
        ans += r1-r0

print(ans)
0