結果

問題 No.2838 Diagonals
ユーザー GOTKAKOGOTKAKO
提出日時 2024-08-09 23:20:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,112 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 221,052 KB
実行使用メモリ 7,672 KB
最終ジャッジ日時 2024-08-09 23:20:37
合計ジャッジ時間 8,385 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 6 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 782 ms
7,544 KB
testcase_09 WA -
testcase_10 AC 651 ms
7,664 KB
testcase_11 AC 722 ms
7,540 KB
testcase_12 AC 343 ms
7,532 KB
testcase_13 AC 511 ms
6,944 KB
testcase_14 AC 90 ms
6,944 KB
testcase_15 AC 21 ms
6,944 KB
testcase_16 AC 62 ms
6,944 KB
testcase_17 AC 133 ms
6,940 KB
testcase_18 AC 324 ms
6,940 KB
testcase_19 AC 266 ms
6,940 KB
testcase_20 AC 302 ms
6,940 KB
testcase_21 AC 108 ms
6,940 KB
testcase_22 AC 112 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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;}
};

random_device rnd;
mt19937 mt(rnd());

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 = 1001001001;
    for(int t=0; t<50; t++){
    int nowpow = 0;

    vector<vector<bool>> already(N,vector<bool>(M)),end(N,vector<bool>(M));
    vector<pair<int,int>> look;
    for(int i=0; i<N; i++) for(int k=0; k<M; k++) look.push_back({i,k});
    shuffle(look.begin(),look.end(),mt);
    for(auto [i,k] : look) if(S.at(i).at(k) == '#' && !already.at(i).at(k)){
        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) = true;
        while(Q.size()){
            auto [x,y] = Q.front(); Q.pop();
            int first = 4;
            for(auto [dx,dy] : dxy){
                int nx = dx+x,ny = dy+y;
                if(nx < 0 || ny < 0 || nx >= N || ny >= M) continue;
                if(end.at(nx).at(ny)){first--; continue;}
                if(S.at(nx).at(ny) == '.' || already.at(nx).at(ny)) continue;
                already.at(nx).at(ny) = true; Q.push({nx,ny});
            }
            if(first >= 3) nowpow += 2;
            else if(first == 2) nowpow++;
        
            end.at(x).at(y) = true;
        }
    }
    
    pow = min(pow,nowpow);
    }
  //  cout << pow << endl;
    cout << mint(2).pow(pow).v << endl;
}
0