結果

問題 No.866 レベルKの正方形
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-05-21 12:03:51
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,427 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 81,480 KB
実行使用メモリ 840,776 KB
最終ジャッジ日時 2023-10-20 15:52:51
合計ジャッジ時間 6,438 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
66,044 KB
testcase_01 AC 47 ms
66,040 KB
testcase_02 AC 49 ms
66,044 KB
testcase_03 AC 48 ms
66,040 KB
testcase_04 AC 48 ms
66,048 KB
testcase_05 AC 48 ms
66,040 KB
testcase_06 AC 48 ms
63,992 KB
testcase_07 AC 48 ms
63,996 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 #

h,w,k = map(int,input().split())
C = [[ord(x)-ord("a") for x in input()] for i in range(h)]
accum = [[[0]*26 for i in range(w+1)] for i in range(h+1)]
for i in range(h):
    for j in range(w):
        c = C[i][j]
        for t in range(26):
            accum[i+1][j+1][t] = accum[i+1][j][t]+accum[i][j+1][t]-accum[i][j][t]
        accum[i+1][j+1][c] += 1

def add(l,x,y,f):
    ll = accum[x][y]
    for i in range(26):
        l[i] += ll[i]*f
    return l

def calc(a,b,c,d):

    l = [0]*26
    l = add(l,c,d,1)
    l = add(l,a-1,b-1,1)
    l = add(l,c,b-1,-1)
    l = add(l,a-1,d,-1)
    num = 0
    for i in l:
        if i > 0:
            num += 1
    return num


ans = 0

for i in range(1,h+1):

    lx,ly = i,1
    rx,ry = i,1

    for j in range(i,h+1):
        x,y = j,(j-i)+1
        while lx < h+1 and calc(x,y,lx,ly) < k:
            lx,ly = lx+1,ly+1

        while rx < h+1 and calc(x,y,rx,ry) <= k:
            rx,ry = rx+1,ry+1

        if lx >= h+1:
            break
        if calc(x,y,lx,ly) == k:
            ans += rx-lx


for i in range(2,w+1):
    
    lx,ly = 1,i
    rx,ry = 1,i

    for j in range(i,w+1):
        x,y = (j-i)+1,j
        while ly < w+1 and calc(x,y,lx,ly) < k:
            lx,ly = lx+1,ly+1

        while ry < w+1 and calc(x,y,rx,ry) <= k:
            rx,ry = rx+1,ry+1

        if ly >= w+1:
            break
        if calc(x,y,lx,ly) == k:
            ans += rx-lx
print(ans)

0