結果
| 問題 | No.866 レベルKの正方形 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-27 16:57:17 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 815 ms / 6,000 ms |
| + 956µs | |
| コード長 | 1,438 bytes |
| 記録 | |
| コンパイル時間 | 4,559 ms |
| コンパイル使用メモリ | 353,136 KB |
| 実行使用メモリ | 446,336 KB |
| 最終ジャッジ日時 | 2026-08-27 16:57:49 |
| 合計ジャッジ時間 | 17,498 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
// <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";
}