結果
問題 |
No.866 レベルKの正方形
|
ユーザー |
![]() |
提出日時 | 2020-06-10 00:50:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,472 bytes |
コンパイル時間 | 945 ms |
コンパイル使用メモリ | 83,636 KB |
実行使用メモリ | 415,104 KB |
最終ジャッジ日時 | 2024-06-11 07:54:04 |
合計ジャッジ時間 | 9,800 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 7 WA * 1 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 l = 1, r = min(H-h1-1, W-w1-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 << ans << endl; }