結果
問題 | No.866 レベルKの正方形 |
ユーザー |
|
提出日時 | 2020-08-05 02:47:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,494 ms / 6,000 ms |
コード長 | 1,445 bytes |
コンパイル時間 | 4,440 ms |
コンパイル使用メモリ | 75,648 KB |
最終ジャッジ日時 | 2025-01-12 14:37:51 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <string>using lint = long long;constexpr int N = 2000;int dss[N + 1][N + 1][27];constexpr int INF = 1 << 30;void solve() {int h, w, k;std::cin >> h >> w >> k;for (int i = 0; i <= h; ++i) {for (int j = 0; j <= w; ++j) {for (int d = 0; d < 27; ++d) {dss[i][j][d] = INF;}}}for (int i = 1; i <= h; ++i) {for (int j = 1; j <= w; ++j) {char c;std::cin >> c;dss[i][j][c - 'a'] = 0;for (int d = 0; d < 27; ++d) {dss[i][j][d] = std::min(dss[i][j][d],std::min({dss[i - 1][j][d],dss[i][j - 1][d],dss[i - 1][j - 1][d]}) +1);}}}lint ans = 0;for (int rx = 1; rx <= h; ++rx) {for (int ry = 1; ry <= w; ++ry) {auto ds = dss[rx][ry];std::sort(ds, ds + 27);int l = std::min(ds[k - 1], std::min(rx, ry));int r = std::min(ds[k], std::min(rx, ry));ans += r - l;}}std::cout << ans << "\n";}int main() {std::cin.tie(nullptr);std::ios::sync_with_stdio(false);solve();return 0;}