結果

問題 No.866 レベルKの正方形
ユーザー MisterMister
提出日時 2020-08-05 02:24:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,941 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 69,764 KB
実行使用メモリ 414,144 KB
最終ジャッジ日時 2023-10-13 06:29:46
合計ジャッジ時間 9,847 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,420 KB
testcase_01 AC 3 ms
6,400 KB
testcase_02 AC 3 ms
6,420 KB
testcase_03 AC 3 ms
6,480 KB
testcase_04 AC 3 ms
6,480 KB
testcase_05 AC 4 ms
6,564 KB
testcase_06 AC 3 ms
6,428 KB
testcase_07 AC 3 ms
6,412 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using lint = long long;

constexpr int N = 2000;

int acc[26][N + 1][N + 1];
int get(int lx, int ly, int rx, int ry) {
    int ret = 0;
    for (int d = 0; d < 26; ++d) {
        int c = acc[d][rx][ry] - acc[d][rx][ly - 1] -
                acc[d][lx - 1][ry] + acc[d][lx - 1][ly - 1];
        if (c > 0) ++ret;
    }
    return ret;
}

void solve() {
    int h, w, k;
    std::cin >> h >> w >> k;

    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            char c;
            std::cin >> c;
            ++acc[c - 'a'][i][j];

            for (auto& vv : acc) {
                vv[i][j] += vv[i - 1][j] + vv[i][j - 1] - vv[i - 1][j - 1];
            }
        }
    }

    lint ans = 0;
    for (int lx = 1; lx <= h; ++lx) {
        for (int ly = 1; ly <= w; ++ly) {
            int dl, dr;
            {
                int ok = std::min(h - lx, w - ly) + 1, ng = -1;
                // [lx, lx + ok] * [ly, ly + ok] >= k
                while (ok - ng > 1) {
                    int mid = (ok + ng) / 2;
                    if (get(lx, ly, lx + mid, ly + mid) >= k) {
                        ok = mid;
                    } else {
                        ng = mid;
                    }
                }
                dl = ok;
            }

            {
                int ok = std::min(h - lx, w - ly) + 1, ng = dl - 1;
                // [lx, lx + ok] * [ly, ly + ok] > k
                while (ok - ng > 1) {
                    int mid = (ok + ng) / 2;
                    if (get(lx, ly, lx + mid, ly + mid) > k) {
                        ok = mid;
                    } else {
                        ng = mid;
                    }
                }
                dr = ok;
            }

            ans += dr - dl;
        }
    }

    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0