結果

問題 No.866 レベルKの正方形
ユーザー uenokuuenoku
提出日時 2020-04-28 22:12:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,114 ms / 6,000 ms
コード長 2,155 bytes
コンパイル時間 3,078 ms
コンパイル使用メモリ 215,124 KB
実行使用メモリ 427,332 KB
最終ジャッジ日時 2023-08-16 20:04:32
合計ジャッジ時間 43,148 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,440 KB
testcase_01 AC 2 ms
5,388 KB
testcase_02 AC 2 ms
5,396 KB
testcase_03 AC 2 ms
5,720 KB
testcase_04 AC 2 ms
5,504 KB
testcase_05 AC 1 ms
5,396 KB
testcase_06 AC 2 ms
5,384 KB
testcase_07 AC 1 ms
5,424 KB
testcase_08 AC 1,966 ms
427,332 KB
testcase_09 AC 2,104 ms
427,016 KB
testcase_10 AC 2,959 ms
427,020 KB
testcase_11 AC 3,025 ms
427,144 KB
testcase_12 AC 2,711 ms
427,092 KB
testcase_13 AC 2,942 ms
427,016 KB
testcase_14 AC 2,790 ms
427,024 KB
testcase_15 AC 2,735 ms
427,216 KB
testcase_16 AC 3,114 ms
427,196 KB
testcase_17 AC 2,846 ms
427,200 KB
testcase_18 AC 2,924 ms
427,024 KB
testcase_19 AC 2,422 ms
427,092 KB
testcase_20 AC 1,943 ms
427,068 KB
testcase_21 AC 2,792 ms
427,072 KB
testcase_22 AC 2 ms
5,412 KB
testcase_23 AC 2 ms
5,476 KB
testcase_24 AC 2 ms
5,468 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int calc(int, int, int)’ 内:
main.cpp:26:15: 警告: ‘h’ is used uninitialized [-Wuninitialized]
   26 |     const int h = h;
      |               ^
main.cpp:26:15: 備考: ‘h’ はここで定義されています
   26 |     const int h = h;
      |               ^
main.cpp:27:15: 警告: ‘w’ is used uninitialized [-Wuninitialized]
   27 |     const int w = w;
      |               ^
main.cpp:27:15: 備考: ‘w’ はここで定義されています
   27 |     const int w = w;
      |               ^
main.cpp:28:15: 警告: ‘k’ is used uninitialized [-Wuninitialized]
   28 |     const int k = k;
      |               ^
main.cpp:28:15: 備考: ‘k’ はここで定義されています
   28 |     const int k = k;
      |               ^

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#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