結果
| 問題 |
No.866 レベルKの正方形
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-15 21:12:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,473 bytes |
| コンパイル時間 | 2,129 ms |
| コンパイル使用メモリ | 139,864 KB |
| 最終ジャッジ日時 | 2025-01-19 17:23:38 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 TLE * 14 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template<class T>
inline bool chmax(T& x, T y){
if(x < y){
x = y;
return true;
}
return false;
}
template<class T>
inline bool chmin(T& x, T y){
if(x > y){
x = y;
return true;
}
return false;
}
template<typename T>
struct CumulativeSum2D{
vector<vector<T>> data;
CumulativeSum2D(int W, int H) : data(W + 1, vector<T>(H + 1, 0)) {}
void add(int x, int y, T z){
++x, ++y;
if(x >= data.size() || y >= data[0].size()) return;
data[x][y] += z;
}
void build(){
for(int i = 1; i < (int)data.size(); ++i){
for(int j = 1; j < (int)data[i].size(); ++j){
data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
}
}
}
T query(int sx, int sy, int gx, int gy){
return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W, K;
cin >> H >> W >> K;
vector<CumulativeSum2D<int>> S(26, CumulativeSum2D<int>(H, W));
vector<vector<char>> c(H, vector<char>(W));
for(int i = 0; i < H; ++i){
for(int j = 0; j < W; ++j){
cin >> c[i][j];
S[c[i][j] - 'a'].add(i, j, 1);
}
}
for(int i = 0; i < 26; ++i) S[i].build();
int ans = 0;
for(int x = 0; x < H; ++x){
for(int y = 0; y < W; ++y){
for(int i = 1; i <= min(H, W); ++i){
if(x + i > H || y + i > W) continue;
int cnt = 0;
for(int j = 0; j < 26; ++j){
cnt += S[j].query(x, y, x + i, y + i) > 0;
}
if(cnt > K) break;
ans += cnt == K;
}
}
}
cout << ans << endl;
return 0;
}