結果

問題 No.866 レベルKの正方形
ユーザー 👑 kmjpkmjp
提出日時 2019-08-16 21:56:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4,039 ms / 6,000 ms
コード長 1,413 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 169,892 KB
実行使用メモリ 419,836 KB
最終ジャッジ日時 2023-10-23 23:01:13
合計ジャッジ時間 45,613 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2,836 ms
418,032 KB
testcase_09 AC 2,787 ms
418,100 KB
testcase_10 AC 3,604 ms
419,836 KB
testcase_11 AC 3,834 ms
419,836 KB
testcase_12 AC 2,280 ms
419,836 KB
testcase_13 AC 4,039 ms
419,836 KB
testcase_14 AC 2,367 ms
419,836 KB
testcase_15 AC 3,660 ms
419,836 KB
testcase_16 AC 3,631 ms
419,836 KB
testcase_17 AC 3,640 ms
419,836 KB
testcase_18 AC 3,532 ms
419,836 KB
testcase_19 AC 1,671 ms
419,836 KB
testcase_20 AC 467 ms
419,836 KB
testcase_21 AC 3,776 ms
419,832 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 2 ms
4,372 KB
testcase_24 AC 2 ms
4,372 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 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++;
	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++;
		
		for(i=11;i>=0;i--) {
			if(y+L+(1<<i)<=H && x+L+(1<<i)<=W) {
				if(num(y,x,L+(1<<i))<K) L+=1<<i;
			}
			if(R-(1<<i)>=0) {
				if(num(y,x,R-(1<<i))>K) R-=1<<i;
			}
		}
		ret+=R-L-1;
		
	}
	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