結果

問題 No.866 レベルKの正方形
ユーザー IKyoproIKyopro
提出日時 2019-08-17 12:21:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,192 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 72,848 KB
実行使用メモリ 414,352 KB
最終ジャッジ日時 2023-10-25 00:07:59
合計ジャッジ時間 8,953 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
36,756 KB
testcase_01 AC 10 ms
42,776 KB
testcase_02 AC 8 ms
36,752 KB
testcase_03 AC 11 ms
46,788 KB
testcase_04 AC 10 ms
46,792 KB
testcase_05 AC 9 ms
40,764 KB
testcase_06 AC 9 ms
40,764 KB
testcase_07 AC 9 ms
38,756 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 <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int sum[26][2001][2001] = {};
int calc(int x1,int y1,int x2,int y2){
    int res = 0;
    for(int c=0;c<26;c++) res += sum[c][x2][y2]-sum[c][x1-1][y2]-sum[c][x2][y1-1]+sum[c][x1-1][y1-1]>=1;
    return res;
}

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){
        char c;
        cin >> c;
        sum[c-'a'][i][j]++;            
    }
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) for(int k=0;k<26;k++) sum[k][i][j] += sum[k][i][j-1];
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) for(int k=0;k<26;k++) sum[k][i][j] += sum[k][i-1][j];
    ll ans = 0;
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){
        ll l1 = 1,r1 = min(H-i+1,W-j+1)+1;
        while(l1+1<r1){
            ll m = (l1+r1)/2;
            int cnt = 0;
            if(calc(i,j,i+m-1,j+m-1)<=K) l1 = m;
            else r1 = m;
        }
        ll l2 = 0,r2 = l1+1;
        while(l2+1<r2){
            ll m = (l2+r2)/2;
            int cnt = 0;
            if(calc(i,j,i+m-1,j+m-1)<K) l2 = m;
            else r2 = m;
        }
        ans += l1-l2;
    }
    cout << ans << endl;
}
0