結果

問題 No.866 レベルKの正方形
ユーザー uenokuuenoku
提出日時 2020-04-28 21:54:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,001 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 166,244 KB
実行使用メモリ 431,176 KB
最終ジャッジ日時 2023-08-16 19:36:20
合計ジャッジ時間 10,031 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,552 KB
testcase_01 AC 3 ms
6,444 KB
testcase_02 AC 3 ms
6,516 KB
testcase_03 AC 3 ms
6,488 KB
testcase_04 AC 3 ms
6,452 KB
testcase_05 AC 3 ms
6,724 KB
testcase_06 AC 3 ms
6,620 KB
testcase_07 AC 3 ms
6,448 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>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
int c[2005][2005];
int sum[26][2005][2005] = {};
lli f(int l, int i, int j, int p)
{
    return sum[l][i + p][j + p] - sum[l][i + p][j] - sum[l][i][j + p] + sum[l][i][j];
}
lli h,
    w, k;
lli calc(int i, int j, int p)
{
    // [up, n)でp種類以上
    lli up1 = min(h - i, w - j) + 1;
    lli low1 = 0;

    while (up1 - low1 > 1)
    {
        lli mid = (up1 + low1) / 2;
        lli cnt = 0;
        rep(l, 26)
            cnt += (f(l, i, j, mid) >= 1);
        (cnt >= p ? up1 : low1) = mid;
    }
    lli up2 = up1;
    lli low2 = 0;
    p--;
    while (up2 - low2 > 1)
    {
        lli mid = (up2 + low2) / 2;
        lli cnt = 0;
        rep(l, 26)
            cnt += (f(l, i, j, mid) >= 1);
        (cnt >= p ? up2 : low2) = mid;
    }

    return up1 - up2;
}
int main()
{
    cin >> h >> w >> k;
    rep(i, h) rep(j, w)
    {
        char ch;
        cin >> ch;
        c[i][j] = ch - 'a';
    }
    rep(l, 26)
    {
        rep(i, h) rep(j, w)
            sum[l][i + 1][j + 1] = sum[l][i][j + 1] + sum[l][i + 1][j] - sum[l][i][j] + int(c[i][j] == l);
    }
    lli ret = 0;
    rep(i, h) rep(j, w)
    {
        // cout << i << " " << j << " " << calc(i, j, k) << endl;
        // cout << i << " " << j << " " << calc(i, j, k + 1) << endl;
        ret += calc(i, j, k + 1);
    }
    cout << ret << endl;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
    return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
    return (l < r) ? (l = r, true) : false;
}
0