結果

問題 No.866 レベルKの正方形
ユーザー IKyoproIKyopro
提出日時 2019-08-17 20:42:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,148 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 79,072 KB
実行使用メモリ 414,440 KB
最終ジャッジ日時 2023-10-25 09:28:08
合計ジャッジ時間 76,479 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
56,832 KB
testcase_01 AC 12 ms
56,836 KB
testcase_02 AC 13 ms
56,832 KB
testcase_03 AC 13 ms
56,836 KB
testcase_04 AC 13 ms
56,836 KB
testcase_05 AC 13 ms
56,836 KB
testcase_06 AC 13 ms
56,836 KB
testcase_07 AC 12 ms
56,836 KB
testcase_08 TLE -
testcase_09 AC 5,465 ms
414,440 KB
testcase_10 AC 5,227 ms
414,332 KB
testcase_11 AC 5,199 ms
414,320 KB
testcase_12 AC 4,833 ms
414,276 KB
testcase_13 AC 5,153 ms
414,296 KB
testcase_14 AC 4,889 ms
414,328 KB
testcase_15 AC 5,147 ms
414,324 KB
testcase_16 AC 5,017 ms
414,312 KB
testcase_17 AC 5,282 ms
414,324 KB
testcase_18 AC 5,156 ms
414,320 KB
testcase_19 AC 4,973 ms
414,324 KB
testcase_20 AC 4,849 ms
414,320 KB
testcase_21 AC 5,035 ms
414,280 KB
testcase_22 AC 12 ms
56,804 KB
testcase_23 AC 12 ms
56,804 KB
testcase_24 AC 14 ms
63,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

int H,W,K;
char F[2001][2001];
int dp[26][2001][2001];

int rec(int x,int y,int c){
    if(dp[c][x][y]!=-1) return dp[c][x][y];
    if(F[x][y]-'a'==c) return dp[c][x][y] = 1;
    int res = min(H-x+1,W-y+1)+1;
    if(x!=H && y!=W) res = min(res,rec(x+1,y+1,c)+1);
    if(x!=H) res = min(res,rec(x+1,y,c)+1);
    if(y!=W) res = min(res,rec(x,y+1,c)+1);
    return dp[c][x][y] = res;
}

int main(){
    cin >> H >> W >> K;
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){
        cin >> F[i][j];
        for(int c=0;c<26;c++) dp[c][i][j] = -1;
    }
    ll ans = 0;
    for(int c=0;c<26;c++){
        for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) rec(i,j,c);
    }
    for(int i=1;i<=H;i++) for(int j=1;j<=W;j++){
        priority_queue<ll> Q;
        for(int c=0;c<26;c++){
            Q.push(dp[c][i][j]);
            if(Q.size()>K+1) Q.pop();
        }
        if(K==26) ans += min(H-i+1,W-j+1)+1-Q.top();
        else{
            ll r = Q.top(); Q.pop();
            ll l = Q.top();
            ans += r-l;
        }
    }
    cout << ans << endl;
}
0