結果

問題 No.866 レベルKの正方形
ユーザー first_vilfirst_vil
提出日時 2020-06-11 18:11:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,302 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 100,132 KB
実行使用メモリ 431,748 KB
最終ジャッジ日時 2023-09-06 08:21:16
合計ジャッジ時間 9,685 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 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 #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using VI = vector<int>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define each(i, a) for(auto &i : a)
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }

template<class T> class acc2d {
    int h, w;
    vector<vector<T>>& dat;
public:
    acc2d(vector<vector<T>>& _dat) : dat(_dat), h(_dat.size()), w(_dat[0].size()) {
        FOR(i, 0, h)FOR(j, 1, w)dat[i][j] += dat[i][j - 1];
        FOR(i, 1, h)FOR(j, 0, w)dat[i][j] += dat[i - 1][j];
    }
    T sum(int y1, int x1, int y2, int x2) {
        T ret = dat[y2][x2];
        if (0 < y1)ret -= dat[y1 - 1][x2];
        if (0 < x1)ret -= dat[y2][x1 - 1];
        if (0 < y1 && 0 < x1)ret += dat[y1 - 1][x1 - 1];
        return ret;
    }
    T sum(int y2, int x2) { return sum(0, 0, y2, x2); }
};

int main() {
    int h, w, k; scanf("%d %d %d", &h, &w, &k);
    auto dat = vec<int>(26, h, w);
    FOR(y, 0, h) {
        string s; cin >> s;
        FOR(x, 0, w)++dat[s[x] - 'a'][y][x];
    }
    vector<acc2d<int>> acc;
    each(i, dat)acc.emplace_back(i);

    ll ans = 0;
    FOR(y, 0, h)FOR(x, 0, w) {
        int l, r;
        {
            int ok = 0, ng = min(h - y, w - x) + 1;
            while (ng - ok > 1) {
                int mid = ok + ng >> 1;
                int kind = 0;
                FOR(i, 0, 26) {
                    if (acc[i].sum(y, x, y + mid - 1, x + mid - 1))++kind;
                }
                if (kind <= k)ok = mid;
                else ng = mid;
            }
            r = ok;
        }
        {
            int ok = 0, ng = r + 1;
            while (ng - ok > 1) {
                int mid = ok + ng >> 1;
                int kind = 0;
                FOR(i, 0, 26) {
                    if (acc[i].sum(y, x, y + mid - 1, x + mid - 1))++kind;
                }
                if (kind < k)ok = mid;
                else ng = mid;
            }
            l = ok;
        }
        ans += r - l;
    }
    printf("%lld\n", ans);

    return 0;
}
0