結果

問題 No.866 レベルKの正方形
ユーザー finefine
提出日時 2019-08-17 00:21:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,142 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 171,304 KB
実行使用メモリ 418,656 KB
最終ジャッジ日時 2023-10-24 13:12:39
合計ジャッジ時間 10,039 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 9 ms
40,860 KB
testcase_07 AC 8 ms
38,860 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 <bits/stdc++.h>

using namespace std;

using ll = long long;

int cnt[26][2001][2001];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, K;
    cin >> h >> w >> K;
    vector<string> c(h);
    for (int i = 0; i < h; i++) {
        cin >> c[i];
        for (int j = 0; j < w; j++) {
            cnt[c[i][j] - 'a'][i + 1][j + 1]++;
        }
    }

    for (int i = 0; i <= h; i++) {
        for (int j = 0; j <= w; j++) {
            for (int k = 0; k < 26; k++) {
                if (i > 0) cnt[k][i][j] += cnt[k][i - 1][j];
                if (j > 0) cnt[k][i][j] += cnt[k][i][j - 1];
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int sz = min(i + 1, j + 1);

            int ng = 0, ok = sz + 1;
            while (ok - ng > 1) {
                int mid = (ok + ng) / 2;
                int val = 0;
                for (int k = 0; k < 26; k++) {
                    int hoge = cnt[k][i + 1][j + 1] + cnt[k][i + 1 - mid][j + 1 - mid] - cnt[k][i + 1][j + 1 - mid] - cnt[k][i + 1 - mid][j + 1];
                    val += (hoge > 0);
                }
                if (val >= K) {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }

            if (ok <= 0 || ok > sz) continue;

            int ng2 = sz + 1, ok2 = ok;
            while (ng2 - ok2 > 1) {
                int mid = (ok2 + ng2) / 2;
                int val = 0;
                for (int k = 0; k < 26; k++) {
                    int hoge = cnt[k][i + 1][j + 1] + cnt[k][i + 1 - mid][j + 1 - mid] - cnt[k][i + 1][j + 1 - mid] - cnt[k][i + 1 - mid][j + 1];
                    val += (hoge > 0);
                }
                if (val <= K) {
                    ok2 = mid;
                } else {
                    ng2 = mid;
                }
            }

            if (ok2 <= 0 || ok2 > sz || ok > ok2) continue;
            ans += ok2 - ok + 1;
            //cerr << i << " " << j << ": " << ok << " " << ok2 << endl;
        }
    }
    cout << ans << "\n";
    return 0;
}
0