結果

問題 No.866 レベルKの正方形
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-08-17 19:35:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,649 bytes
コンパイル時間 2,504 ms
コンパイル使用メモリ 204,640 KB
実行使用メモリ 422,080 KB
最終ジャッジ日時 2023-10-25 07:50:02
合計ジャッジ時間 11,473 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
38,904 KB
testcase_01 AC 11 ms
44,916 KB
testcase_02 AC 9 ms
36,860 KB
testcase_03 AC 10 ms
46,876 KB
testcase_04 AC 11 ms
46,884 KB
testcase_05 AC 10 ms
42,908 KB
testcase_06 AC 10 ms
40,876 KB
testcase_07 AC 9 ms
38,876 KB
testcase_08 TLE -
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 #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/










int H, W, K;
string C[2010];
//---------------------------------------------------------------------------------------------------
int buf[26][2010][2010];
void init() {
	rep(y, 1, H + 1) rep(x, 1, W + 1) buf[C[y][x] - 'a'][y][x]++;
	rep(c, 0, 26) rep(y, 1, H + 2) rep(x, 1, W + 2) {
		buf[c][y][x] += buf[c][y - 1][x] + buf[c][y][x - 1] - buf[c][y - 1][x - 1];
	}
}
int get(int x, int y, int length) {
	int res = 0;
	rep(c, 0, 26) if (0 < buf[c][y + length][x + length] - buf[c][y + length][x] - buf[c][y][x + length] + buf[c][y][x]) res++;
	return res;
}
//---------------------------------------------------------------------------------------------------
inline int binarySearch(int x, int y, int l, int r, int limit) { //[l,r)
	if (limit <= get(x, y, l)) return l;
	
	int ng = l, ok = r;
	while (ng + 1 != ok) {
		int md = (ng + ok) / 2;
		if (limit <= get(x, y, md)) ok = md;
		else ng = md;
	}

	return ok;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W >> K;
	rep(y, 1, H + 1) cin >> C[y];
	rep(y, 1, H + 1) C[y] = "#" + C[y];

	init();

	ll ans = 0;
	rep(y, 0, H) rep(x, 0, W) {
		int maxlen = min(W - x, H - y);
		ans += binarySearch(x, y, 1, maxlen + 1, K + 1) - binarySearch(x, y, 1, maxlen + 1, K);
	}
	cout << ans << endl;
}






0