結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
427,636 KB
testcase_01 AC 201 ms
427,636 KB
testcase_02 AC 202 ms
427,636 KB
testcase_03 AC 201 ms
427,636 KB
testcase_04 AC 202 ms
427,636 KB
testcase_05 AC 203 ms
427,636 KB
testcase_06 AC 203 ms
427,636 KB
testcase_07 AC 202 ms
427,636 KB
testcase_08 AC 3,216 ms
431,536 KB
testcase_09 AC 2,660 ms
431,536 KB
testcase_10 AC 2,472 ms
431,536 KB
testcase_11 AC 3,120 ms
431,536 KB
testcase_12 AC 2,766 ms
431,536 KB
testcase_13 AC 3,161 ms
431,536 KB
testcase_14 WA -
testcase_15 AC 3,076 ms
431,536 KB
testcase_16 AC 2,931 ms
431,536 KB
testcase_17 AC 2,763 ms
431,536 KB
testcase_18 AC 3,100 ms
431,536 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1,837 ms
431,536 KB
testcase_22 AC 204 ms
427,624 KB
testcase_23 AC 203 ms
427,624 KB
testcase_24 AC 204 ms
427,656 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 += 1LL* ( min(h+1-i, w+1-j)+1-dp[i][j][k-1]); continue;}
			ans += 1LL * (dp[i][j][k] - dp[i][j][k-1]);
		}
	}
	cout << ans << endl;
    return 0;
}
0