結果

問題 No.866 レベルKの正方形
ユーザー 👑 kmjpkmjp
提出日時 2019-08-16 22:02:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,559 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 169,820 KB
実行使用メモリ 433,836 KB
最終ジャッジ日時 2023-10-23 23:27:20
合計ジャッジ時間 67,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 4,530 ms
433,732 KB
testcase_09 AC 4,848 ms
433,796 KB
testcase_10 AC 5,291 ms
433,328 KB
testcase_11 AC 5,847 ms
433,336 KB
testcase_12 AC 3,563 ms
430,276 KB
testcase_13 TLE -
testcase_14 AC 3,772 ms
431,280 KB
testcase_15 AC 5,740 ms
433,288 KB
testcase_16 AC 5,136 ms
432,268 KB
testcase_17 AC 5,404 ms
433,292 KB
testcase_18 AC 5,319 ms
433,172 KB
testcase_19 AC 2,647 ms
427,600 KB
testcase_20 AC 668 ms
418,060 KB
testcase_21 AC 4,786 ms
433,836 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int H,W,K;
string S[2020];
int C[2020][2020][26];
int PL[2020][2020];

int num(int y,int x,int s) {
	int num=0,i;
	FOR(i,26) if(C[y+s][x+s][i]-C[y][x+s][i]-C[y+s][x][i]+C[y][x][i]>0) {
		num++;
		if(num>K) return num;
		if(num+(26-i)<K) return num;
	}
	return num;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>K;
	FOR(y,H) {
		cin>>S[y];
		FOR(x,W) {
			FOR(i,26) {
				C[y+1][x+1][i]=C[y][x+1][i]+C[y+1][x][i]-C[y][x][i];
				if(S[y][x]=='a'+i) C[y+1][x+1][i]++;
			}
		}
	}
	
	ll ret=0;
	FOR(y,H) FOR(x,W) {
		int L=0,R=min(H-y,W-x);
		if(num(y,x,R)<K) continue;
		if(num(y,x,R)==K) R++;
		if(y) L=max(L,PL[y-1][x]-1);
		if(x) L=max(L,PL[y][x-1]-1);
		if(y&&x) L=max(L,PL[y-1][x-1]-1);
		
		for(i=10;i>=0;i--) {
			if(L+(1<<i)<R && num(y,x,L+(1<<i))<K) L+=1<<i;
			if(R-(1<<i)>L && num(y,x,R-(1<<i))>K) R-=1<<i;
		}
		ret+=R-L-1;
		PL[y][x]=L;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0