結果
問題 |
No.2838 Diagonals
|
ユーザー |
![]() |
提出日時 | 2025-07-25 00:58:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 1,134 bytes |
コンパイル時間 | 2,202 ms |
コンパイル使用メモリ | 203,512 KB |
実行使用メモリ | 41,240 KB |
最終ジャッジ日時 | 2025-07-25 00:58:25 |
合計ジャッジ時間 | 4,060 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int ll #define fast_io cin.tie(0)->sync_with_stdio(0); #define endl '\n' typedef long long ll; int32_t main() { fast_io; int n, m; cin >> n >> m; vector<string> grid(n); for (auto &s : grid) cin >> s; const int MAX = 8 * n * m + 10; const int MOD = 998244353; vector<int> pot(MAX); pot[0] = 1; for (int i = 1; i < MAX; i++) pot[i] = pot[i - 1] * 2 % MOD; int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (grid[i][j] == '#') { ans += 3; if (i > 0 && grid[i - 1][j] == '#') ans--; if (j > 0 && grid[i][j - 1] == '#') ans--; } } } vector vis(n, vector(m, 0)); auto dfs = [&] (auto&& self, int i, int j) { if (i < 0 || i >= n || j < 0 || j >= m) return; if (vis[i][j]) return; if (grid[i][j] != '#') return; vis[i][j] = 1; self(self, i + 1, j); self(self, i - 1, j); self(self, i, j + 1); self(self, i, j - 1); }; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (grid[i][j] == '#' && !vis[i][j]) { dfs(dfs, i, j); ans--; } } } cout << pot[ans] << endl; }