結果

問題 No.2838 Diagonals
ユーザー GOTKAKO
提出日時 2024-08-09 22:56:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,705 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 208,500 KB
最終ジャッジ日時 2025-02-23 22:00:41
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long mod = 998244353;
//入力が必ずmod未満の時に使う.
struct mint{
    long long v = 0;
    mint(){} mint(int a){v = a;} mint(long long a){v = a;} mint(unsigned long long a){v = a;}
    long long val(){return v;}
    void modu(){v %= mod;}
 
    mint repeat2mint(const long long a,long long b){
        mint ret = 1,p = a;
        while(b){
            if(b&1) ret *= p;
            p *= p; b >>= 1;
        }
        return ret;
    };
 
    mint operator+(const mint b){return mint(v)+=b;}
    mint operator-(const mint b){return mint(v)-=b;}
    mint operator*(const mint b){return mint(v)*=b;}
    mint operator/(const mint b){return mint(v)/=b;}
 
    mint operator+=(const mint b){
        v += b.v; if(v >= mod) v -= mod;
        return *this;
    }
    mint operator-=(const mint b){
        v -= b.v; if(v < 0) v += mod; 
        return *this;
    }   
    mint operator*=(const mint b){v = v*b.v%mod; return *this;}
    mint operator/=(mint b){
        if(b == 0) assert(false);
        int left = mod-2;
        while(left){if(left&1) *this *= b; b *= b; left >>= 1;}
        return *this;
    }
 
    mint operator++(int){*this += 1; return *this;}
    mint operator--(int){*this -= 1; return *this;}
    bool operator==(const mint b){return v == b.v;}
    bool operator!=(const mint b){return v != b.v;}
    bool operator>(const mint b){return v > b.v;}
    bool operator>=(const mint b){return v >= b.v;}
    bool operator<(const mint b){return v < b.v;}
    bool operator<=(const mint b){return v <= b.v;}
    
    mint pow(const long long x){return repeat2mint(v,x);}
    mint inv(){return mint(1)/v;}
};

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

    int N,M; cin >> N >> M;
    vector<string> S(N);
    for(auto &s : S) cin >> s;

    int pow = 0;
    vector<vector<int>> already(N,vector<int>(M));    
    for(int i=0; i<N; i++) for(int k=0; k<M; k++) if(S.at(i).at(k) == '#' && already.at(i).at(k) == 0){
        queue<pair<int,int>> Q; Q.push({i,k});
        vector<pair<int,int>> dxy = {{-1,0},{0,1},{1,0},{0,-1}};
        already.at(i).at(k) = 1;
        while(Q.size()){
            auto [x,y] = Q.front(); Q.pop();
            if(already.at(x).at(y) <= 1) pow++;
            pow++;
            for(auto [dx,dy] : dxy){
                int nx = dx+x,ny = dy+y;
                if(nx < 0 || ny < 0 || nx >= N || ny >= M) continue;
                if(S.at(nx).at(ny) == '.') continue;
                already.at(nx).at(ny)++;
                if(already.at(nx).at(ny) == 1) Q.push({nx,ny});
            }
        }
    }
  //  cout << pow << endl;
    cout << mint(2).pow(pow).v << endl;
}
0