結果
問題 | No.866 レベルKの正方形 |
ユーザー | MarcusAureliusAntoninus |
提出日時 | 2019-08-16 23:30:52 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,474 ms / 6,000 ms |
コード長 | 1,575 bytes |
コンパイル時間 | 2,282 ms |
コンパイル使用メモリ | 211,020 KB |
実行使用メモリ | 411,744 KB |
最終ジャッジ日時 | 2023-10-24 06:07:27 |
合計ジャッジ時間 | 33,783 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 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 | 2 ms
4,348 KB |
testcase_08 | AC | 2,300 ms
411,672 KB |
testcase_09 | AC | 2,146 ms
411,744 KB |
testcase_10 | AC | 2,465 ms
411,744 KB |
testcase_11 | AC | 2,474 ms
411,744 KB |
testcase_12 | AC | 1,934 ms
411,744 KB |
testcase_13 | AC | 2,418 ms
411,744 KB |
testcase_14 | AC | 1,720 ms
411,744 KB |
testcase_15 | AC | 2,425 ms
411,744 KB |
testcase_16 | AC | 2,295 ms
411,744 KB |
testcase_17 | AC | 2,411 ms
411,744 KB |
testcase_18 | AC | 2,410 ms
411,744 KB |
testcase_19 | AC | 1,605 ms
411,744 KB |
testcase_20 | AC | 1,413 ms
411,744 KB |
testcase_21 | AC | 1,645 ms
411,744 KB |
testcase_22 | AC | 2 ms
4,348 KB |
testcase_23 | AC | 1 ms
4,348 KB |
testcase_24 | AC | 2 ms
4,348 KB |
ソースコード
#include <bits/stdc++.h> using vi26 = std::vector<std::array<int, 26>>; using vvi26 = std::vector<vi26>; int H, W, K; vvi26 table; int scaleCount(int, int, int); int calcLevel(int, int, int, int); int main() { scanf("%d%d%d", &H, &W, &K); table.resize(H + 1, vi26(W + 1)); for (int h{1}; h <= H; h++) for (int w{1}; w <= W; w++) { char c; scanf(" %c", &c); table[h][w][c - 'a']++; } for (int h{1}; h <= H; h++) for (int w{1}; w <= W; w++) for (int c{}; c < 26; c++) table[h][w][c] += table[h][w - 1][c]; for (int h{1}; h <= H; h++) for (int w{}; w <= W; w++) for (int c{}; c < 26; c++) table[h][w][c] += table[h - 1][w][c]; int64_t ans{}; for (int h{H - 1}; h > 0; h--) ans += scaleCount(h, 0, K) - scaleCount(h, 0, K + 1); ans += scaleCount(0, 0, K) - scaleCount(0, 0, K + 1); for (int w{W}; w > 0; w--) ans += scaleCount(0, w, K) - scaleCount(0, w, K + 1); printf("%lld\n", ans); return 0; } int scaleCount(int begin_h, int begin_w, int K) { int ans{}; for (int right{1}, left{}; begin_h + right <= H && begin_w + right <= W; right++) { if (calcLevel(begin_h + left, begin_w + left, begin_h + right, begin_w + right) < K) continue; while (calcLevel(begin_h + left + 1, begin_w + left + 1, begin_h + right, begin_w + right) >= K) left++; ans += left + 1; } return ans; } int calcLevel(int top, int left, int bottom, int right) { int level{}; for (int c{}; c < 26; c++) if (table[bottom][right][c] + table[top][left][c] - table[top][right][c] - table[bottom][left][c] > 0) level++; return level; }