結果

問題 No.866 レベルKの正方形
ユーザー at_tokioat_tokio
提出日時 2019-08-17 12:40:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,422 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 170,656 KB
実行使用メモリ 431,628 KB
最終ジャッジ日時 2023-10-25 00:13:05
合計ジャッジ時間 48,218 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
427,652 KB
testcase_01 AC 249 ms
427,724 KB
testcase_02 AC 246 ms
427,724 KB
testcase_03 AC 247 ms
427,724 KB
testcase_04 AC 248 ms
427,724 KB
testcase_05 AC 256 ms
427,724 KB
testcase_06 AC 248 ms
427,724 KB
testcase_07 AC 245 ms
427,724 KB
testcase_08 AC 3,310 ms
431,624 KB
testcase_09 AC 2,744 ms
431,624 KB
testcase_10 AC 2,566 ms
431,624 KB
testcase_11 AC 3,213 ms
431,624 KB
testcase_12 AC 2,854 ms
431,624 KB
testcase_13 AC 3,318 ms
431,624 KB
testcase_14 WA -
testcase_15 AC 3,140 ms
431,624 KB
testcase_16 AC 3,031 ms
431,624 KB
testcase_17 AC 2,859 ms
431,624 KB
testcase_18 AC 3,197 ms
431,624 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1,913 ms
431,624 KB
testcase_22 AC 245 ms
427,712 KB
testcase_23 AC 244 ms
427,712 KB
testcase_24 AC 245 ms
427,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60; const ll mod=1e9+7; const int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------
int h,w,k;
char table[2000+5][2000+5];
int dp[2000+5][2000+5][27];
int base = int('a');

int main(){
	cin >> h >> w >> k;
	ll ans = 0;
	memset(dp,INF,sizeof(dp));
	FOR(i,1,h) FOR(j,1,w){
		cin >> table[i][j];
	}
	for(int a=0; a<26;a++){
		for(int i=h+1; i>=1; i--){
			for(int j=w+1; j>=1; j--){
				if(table[i][j] == char(base+a)){
					dp[i][j][a] = 1; continue;
				}
				dp[i][j][a] = min(dp[i+1][j+1][a], min(dp[i+1][j][a],dp[i][j+1][a]))+1;
				//dp[i][j][a] = min(dp[i][j][a], min(h+1-i, w+1-j)+1);
			}
		}
	}
	FOR(i,1,h){
		FOR(j,1,w){
			sort(dp[i][j], dp[i][j]+26);
			if(dp[i][j][k-1] >= INF) continue;
			else if(dp[i][j][k] >= INF){ ans += min(h+1-i, w+1-j); continue;}
			ans += 1LL * (dp[i][j][k] - dp[i][j][k-1]);
		}
	}
	cout << ans << endl;
    return 0;
}
0