結果
問題 | No.2838 Diagonals |
ユーザー | Carpenters-Cat |
提出日時 | 2024-08-09 23:12:56 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,239 bytes |
コンパイル時間 | 4,109 ms |
コンパイル使用メモリ | 266,860 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-09 23:13:01 |
合計ジャッジ時間 | 5,248 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 18 ms
6,944 KB |
testcase_09 | AC | 21 ms
6,940 KB |
testcase_10 | AC | 15 ms
6,944 KB |
testcase_11 | AC | 22 ms
6,940 KB |
testcase_12 | AC | 14 ms
6,940 KB |
testcase_13 | AC | 14 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 3 ms
6,940 KB |
testcase_17 | AC | 5 ms
6,944 KB |
testcase_18 | AC | 10 ms
6,940 KB |
testcase_19 | AC | 8 ms
6,944 KB |
testcase_20 | AC | 8 ms
6,944 KB |
testcase_21 | AC | 5 ms
6,940 KB |
testcase_22 | AC | 4 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint = modint998244353; int main () { int H, W; cin >> H >> W; assert(1 <= min(H, W) && max(H, W) <= 500); mint ans = 1; char A[555][555]; for (int i = 0; i <= H; i ++) { for (int j = 0; j <= W; j ++) { if (min(i, j) == 0) { A[i][j] = '.'; } else { cin >> A[i][j]; if (A[i][j] == '#') { ans *= 2; if (A[i][j - 1] == '.' || A[i - 1][j] == '.') { ans *= 2; } if (A[i][j - 1] == '.' && A[i - 1][j] == '.') { ans *= 2; } } } } } for (int i = 1; i <= H; i ++) { A[i][W + 1] = '.'; } for (int j = 1; j <= W; j ++) { A[H + 1][W] = '.'; } int mi[] = {0, 1, 0, -1}, mj[] = {1, 0, -1, 0}; for (int i = 1; i <= H; i ++) { for (int j = 1; j <= W; j ++) { if (A[i][j] == '#') { ans /= 2; std::stack<pair<int, int>> st ; st.emplace(i, j); A[i][j] = '.'; while (!st.empty()) { auto [ui, uj] = st.top(); st.pop(); for (int d = 0; d < 4; d ++) { int vi = ui + mi[d], vj = uj + mj[d]; if (A[vi][vj] == '#') { A[vi][vj] = '.'; st.emplace(vi, vj); } } } } } } cout << ans.val() << endl; }