結果
| 問題 |
No.866 レベルKの正方形
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-06-10 01:02:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,616 bytes |
| コンパイル時間 | 2,784 ms |
| コンパイル使用メモリ | 83,516 KB |
| 実行使用メモリ | 415,232 KB |
| 最終ジャッジ日時 | 2024-06-11 14:48:32 |
| 合計ジャッジ時間 | 9,418 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 8 TLE * 1 -- * 13 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int cnt[26][2001][2001];
int H, W, K;
bool exist(int h1, int w1, int h2, int w2, char c){
return cnt[c-'a'][h2+1][w2+1]-cnt[c-'a'][h1][w2+1]-cnt[c-'a'][h2+1][w1]+cnt[c-'a'][h1][w1] > 0;
}
int sum(int h1, int w1, int h2, int w2){
int ans = 0;
for(int i = 0; i < 26; i++){
if(exist(h1, w1, h2, w2, 'a'+i)) ans++;
}
return ans;
}
int search_upper(int h1, int w1, int m){
if(sum(h1, w1, h1+1, w1+1) > m) return 0;
int r = min(H-h1-1, W-w1-1);
int l = min(1, r);
// int l = 1;
if(sum(h1, w1, h1+r, w1+r) == m) return r;
while(r-l > 1){
int c = (l+r)/2;
if(sum(h1, w1, h1+c, w1+c) > m) r = c;
else l = c;
}
return l;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> H >> W >> K;
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
char c;
cin >> c;
for(int k = 0; k < 26; k++){
cnt[k][i+1][j+1] = cnt[k][i+1][j]+cnt[k][i][j+1]-cnt[k][i][j];
if(c == 'a'+k) cnt[k][i+1][j+1]++;
}
}
}
ll ans = 0;
for(int i = 0; i < H; i++){
for(int j = 0; j < W; j++){
ans += max(0, search_upper(i, j, K)-search_upper(i, j, K-1));
// cout << i << ' ' << j << ' ' << max(0, search_upper(i, j, K)-search_upper(i, j, K-1)) << endl;
}
}
cout << ans << endl;
}
milanis48663220