結果

問題 No.866 レベルKの正方形
ユーザー vwxyzvwxyz
提出日時 2024-04-14 13:43:41
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,317 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 829,956 KB
最終ジャッジ日時 2024-04-14 13:43:54
合計ジャッジ時間 7,719 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
77,132 KB
testcase_01 AC 109 ms
77,372 KB
testcase_02 AC 95 ms
76,924 KB
testcase_03 AC 101 ms
77,096 KB
testcase_04 AC 110 ms
77,676 KB
testcase_05 AC 110 ms
77,516 KB
testcase_06 AC 121 ms
77,320 KB
testcase_07 AC 112 ms
76,956 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 #

class Cumsum2:
    def __init__(self,lst,mod=0):
        self.H=len(lst)
        self.W=len(lst[0]) if lst else 0
        self.cumsum2=[[0]*(self.W+1) for i in range(self.H+1)]
        for i in range(1,self.H+1):
            for j in range(1,self.W+1):
                self.cumsum2[i][j]=lst[i-1][j-1]
        self.mod=mod
        for i in range(self.H+1):
            for j in range(1,self.W+1):
                self.cumsum2[i][j]+=self.cumsum2[i][j-1]
                if self.mod:
                    self.cumsum2[i][j]%=self.mod
        for i in range(1,self.H+1):
            for j in range(self.W+1):
                self.cumsum2[i][j]+=self.cumsum2[i-1][j]
                if self.mod:
                    self.cumsum2[i][j]%=self.mod

    def __getitem__(self,tpl):
        ab,cd=tpl
        def make_slice(ij,N):
            if type(ij)==int:
                i,j=ij,ij+1
            else:
                i,j=ij.start,ij.stop
                if i==None:
                    i=0
                elif i<-N or N<i:
                    raise IndexError("list index out of range")
                elif -N<=i<0:
                    i+=N
                if j==None:
                    j=N
                elif j<-N or N<j:
                    raise IndexError("list index out of range")
                elif -N<=j<0:
                    j+=N
            return i,j
        a,b=make_slice(ab,self.H)
        c,d=make_slice(cd,self.W)
        retu=self.cumsum2[b][d]+self.cumsum2[a][c]-self.cumsum2[a][d]-self.cumsum2[b][c]
        if self.mod:
            retu%=self.mod
        return retu

    def __str__(self):
        return str(self.cumsum2)

def Bisect_Int(ok,ng,is_ok):
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if is_ok(mid):
            ok=mid
        else:
            ng=mid
    return ok

H,W,K=map(int,input().split())
A=[[ord(a)-97 for a in input()] for h in range(H)]
C=[Cumsum2([[A[h][w]==a for w in range(W)] for h in range(H)]) for a in range(26)]
ans=0
for h in range(H):
    for w in range(W):
        def is_ok(d):
            return sum(1 for a in range(26) if C[a][h:h+d,w:w+d])<K
        ans-=Bisect_Int(1,min(H-h,W-w)+1,is_ok)
        def is_ok(d):
            return sum(1 for a in range(26) if C[a][h:h+d,w:w+d])<K+1
        ans+=Bisect_Int(1,min(H-h,W-w)+1,is_ok)
print(ans)
0