結果

問題 No.866 レベルKの正方形
ユーザー TAISA_TAISA_
提出日時 2019-08-16 23:13:57
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 2,874 ms / 6,000 ms
コード長 2,792 bytes
コンパイル時間 1,441 ms
使用メモリ 411,760 KB
最終ジャッジ日時 2022-11-22 12:47:32
合計ジャッジ時間 38,002 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,544 KB
testcase_01 AC 2 ms
3,408 KB
testcase_02 AC 1 ms
3,456 KB
testcase_03 AC 1 ms
3,528 KB
testcase_04 AC 2 ms
3,400 KB
testcase_05 AC 2 ms
3,404 KB
testcase_06 AC 2 ms
3,456 KB
testcase_07 AC 2 ms
3,416 KB
testcase_08 AC 2,429 ms
411,388 KB
testcase_09 AC 2,626 ms
411,760 KB
testcase_10 AC 2,874 ms
411,704 KB
testcase_11 AC 2,848 ms
411,652 KB
testcase_12 AC 2,330 ms
411,692 KB
testcase_13 AC 2,832 ms
411,652 KB
testcase_14 AC 2,158 ms
411,704 KB
testcase_15 AC 2,820 ms
411,756 KB
testcase_16 AC 2,709 ms
411,740 KB
testcase_17 AC 2,821 ms
411,704 KB
testcase_18 AC 2,814 ms
411,596 KB
testcase_19 AC 2,003 ms
411,596 KB
testcase_20 AC 1,826 ms
411,756 KB
testcase_21 AC 1,703 ms
411,748 KB
testcase_22 AC 1 ms
3,564 KB
testcase_23 AC 2 ms
3,400 KB
testcase_24 AC 2 ms
3,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int co[1 << 11][1 << 11][26];
int h, w, k;
int sum(int y1, int x1, int y2, int x2) {
    int res = 0;
    for (int k = 0; k < 26; k++) {
        if (co[y2][x2][k] - co[y1][x2][k] - co[y2][x1][k] + co[y1][x1][k] > 0) {
            res++;
        }
    }
    return res;
}
ll calc(int p) {
    ll res = 0;
    for (int i = 1; i < h; i++) {
        int y = i, x = 0;
        ll l = 0;
        while (x < w && y < h) {
            while (l <= x && sum(i + l, l, y + 1, x + 1) >= p) {
                l++;
            }
            res += l;
            x++;
            y++;
        }
    }
    for (int i = 0; i < w; i++) {
        int y = 0, x = i;
        int l = 0;
        while (x < w && y < h) {
            while (l <= y && sum(l, i + l, y + 1, x + 1) >= p) {
                l++;
            }
            res += l;
            x++;
            y++;
        }
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w >> k;
    string s;
    for (int i = 0; i < h; i++) {
        cin >> s;
        for (int j = 0; j < w; j++) {
            co[i + 1][j + 1][s[j] - 'a']++;
        }
    }
    for (int i = 0; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            for (int k = 0; k < 26; k++) {
                co[i][j][k] += co[i][j - 1][k];
            }
        }
    }
    for (int j = 0; j <= w; j++) {
        for (int i = 1; i <= h; i++) {
            for (int k = 0; k < 26; k++) {
                co[i][j][k] += co[i - 1][j][k];
            }
        }
    }
    cout << calc(k) - calc(k + 1) << '\n';
}
0