結果

問題 No.866 レベルKの正方形
コンテスト
ユーザー zengyongxu-jerry
提出日時 2026-08-25 20:48:56
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 798 ms / 6,000 ms
+ 33µs
コード長 1,438 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,086 ms
コンパイル使用メモリ 352,852 KB
実行使用メモリ 446,336 KB
最終ジャッジ日時 2026-08-25 20:49:29
合計ジャッジ時間 18,967 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// <DATETIME>
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define rep(i, x, y) for (int i = (x); i <= (y); i ++ )
#define per(i, x, y) for (int i = (x); i >= (y); i -- )
const int N = 2000 + 5, M = 1e6 + 5;
const int inf = 1e9, mod = 998244353;
const ll INF = 1e18, RMX = 2324814;
mt19937 rd(time(0));
uniform_int_distribution<int> dist(0, RMX);

int n, m, k;
int lt[N][N], rt[N][N];
char a[N][N];
int pre[N][N][26];

int calc(int a, int b, int c, int d){
	int res = 0;
	rep(x, 0, 25){
		int cnt = pre[c][d][x] - pre[a - 1][d][x] - pre[c][b - 1][x] + pre[a - 1][b - 1][x];
		if (cnt) res ++ ;
	}
	return res;
}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    cin >> n >> m >> k;
    rep(i, 1, n) rep(j, 1, m) cin >> a[i][j];
    rep(i, 1, n){
		rep(j, 1, m){
			rep(x, 0, 25) pre[i][j][x] = pre[i][j - 1][x] + pre[i - 1][j][x] - pre[i - 1][j - 1][x];
			pre[i][j][a[i][j] - 'a'] ++ ;
		}
	}
    
    ll awa = 0;
    rep(i, 1, n){
		rep(j, 1, m){
			lt[i][j] = max(0, lt[i - 1][j - 1] - 1);
			rt[i][j] = max(0, rt[i - 1][j - 1] - 1);
			
			while (i + lt[i][j] <= n && j + lt[i][j] <= m && calc(i, j, i + lt[i][j], j + lt[i][j]) < k) lt[i][j] ++ ;
			while (i + rt[i][j] <= n && j + rt[i][j] <= m && calc(i, j, i + rt[i][j], j + rt[i][j]) <= k) rt[i][j] ++ ;
			awa += rt[i][j] - lt[i][j];
		}
	}
	cout << awa << "\n";
}
0