結果

問題 No.2838 Diagonals
ユーザー momoyuumomoyuu
提出日時 2024-08-09 23:26:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 1,148 ms
コンパイル使用メモリ 109,540 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-08-09 23:26:39
合計ジャッジ時間 2,099 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

#include<atcoder/dsu>
#include<atcoder/modint>
using mint = atcoder::modint998244353;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,m;
    cin>>n>>m;
    vector<string> s(n);
    for(int i = 0;i<n;i++) cin>>s[i];
    atcoder::dsu uf(n*m);
    mint ans = 1;

    auto ok = [&](int i,int j){
        if(i<0||i>=n||j<0||j>=m) return 0;
        return 1;
    };
    auto calc = [&](int i,int j){
        return i * m + j;
    };

    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            if(s[i][j]=='.') continue;
            if(ok(i-1,j)&&ok(i,j-1)&&uf.same(calc(i-1,j),calc(i,j-1))) ans *= 2;
            else ans *= 4;
            if(ok(i-1,j)&&s[i-1][j]=='#') uf.merge(calc(i,j),calc(i-1,j));
            if(ok(i,j-1)&&s[i][j-1]=='#') uf.merge(calc(i,j),calc(i,j-1));
        }
    }
    cout<<ans.val()<<endl;

}

0