結果

問題 No.866 レベルKの正方形
ユーザー uenokuuenoku
提出日時 2020-04-28 22:12:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,892 ms / 6,000 ms
コード長 2,091 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 167,540 KB
実行使用メモリ 427,316 KB
最終ジャッジ日時 2023-08-16 20:08:04
合計ジャッジ時間 50,480 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,500 KB
testcase_01 AC 2 ms
5,448 KB
testcase_02 AC 1 ms
5,496 KB
testcase_03 AC 2 ms
5,444 KB
testcase_04 AC 2 ms
5,452 KB
testcase_05 AC 2 ms
5,456 KB
testcase_06 AC 1 ms
5,516 KB
testcase_07 AC 1 ms
5,512 KB
testcase_08 AC 2,153 ms
427,060 KB
testcase_09 AC 2,388 ms
427,216 KB
testcase_10 AC 3,341 ms
427,124 KB
testcase_11 AC 3,417 ms
427,016 KB
testcase_12 AC 3,732 ms
427,216 KB
testcase_13 AC 3,444 ms
427,316 KB
testcase_14 AC 3,739 ms
427,092 KB
testcase_15 AC 3,221 ms
427,316 KB
testcase_16 AC 3,892 ms
427,032 KB
testcase_17 AC 3,306 ms
427,012 KB
testcase_18 AC 3,437 ms
427,016 KB
testcase_19 AC 3,552 ms
427,156 KB
testcase_20 AC 3,215 ms
427,060 KB
testcase_21 AC 3,583 ms
427,096 KB
testcase_22 AC 2 ms
5,428 KB
testcase_23 AC 2 ms
5,428 KB
testcase_24 AC 2 ms
5,520 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int calc(int, int, int)’ 内:
main.cpp:25:15: 警告: ‘h’ is used uninitialized [-Wuninitialized]
   25 |     const int h = h;
      |               ^
main.cpp:25:15: 備考: ‘h’ はここで定義されています
   25 |     const int h = h;
      |               ^
main.cpp:26:15: 警告: ‘w’ is used uninitialized [-Wuninitialized]
   26 |     const int w = w;
      |               ^
main.cpp:26:15: 備考: ‘w’ はここで定義されています
   26 |     const int w = w;
      |               ^
main.cpp:27:15: 警告: ‘k’ is used uninitialized [-Wuninitialized]
   27 |     const int k = k;
      |               ^
main.cpp:27:15: 備考: ‘k’ はここで定義されています
   27 |     const int k = k;
      |               ^

ソースコード

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[2005][2005][26] = {};
inline int f(int l, int i, int j, int p)
{
    return sum[i + p][j + p][l] - sum[i + p][j][l] - sum[i][j + p][l] + sum[i][j][l];
}
int h, w, k;
int calc(int i, int j, int p)
{
    // [up, n)でp種類以上
    int up1 = min(h - i, w - j) + 1;
    int low1 = 0;
    const int h = h;
    const int w = w;
    const int k = k;
    while (up1 - low1 > 1)
    {
        int mid = (up1 + low1) / 2;
        int cnt = 0;
        rep(l, 26)
            cnt += (f(l, i, j, mid) >= 1);
        (cnt >= p ? up1 : low1) = mid;
    }
    if (up1 == 0)
        return 0;
    int up2 = up1;
    int low2 = 0;
    p--;
    while (up2 - low2 > 1)
    {
        int mid = (up2 + low2) / 2;
        int 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(i, h) rep(j, w)
        rep(l, 26)
            sum[i + 1][j + 1][l] = sum[i][j + 1][l] + sum[i + 1][j][l] - sum[i][j][l] + 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