結果

問題 No.866 レベルKの正方形
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-08-17 20:24:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,591 ms / 6,000 ms
コード長 2,493 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 205,852 KB
実行使用メモリ 416,216 KB
最終ジャッジ日時 2023-10-25 08:54:03
合計ジャッジ時間 46,159 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,728 KB
testcase_01 AC 2 ms
5,728 KB
testcase_02 AC 3 ms
5,728 KB
testcase_03 AC 3 ms
5,728 KB
testcase_04 AC 2 ms
5,728 KB
testcase_05 AC 2 ms
5,728 KB
testcase_06 AC 2 ms
5,728 KB
testcase_07 AC 2 ms
5,728 KB
testcase_08 AC 2,072 ms
416,176 KB
testcase_09 AC 2,327 ms
416,180 KB
testcase_10 AC 3,382 ms
416,180 KB
testcase_11 AC 3,483 ms
416,180 KB
testcase_12 AC 3,112 ms
416,180 KB
testcase_13 AC 3,591 ms
416,180 KB
testcase_14 AC 2,976 ms
416,180 KB
testcase_15 AC 3,210 ms
416,180 KB
testcase_16 AC 3,467 ms
416,180 KB
testcase_17 AC 3,387 ms
416,180 KB
testcase_18 AC 3,464 ms
416,180 KB
testcase_19 AC 2,687 ms
416,180 KB
testcase_20 AC 2,017 ms
416,216 KB
testcase_21 AC 3,013 ms
416,212 KB
testcase_22 AC 2 ms
5,728 KB
testcase_23 AC 2 ms
5,728 KB
testcase_24 AC 3 ms
7,784 KB
権限があれば一括ダウンロードができます

ソースコード

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[2010][2010][26];
void init() {
	rep(y, 0, H) rep(x, 0, W) buf[y + 1][x + 1][C[y][x] - 'a']++;
	rep(c, 0, 26) rep(y, 1, H + 2) rep(x, 1, W + 2) {
		buf[y][x][c] += buf[y - 1][x][c] + buf[y][x - 1][c] - buf[y - 1][x - 1][c];
	}
}
//---------------------------------------------------------------------------------------------------
inline int binarySearch(int x, int y, int l, int r, int limit) { //[l,r)
	int ng = l - 1, ok = r;
	while (ng + 1 != ok) {
		int md = (ng + ok) / 2;

		int res = 0;
		rep(c, 0, 26) if (0 < buf[y + md][x + md][c] - buf[y + md][x][c] - buf[y][x + md][c] + buf[y][x][c]) res++;

		if (limit <= res) ok = md;
		else ng = md;
	}

	return ok;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W >> K;
	rep(y, 0, H) cin >> 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