結果
問題 |
No.2838 Diagonals
|
ユーザー |
|
提出日時 | 2024-08-10 08:36:39 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 746 bytes |
コンパイル時間 | 2,721 ms |
コンパイル使用メモリ | 254,468 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-10 08:36:43 |
合計ジャッジ時間 | 3,808 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/dsu> #include <atcoder/modint> using namespace std; using namespace atcoder; using mint = modint998244353; int main() { int N, M; cin >> N >> M; vector<string> S(N); for (int i = 0; i < N; i++) { cin >> S[i]; } mint ans = 1; dsu uf(N * M); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (S[i][j] == '#') { if (i == 0 || j == 0) { ans *= 4; } else if (uf.same((i - 1) * M + j, i * M + j - 1)) { ans *= 2; } else { ans *= 4; } if (i > 0 && S[i - 1][j] == '#') { uf.merge(i * M + j, (i - 1) * M + j); } if (j > 0 && S[i][j - 1] == '#') { uf.merge(i * M + j, i * M + j - 1); } } } } cout << ans.val() << '\n'; }