結果

問題 No.866 レベルKの正方形
ユーザー finefine
提出日時 2019-08-16 23:17:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,079 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 174,588 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-24 05:15:43
合計ジャッジ時間 10,131 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 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 <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, K;
    cin >> h >> w >> K;
    vector<string> c(h);
    for (int i = 0; i < h; i++) {
        cin >> c[i];
    }

    int sz = min(h, w);
    vector< vector<int> > dp(w, vector<int>(sz + 1, 0));
    ll ans = 0;
    for (int j = 0; j < w; j++) {
        dp[j][1] = (1 << (c[0][j] - 'a'));
        if (K == 1) ans++;
    }
    for (int i = 1; i < h; i++) {
        vector< vector<int> > ndp(w, vector<int>(sz + 1, 0));
        ndp[0][1] = (1 << (c[i][0] - 'a'));
        if (K == 1) ans++;
        for (int j = 1; j < w; j++) {
            for (int k = min(i + 1, j + 1); k >= 1; k--) {
                ndp[j][k] = (1 << (c[i][j] - 'a'));
                ndp[j][k] |= dp[j][k - 1];
                ndp[j][k] |= dp[j - 1][k - 1];
                ndp[j][k] |= ndp[j - 1][k - 1];
                if (__builtin_popcount(ndp[j][k]) == K) ans++;
            }
        }
        dp = move(ndp);
    }
    cout << ans << "\n";
    return 0;
}
0