結果

問題 No.866 レベルKの正方形
ユーザー IKyoproIKyopro
提出日時 2019-08-17 20:28:19
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,194 bytes
コンパイル時間 1,324 ms
コンパイル使用メモリ 95,756 KB
実行使用メモリ 435,972 KB
最終ジャッジ日時 2023-08-20 12:53:50
合計ジャッジ時間 13,239 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 363 ms
431,084 KB
testcase_01 AC 367 ms
431,140 KB
testcase_02 AC 368 ms
431,140 KB
testcase_03 AC 368 ms
431,156 KB
testcase_04 AC 367 ms
431,100 KB
testcase_05 AC 367 ms
431,132 KB
testcase_06 AC 370 ms
431,084 KB
testcase_07 AC 366 ms
431,036 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 5,823 ms
431,588 KB
testcase_11 AC 5,795 ms
431,204 KB
testcase_12 AC 5,591 ms
431,588 KB
testcase_13 AC 5,845 ms
431,036 KB
testcase_14 AC 5,656 ms
431,632 KB
testcase_15 AC 5,734 ms
431,584 KB
testcase_16 AC 5,661 ms
431,596 KB
testcase_17 AC 5,850 ms
431,704 KB
testcase_18 AC 5,797 ms
431,040 KB
testcase_19 AC 5,487 ms
431,696 KB
testcase_20 AC 5,523 ms
431,152 KB
testcase_21 AC 5,689 ms
431,040 KB
testcase_22 AC 375 ms
431,036 KB
testcase_23 AC 369 ms
431,112 KB
testcase_24 AC 369 ms
431,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int H,W,K;
vector<vector<char>> F(2001,vector<char>(2001));
vector<vector<vector<int>>> dp(26,vector<vector<int>>(2001,vector<int>(2001,-1)));

ll 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;
    ll 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];
    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